Skip to content

Commit

Permalink
fuzzyPresent directly in TextQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownJoe796 committed Oct 31, 2024
1 parent 650e0a2 commit 5c53cba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,15 @@ class SearchTextConditionTest {
.toList()
.let { assertEquals(2, it.size, "Got $it") }

// var query = "One"
// var condition = path<ModelWithTextIndex2>().fullTextSearch(query, requireAllTermsPresent = true)
// var results = collection.find(condition).toList()
// assertContains(results, value1)
//
// query = "One two three"
// condition = path<ModelWithTextIndex2>().fullTextSearch(query, requireAllTermsPresent = true)
// results = collection.find(condition).toList()
// assertContains(results, value1)
//
// query = "One two four"
// condition = path<ModelWithTextIndex2>().fullTextSearch(query, requireAllTermsPresent = true)
// results = collection.find(condition).toList()
// assertTrue(results.isEmpty())
//
// query = "one"
// condition = path<ModelWithTextIndex2>().fullTextSearch(query, requireAllTermsPresent = true)
// results = collection.find(condition).toList()
// assertContains(results, value1)
collection
.find(condition { it.fullTextSearch("911 gtx", requireAllTermsPresent = true) })
.toList()
.let { assertEquals(1, it.size, "Got $it") }

collection
.find(condition { it.fullTextSearch("911 gtz", requireAllTermsPresent = true) })
.toList()
.let { assertEquals(0, it.size, "Got $it") }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@ data class TextQuery(
fun fuzzyPresent(input: String, off: Int = 2): Boolean {
val words = input.split(' ', '\n', '\t')
return exact.all {
input.contains(it)
input.contains(it, true)
} && loose.all { l ->
words.any { w -> levenshtein(l.lowercase(), w.lowercase()) <= off }
words.any { w ->
if(l.termShouldUseFuzzySearch())
levenshtein(l.lowercase(), w.lowercase()) <= off
else
input.contains(l, true)
}
} && reject.none {
input.contains(it)
input.contains(it, true)
}
}

Expand Down

0 comments on commit 5c53cba

Please sign in to comment.