Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlighting - does not work with custom_score or boosting, closes #1314 #1315

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -25,13 +25,18 @@
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.BoostingQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.highlight.*;
import org.apache.lucene.search.vectorhighlight.*;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.io.FastStringReader;
import org.elasticsearch.common.lucene.document.SingleFieldSelector;
import org.elasticsearch.common.lucene.search.MoreLikeThisQuery;
import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery;
import org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery;
import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperService;
Expand Down Expand Up @@ -110,7 +115,32 @@ public static class Encoders {
}
// Don't use the context.query() since it might be rewritten, and we need to pass the non rewritten queries to
// let the highlighter handle MultiTerm ones
QueryScorer queryScorer = new QueryScorer(context.parsedQuery().query(), null);
QueryScorer queryScorer;
if (context.parsedQuery().query() instanceof FunctionScoreQuery) {
queryScorer = new QueryScorer(((FunctionScoreQuery)context.parsedQuery().query()).getSubQuery(), null);
} else if (context.parsedQuery().query() instanceof FiltersFunctionScoreQuery) {
queryScorer = new QueryScorer(((FiltersFunctionScoreQuery)context.parsedQuery().query()).getSubQuery(), null);
} else if (context.parsedQuery().query() instanceof BoostingQuery) {
try {
queryScorer = new QueryScorer(((BoostingQuery)context.parsedQuery().query()).rewrite(hitContext.reader()), null);
} catch (IOException e) {
throw new ElasticSearchException("Failed rewriting BoostingQuery",e);
}
} else if (context.parsedQuery().query() instanceof MoreLikeThisQuery) {
try {
queryScorer = new QueryScorer(((MoreLikeThisQuery)context.parsedQuery().query()).rewrite(hitContext.reader()), null);
} catch (IOException e) {
throw new ElasticSearchException("Failed rewriting MoreLikeThisQuery",e);
}
} else if (context.parsedQuery().query() instanceof MultiPhrasePrefixQuery) {
try {
queryScorer = new QueryScorer(((MultiPhrasePrefixQuery)context.parsedQuery().query()).rewrite(hitContext.reader()), null);
} catch (IOException e) {
throw new ElasticSearchException("Failed rewriting MultiPhrasePrefixQuery",e);
}
} else {
queryScorer = new QueryScorer(context.parsedQuery().query(), null);
}
queryScorer.setExpandMultiTermQuery(true);
Fragmenter fragmenter;
if (field.numberOfFragments() == 0) {
Expand Down