dsmiley commented on a change in pull request #1151: SOLR-13890: Add "top-level" DVTQ implementation URL: https://github.com/apache/lucene-solr/pull/1151#discussion_r363758827
########## File path: solr/core/src/java/org/apache/solr/search/TermsQParserPlugin.java ########## @@ -138,8 +164,128 @@ public Query parse() throws SyntaxError { bytesRefs[i] = term.toBytesRef(); } - return method.makeFilter(fname, bytesRefs); + return method.makeFilter(fname, bytesRefs, localParams); } }; } + + private static abstract class TopLevelTwoPhaseIterator extends TwoPhaseIterator { + private final int docBase; + private final int nextDocBase; + public TopLevelTwoPhaseIterator(DocIdSetIterator approximation, int docBase, int nextDocBase) { + super(new PerSegmentViewDocIdSetIterator(approximation, docBase, nextDocBase)); + + this.docBase = docBase; + this.nextDocBase = nextDocBase; + } + } + + private static class TopLevelDocValuesTermsQuery extends DocValuesTermsQuery implements ExtendedQuery{ + private final String fieldName; + private SortedSetDocValues values; + private LongBitSet queryTermOrdinals; + private boolean matchesAtLeastOneTerm = false; + private boolean cache = true; + private boolean cacheSeparately = false; + private int cost; + + + public TopLevelDocValuesTermsQuery(String field, BytesRef... terms) { + super(field, terms); + this.fieldName = field; + } + + public Weight createWeight(IndexSearcher searcher, final ScoreMode scoreMode, float boost) throws IOException { + values = DocValues.getSortedSet(((SolrIndexSearcher)searcher).getSlowAtomicReader(), fieldName); + queryTermOrdinals = new LongBitSet(values.getValueCount()); + PrefixCodedTerms.TermIterator iterator = getTerms().iterator(); + + long lastOrdFound = 0; + for(BytesRef term = iterator.next(); term != null; term = iterator.next()) { + long ord = lookupTerm(values, term, lastOrdFound); + if (ord >= 0L) { + matchesAtLeastOneTerm = true; + queryTermOrdinals.set(ord); + lastOrdFound = ord; + } + } + + return new ConstantScoreWeight(this, boost) { + public Scorer scorer(LeafReaderContext context) throws IOException { Review comment: I see that you are using the top level sortedSetDocValues as a DocIdSetIterator approximation. I can see this works but I think we needn't get that complex, and we miss out on other optimizations by doing so. I'll post PR comment on how to replace it in a way that also removes TopLevelTwoPhaseIterator. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org