Commit ec0fea8e authored by Rob Tomsick's avatar Rob Tomsick

Make drug search use the same fuzzy hashing approach as everything else

parent d61bbba1
......@@ -190,18 +190,30 @@ implements DictionaryService
/* fuzzy hash search */
final Iterator<List<String>> hi =
partitionByLength(hashFuzz(query, HASH_DISTANCE, MIN_FUZZY_HASH_LEN)).iterator();
final List<List<String>> hashes =
partitionByLength(hashFuzz(query, HASH_DISTANCE, MIN_FUZZY_HASH_LEN));
while (drugs.size() < limit && hi.hasNext())
final Field<String> hashField =
field(name("phonetic_hash"), String.class);
for (final List<String> hashGroup : hashes)
{
List<String> hashes = hi.next();
if (drugs.size() >= limit)
{
break;
}
Condition cond = DSL.falseCondition();
for (String hash : hashGroup)
{
cond = cond.or(hashField.like(hash));
}
this.ctx
.select(nf)
.from(N_TABLE)
.where(field(name("phonetic_hash"), String.class).in(hashes))
.limit(limit - drugs.size())
.where(cond)
.fetch(nf)
.stream()
.map(n -> new Drug(n.toUpperCase()))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment