Commit 120eb3c7 authored by Rob Tomsick's avatar Rob Tomsick

Ensure that non-wildcard hashes appear first

parent 5e1cfb12
......@@ -191,7 +191,7 @@ implements DictionaryService
/* fuzzy hash search */
final List<List<String>> hashes =
partitionByLength(hashFuzz(query, HASH_DISTANCE, MIN_FUZZY_HASH_LEN));
partitionHashesByLength(hashFuzz(query, HASH_DISTANCE, MIN_FUZZY_HASH_LEN));
final Field<String> hashField =
field(name("phonetic_hash"), String.class);
......@@ -255,7 +255,7 @@ implements DictionaryService
/* fuzzy hash search over proprietary names */
final List<List<String>> hashes =
partitionByLength(hashFuzz(query, HASH_DISTANCE, MIN_FUZZY_HASH_LEN));
partitionHashesByLength(hashFuzz(query, HASH_DISTANCE, MIN_FUZZY_HASH_LEN));
for (final List<String> hashGroup : hashes)
{
......@@ -482,11 +482,12 @@ implements DictionaryService
}
private static final List<List<String>>
partitionByLength(Stream<String> stream)
partitionHashesByLength(Stream<String> stream)
{
return stream
.collect(Collectors.toMap(s -> s.length(), Stream :: of, Stream :: concat))
.collect(Collectors.toMap(s -> s.length() - StringUtils.countMatches(s, '_'),
Stream :: of, Stream :: concat))
.entrySet().stream()
.sorted((a, b) -> b.getKey() - a.getKey())
.map(e -> e.getValue().collect(Collectors.toList()))
......
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