dsmiley commented on a change in pull request #780: SOLR-11866: Support efficient subset matching in query elevation rules URL: https://github.com/apache/lucene-solr/pull/780#discussion_r303657585
########## File path: solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java ########## @@ -1020,8 +1066,58 @@ public Elevation(Set<BytesRef> elevatedIds, Set<BytesRef> excludedIds, for (BytesRef excludedId : excludedIds) { excludeQueriesBuilder.add(new TermQuery(new Term(queryFieldName, excludedId))); } - excludeQueries = excludeQueriesBuilder.toArray(new TermQuery[excludeQueriesBuilder.size()]); + excludeQueries = excludeQueriesBuilder.toArray(new TermQuery[0]); + } + } + + protected Elevation(Set<BytesRef> elevatedIds, BooleanQuery includeQuery, Set<BytesRef> excludedIds, TermQuery[] excludeQueries) { + this.elevatedIds = elevatedIds; + this.includeQuery = includeQuery; + this.excludedIds = excludedIds; + this.excludeQueries = excludeQueries; + } + + /** + * Merges this {@link Elevation} with another and creates a new {@link Elevation}. + + * @return A new instance containing the merging of the two elevations; or directly this elevation if the other + * is <code>null</code>. + */ + protected Elevation mergeWith(Elevation elevation) { + if (elevation == null) { + return this; + } + Set<BytesRef> elevatedIds = ImmutableSet.<BytesRef>builder().addAll(this.elevatedIds).addAll(elevation.elevatedIds).build(); + boolean overlappingElevatedIds = elevatedIds.size() != (this.elevatedIds.size() + elevation.elevatedIds.size()); + BooleanQuery.Builder includeQueryBuilder = new BooleanQuery.Builder(); + Set<BooleanClause> clauseSet = (overlappingElevatedIds ? new HashSet<>() : null); + for (BooleanClause clause : this.includeQuery.clauses()) { + if (!overlappingElevatedIds || clauseSet.add(clause)) { + includeQueryBuilder.add(clause); + } + } + for (BooleanClause clause : elevation.includeQuery.clauses()) { + if (!overlappingElevatedIds || clauseSet.add(clause)) { + includeQueryBuilder.add(clause); + } + } + Set<BytesRef> excludedIds = ImmutableSet.<BytesRef>builder().addAll(this.excludedIds).addAll(elevation.excludedIds).build(); + TermQuery[] excludeQueries; + if (this.excludeQueries == null) { + excludeQueries = elevation.excludeQueries; + } else if (elevation.excludeQueries == null) { + excludeQueries = this.excludeQueries; + } else { + boolean overlappingExcludedIds = excludedIds.size() != (this.excludedIds.size() + elevation.excludedIds.size()); + if (overlappingExcludedIds) { + ImmutableSet.Builder<TermQuery> excludeQueriesBuilder = ImmutableSet.builder(); Review comment: lets inline this ---------------------------------------------------------------- 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: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org