SOLR-9027: Collect the TermContexts in createWeight

This commit is contained in:
jbernste 2016-04-29 10:13:23 -04:00
parent f7b333f105
commit 58ad591a64
1 changed files with 14 additions and 15 deletions

View File

@ -100,8 +100,6 @@ public class GraphTermsQParserPlugin extends QParserPlugin {
private class GraphTermsQuery extends Query implements ExtendedQuery {
private Term[] queryTerms;
private List<TermContext> finalContexts;
private List<Term> finalTerms;
private String field;
private int maxDocFreq;
private Object id;
@ -147,19 +145,6 @@ public class GraphTermsQParserPlugin extends QParserPlugin {
@Override
public Query rewrite(IndexReader reader) throws IOException {
this.finalContexts = new ArrayList();
this.finalTerms = new ArrayList();
List<LeafReaderContext> contexts = reader.leaves();
TermContext[] termContexts = new TermContext[this.queryTerms.length];
collectTermContext(reader, contexts, termContexts, this.queryTerms);
for(int i=0; i<termContexts.length; i++) {
TermContext termContext = termContexts[i];
if(termContext != null && termContext.docFreq() <= this.maxDocFreq) {
this.finalContexts.add(termContext);
this.finalTerms.add(queryTerms[i]);
}
}
return this;
}
@ -211,6 +196,20 @@ public class GraphTermsQParserPlugin extends QParserPlugin {
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
List<TermContext> finalContexts = new ArrayList();
List<Term> finalTerms = new ArrayList();
List<LeafReaderContext> contexts = searcher.getTopReaderContext().leaves();
TermContext[] termContexts = new TermContext[this.queryTerms.length];
collectTermContext(searcher.getIndexReader(), contexts, termContexts, this.queryTerms);
for(int i=0; i<termContexts.length; i++) {
TermContext termContext = termContexts[i];
if(termContext != null && termContext.docFreq() <= this.maxDocFreq) {
finalContexts.add(termContext);
finalTerms.add(queryTerms[i]);
}
}
return new ConstantScoreWeight(this) {
@Override