percolator: Add support for the synonym query.
This commit is contained in:
parent
bfb19676a6
commit
9a0ce62550
|
@ -37,6 +37,7 @@ import org.apache.lucene.search.ConstantScoreQuery;
|
|||
import org.apache.lucene.search.DisjunctionMaxQuery;
|
||||
import org.apache.lucene.search.PhraseQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.SynonymQuery;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
import org.apache.lucene.search.spans.SpanFirstQuery;
|
||||
import org.apache.lucene.search.spans.SpanNearQuery;
|
||||
|
@ -90,6 +91,7 @@ public final class ExtractQueryTermsService {
|
|||
map.put(SpanNotQuery.class, spanNotQuery());
|
||||
map.put(BooleanQuery.class, booleanQuery());
|
||||
map.put(DisjunctionMaxQuery.class, disjunctionMaxQuery());
|
||||
map.put(SynonymQuery.class, synonymQuery());
|
||||
queryProcessors = Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
|
@ -221,6 +223,13 @@ public final class ExtractQueryTermsService {
|
|||
};
|
||||
}
|
||||
|
||||
static Function<Query, Result> synonymQuery() {
|
||||
return query -> {
|
||||
Set<Term> terms = new HashSet<>(((SynonymQuery) query).getTerms());
|
||||
return new Result(true, terms);
|
||||
};
|
||||
}
|
||||
|
||||
static Function<Query, Result> commonTermsQuery() {
|
||||
return query -> {
|
||||
List<Term> terms = ((CommonTermsQuery) query).getTerms();
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.apache.lucene.search.ConstantScoreQuery;
|
|||
import org.apache.lucene.search.DisjunctionMaxQuery;
|
||||
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||
import org.apache.lucene.search.PhraseQuery;
|
||||
import org.apache.lucene.search.SynonymQuery;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
import org.apache.lucene.search.TermRangeQuery;
|
||||
import org.apache.lucene.search.spans.SpanFirstQuery;
|
||||
|
@ -558,6 +559,18 @@ public class ExtractQueryTermsServiceTests extends ESTestCase {
|
|||
assertThat(terms.get(3).bytes(), equalTo(termQuery4.getTerm().bytes()));
|
||||
}
|
||||
|
||||
public void testSynonymQuery() {
|
||||
SynonymQuery query = new SynonymQuery();
|
||||
Result result = extractQueryTerms(query);
|
||||
assertThat(result.verified, is(true));
|
||||
assertThat(result.terms.isEmpty(), is(true));
|
||||
|
||||
query = new SynonymQuery(new Term("_field", "_value1"), new Term("_field", "_value2"));
|
||||
result = extractQueryTerms(query);
|
||||
assertThat(result.verified, is(true));
|
||||
assertTermsEqual(result.terms, new Term("_field", "_value1"), new Term("_field", "_value2"));
|
||||
}
|
||||
|
||||
public void testCreateQueryMetadataQuery() throws Exception {
|
||||
MemoryIndex memoryIndex = new MemoryIndex(false);
|
||||
memoryIndex.addField("field1", "the quick brown fox jumps over the lazy dog", new WhitespaceAnalyzer());
|
||||
|
|
Loading…
Reference in New Issue