...
 
......@@ -134,7 +134,7 @@ implements DictionaryService
Map<UUID, String> names =
this.ctx.select(field(name("id"), UUID.class), f)
.from(D_TABLE)
.where(f.likeIgnoreCase(query + "%"))
.where(f.containsIgnoreCase(query))
.orderBy(f.asc())
.limit(limit)
.fetchMap(field(name("id"), UUID.class), f);
......@@ -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()))
......