do not completely exclude results from other languages
@@ -96,31 +96,22 @@ public class PhotonQueryBuilder {
}));
// 3. Either the name or housenumber must be in the query terms.
- // Be more lenient on second pass. And do not expect housenumbers in single term queries.
+ MultiMatchQueryBuilder nameNgramQuery = QueryBuilders.multiMatchQuery(query)
+ .type(MultiMatchQueryBuilder.Type.BEST_FIELDS)
+ .fuzziness(lenient ? Fuzziness.ONE : Fuzziness.ZERO)
+ .analyzer("search_ngram");
- // XXX There is no ngram index on the the default index. Use primary language for now.
- String primaryLang = "default".equals(language) ? languages.get(0) : language;
- if (query.indexOf(',') < 0 && query.indexOf(' ') < 0) {
- query4QueryBuilder.must(QueryBuilders.matchQuery(String.format("name.%s.ngrams", primaryLang), query)
- .analyzer("search_ngram")
- .boost(2f)
- );
- } else {
- BoolQueryBuilder nameQueryBuilder = QueryBuilders.boolQuery();
-
- nameQueryBuilder.should(QueryBuilders.matchQuery(String.format("name.%s.ngrams", primaryLang), query)
- .analyzer("search_ngram")
- );
-
- // 2b) If there is no name, then there must be a housenumber.
- nameQueryBuilder.should(QueryBuilders.matchQuery("housenumber", query).analyzer("standard"));
- nameQueryBuilder.minimumShouldMatch("1");
+ for (String lang: languages) {
+ nameNgramQuery.field(String.format("name.%s.ngrams", lang), lang.equals(language) ? 1.0f : 0.4f);
+ }
- if (lenient) {
- query4QueryBuilder.should(nameQueryBuilder);
+ if (query.indexOf(',') < 0 && query.indexOf(' ') < 0) {
+ query4QueryBuilder.must(nameNgramQuery.boost(2f));
} else {
- query4QueryBuilder.must(nameQueryBuilder);
- }
+ query4QueryBuilder.must(QueryBuilders.boolQuery()
+ .should(nameNgramQuery)
+ .should(QueryBuilders.matchQuery("housenumber", query).analyzer("standard"))
+ .minimumShouldMatch("1"));
}
// 4. Rerank results for having the full name in the default language.
