Search: When searching against a type with a dfs search type, dfs is ignored, closes #1546.

This commit is contained in:
Shay Banon 2011-12-16 19:17:31 +02:00
parent f74256afcd
commit cb4c249a65
2 changed files with 22 additions and 12 deletions

View File

@ -127,16 +127,26 @@ public class HighlightPhase implements FetchSubPhase {
// QueryScorer uses WeightedSpanTermExtractor to extract terms, but we can't really plug into // QueryScorer uses WeightedSpanTermExtractor to extract terms, but we can't really plug into
// it, so, we hack here (and really only support top level queries) // it, so, we hack here (and really only support top level queries)
Query query = context.parsedQuery().query(); Query query = context.parsedQuery().query();
if (query instanceof FunctionScoreQuery) { while (true) {
query = ((FunctionScoreQuery) query).getSubQuery(); boolean extracted = false;
} else if (query instanceof FiltersFunctionScoreQuery) { if (query instanceof FunctionScoreQuery) {
query = ((FiltersFunctionScoreQuery) query).getSubQuery(); query = ((FunctionScoreQuery) query).getSubQuery();
} else if (query instanceof ConstantScoreQuery) { extracted = true;
ConstantScoreQuery q = (ConstantScoreQuery) query; } else if (query instanceof FiltersFunctionScoreQuery) {
if (q.getQuery() != null) { query = ((FiltersFunctionScoreQuery) query).getSubQuery();
query = q.getQuery(); extracted = true;
} else if (query instanceof ConstantScoreQuery) {
ConstantScoreQuery q = (ConstantScoreQuery) query;
if (q.getQuery() != null) {
query = q.getQuery();
extracted = true;
}
}
if (!extracted) {
break;
} }
} }
QueryScorer queryScorer = new QueryScorer(query, null); QueryScorer queryScorer = new QueryScorer(query, null);
queryScorer.setExpandMultiTermQuery(true); queryScorer.setExpandMultiTermQuery(true);
Fragmenter fragmenter; Fragmenter fragmenter;

View File

@ -81,6 +81,10 @@ public class QueryPhase implements SearchPhase {
if (context.queryBoost() != 1.0f) { if (context.queryBoost() != 1.0f) {
context.parsedQuery(new ParsedQuery(new FunctionScoreQuery(context.query(), new BoostScoreFunction(context.queryBoost())), context.parsedQuery())); context.parsedQuery(new ParsedQuery(new FunctionScoreQuery(context.query(), new BoostScoreFunction(context.queryBoost())), context.parsedQuery()));
} }
Filter searchFilter = context.mapperService().searchFilter(context.types());
if (searchFilter != null) {
context.parsedQuery(new ParsedQuery(new FilteredQuery(context.query(), context.filterCache().cache(searchFilter)), context.parsedQuery()));
}
facetPhase.preProcess(context); facetPhase.preProcess(context);
} }
@ -165,10 +169,6 @@ public class QueryPhase implements SearchPhase {
searchContext.queryResult().size(searchContext.size()); searchContext.queryResult().size(searchContext.size());
Query query = searchContext.query(); Query query = searchContext.query();
Filter searchFilter = searchContext.mapperService().searchFilter(searchContext.types());
if (searchFilter != null) {
query = new FilteredQuery(query, searchContext.filterCache().cache(searchFilter));
}
TopDocs topDocs; TopDocs topDocs;
int numDocs = searchContext.from() + searchContext.size(); int numDocs = searchContext.from() + searchContext.size();