jbampton commented on a change in pull request #2146: URL: https://github.com/apache/lucene-solr/pull/2146#discussion_r543233296
########## File path: solr/core/src/java/org/apache/solr/search/TopLevelJoinQuery.java ########## @@ -218,4 +218,28 @@ public BitsetBounds(long lower, long upper) { this.upper = upper; } } + + /** + * A {@link TopLevelJoinQuery} implementation optimized for when 'from' and 'to' cores and fields match and no ordinal- + * conversion is necessary. + */ + static class SelfJoin extends TopLevelJoinQuery { + public SelfJoin(String joinField, Query subQuery) { + super(joinField, joinField, null, subQuery); + } + + protected BitsetBounds convertFromOrdinalsIntoToField(LongBitSet fromOrdBitSet, SortedSetDocValues fromDocValues, + LongBitSet toOrdBitSet, SortedSetDocValues toDocValues) throws IOException { + + // 'from' and 'to' ordinals are identical for self-joins. + toOrdBitSet.or(fromOrdBitSet); + + // Calculate boundary ords used for other optimizations + final long firstToOrd = toOrdBitSet.nextSetBit(0); + final long lastToOrd = toOrdBitSet.prevSetBit(toOrdBitSet.length() - 1); + return new BitsetBounds(firstToOrd, lastToOrd); + } + } } + Review comment: ```suggestion ``` ########## File path: solr/core/src/java/org/apache/solr/search/TopLevelJoinQuery.java ########## @@ -218,4 +218,28 @@ public BitsetBounds(long lower, long upper) { this.upper = upper; } } + + /** + * A {@link TopLevelJoinQuery} implementation optimized for when 'from' and 'to' cores and fields match and no ordinal- + * conversion is necessary. + */ + static class SelfJoin extends TopLevelJoinQuery { + public SelfJoin(String joinField, Query subQuery) { + super(joinField, joinField, null, subQuery); + } + + protected BitsetBounds convertFromOrdinalsIntoToField(LongBitSet fromOrdBitSet, SortedSetDocValues fromDocValues, + LongBitSet toOrdBitSet, SortedSetDocValues toDocValues) throws IOException { + + // 'from' and 'to' ordinals are identical for self-joins. + toOrdBitSet.or(fromOrdBitSet); + + // Calculate boundary ords used for other optimizations + final long firstToOrd = toOrdBitSet.nextSetBit(0); + final long lastToOrd = toOrdBitSet.prevSetBit(toOrdBitSet.length() - 1); + return new BitsetBounds(firstToOrd, lastToOrd); + } + } } + + Review comment: ```suggestion ``` ---------------------------------------------------------------- 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 --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org