From 86f371cbc68f233697f9be8df93b707daf3826b4 Mon Sep 17 00:00:00 2001 From: jbernste Date: Thu, 28 Apr 2016 13:31:00 -0400 Subject: [PATCH] SOLR-9027: GraphTermsQuery optimizations and more explicit handling of non-caching behavior --- .../solr/search/GraphTermsQParserPlugin.java | 71 ++++++++++++------- .../solrj/io/graph/GatherNodesStream.java | 1 - 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/search/GraphTermsQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/GraphTermsQParserPlugin.java index 9c1c1622785..01dfa2d08f4 100644 --- a/solr/core/src/java/org/apache/solr/search/GraphTermsQParserPlugin.java +++ b/solr/core/src/java/org/apache/solr/search/GraphTermsQParserPlugin.java @@ -39,6 +39,7 @@ import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Weight; +import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; import org.apache.lucene.util.DocIdSetBuilder; @@ -77,7 +78,7 @@ public class GraphTermsQParserPlugin extends QParserPlugin { final String[] splitVals = qstr.split(","); - BytesRef[] bytesRefs = new BytesRef[splitVals.length]; + Term[] terms = new Term[splitVals.length]; BytesRefBuilder term = new BytesRefBuilder(); for (int i = 0; i < splitVals.length; i++) { String stringVal = splitVals[i].trim(); @@ -86,15 +87,17 @@ public class GraphTermsQParserPlugin extends QParserPlugin { } else { term.copyChars(stringVal); } - bytesRefs[i] = term.toBytesRef(); + BytesRef ref = term.toBytesRef(); + terms[i] = new Term(fname, ref); } - return new ConstantScoreQuery(new GraphTermsQuery(fname, bytesRefs, maxDocFreq)); + ArrayUtil.timSort(terms); + return new ConstantScoreQuery(new GraphTermsQuery(fname, terms, maxDocFreq)); } }; } - private class GraphTermsQuery extends Query { + private class GraphTermsQuery extends Query implements ExtendedQuery { private Term[] queryTerms; private List finalContexts; @@ -103,14 +106,11 @@ public class GraphTermsQParserPlugin extends QParserPlugin { private int maxDocFreq; private Object id; - public GraphTermsQuery(String field, BytesRef[] terms, int maxDocFreq) { + public GraphTermsQuery(String field, Term[] terms, int maxDocFreq) { this.maxDocFreq = maxDocFreq; this.field = field; - this.queryTerms = new Term[terms.length]; + this.queryTerms = terms; this.id = new Object(); - for(int i=0; i contexts = reader.leaves(); - TermContext[] termContexts = new TermContext[this.queryTerms.length]; - collectTermContext(reader, contexts, termContexts, this.queryTerms); - for(int i=0; i contexts = reader.leaves(); + TermContext[] termContexts = new TermContext[this.queryTerms.length]; + collectTermContext(reader, contexts, termContexts, this.queryTerms); + for(int i=0; i