ercsonusharma commented on code in PR #3648: URL: https://github.com/apache/solr/pull/3648#discussion_r2361715795
########## solr/core/src/java/org/apache/solr/handler/component/CompoundQueryComponent.java: ########## @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.handler.component; + +import java.io.IOException; +import java.util.HashMap; +import org.apache.lucene.search.ScoreDoc; +import org.apache.lucene.search.TopDocs; +import org.apache.lucene.search.TotalHits; +import org.apache.solr.common.SolrDocumentList; +import org.apache.solr.common.params.CommonParams; + +public class CompoundQueryComponent extends QueryComponent { + public static final String COMPONENT_NAME = "compound_query"; + + @Override + public void prepare(ResponseBuilder rb) throws IOException { + if (rb instanceof CompoundResponseBuilder crb) { + final var params = rb.req.getParams(); + if (params.get(CompoundResponseBuilder.RRF_PREFIX) == null) { + for (var prefix : params.get(CompoundResponseBuilder.RRF_PREFIX + ".list").split(",")) { + crb.responseBuilders.add(new CompoundResponseBuilder.Inner(crb, prefix)); + } + for (var rb_i : crb.responseBuilders) { + super.prepare(rb_i); + } + } else { + super.prepare(rb); + } + } + } + Review Comment: I don't see the `process` method here and wonder how the individual queries from responseBuilders are executed on the shard level from the SearchIndexer? ########## solr/core/src/java/org/apache/solr/handler/component/CompoundQueryComponent.java: ########## @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.handler.component; + +import java.io.IOException; +import java.util.HashMap; +import org.apache.lucene.search.ScoreDoc; +import org.apache.lucene.search.TopDocs; +import org.apache.lucene.search.TotalHits; +import org.apache.solr.common.SolrDocumentList; +import org.apache.solr.common.params.CommonParams; + +public class CompoundQueryComponent extends QueryComponent { + public static final String COMPONENT_NAME = "compound_query"; + + @Override + public void prepare(ResponseBuilder rb) throws IOException { + if (rb instanceof CompoundResponseBuilder crb) { + final var params = rb.req.getParams(); + if (params.get(CompoundResponseBuilder.RRF_PREFIX) == null) { + for (var prefix : params.get(CompoundResponseBuilder.RRF_PREFIX + ".list").split(",")) { + crb.responseBuilders.add(new CompoundResponseBuilder.Inner(crb, prefix)); + } + for (var rb_i : crb.responseBuilders) { + super.prepare(rb_i); + } + } else { + super.prepare(rb); + } + } + } + + @Override + public int distributedProcess(ResponseBuilder rb) throws IOException { + int nextStage = ResponseBuilder.STAGE_DONE; + if (rb instanceof CompoundResponseBuilder crb) { + if (rb.getStage() < CompoundResponseBuilder.STAGE_FUSION) { + for (var rb_i : crb.responseBuilders) { + nextStage = Math.min(nextStage, super.distributedProcess(rb_i)); + } + } else if (rb.getStage() == CompoundResponseBuilder.STAGE_FUSION) { + nextStage = doFusion(crb); + } + } + return nextStage; + } + + private int doFusion(CompoundResponseBuilder crb) { + final SolrDocumentList responseDocs = new SolrDocumentList(); + final TopDocs[] hits = new TopDocs[crb.responseBuilders.size()]; + for (int crb_idx = 0; crb_idx < crb.responseBuilders.size(); ++crb_idx) { + + final SolrDocumentList sdl = crb.responseBuilders.get(crb_idx).getResponseDocs(); + + final ScoreDoc[] scoreDocs = new ScoreDoc[sdl.size()]; + for (int idx = 0; idx < sdl.size(); ++idx) { + scoreDocs[idx] = new ScoreDoc(idx /* doc */, 0f /* score */, crb_idx /* shardIndex */); + } + + final TotalHits totalHits = + new TotalHits( + sdl.getNumFound(), + sdl.getNumFoundExact() + ? TotalHits.Relation.EQUAL_TO + : TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO); + + hits[crb_idx] = new TopDocs(totalHits, scoreDocs); + } + + final var params = crb.req.getParams(); + final int topN = params.getInt(CommonParams.ROWS, CommonParams.ROWS_DEFAULT); + final int k = params.getInt("rrf.k", 1); + + final TopDocs fusion = TopDocs.rrf(topN, k, hits); + + for (ScoreDoc scoreDoc : fusion.scoreDocs) { + responseDocs.add( + crb.responseBuilders.get(scoreDoc.shardIndex).getResponseDocs().get(scoreDoc.doc)); + } + final TotalHits totalHits = fusion.totalHits; + responseDocs.setNumFound(totalHits.value()); + responseDocs.setNumFoundExact(TotalHits.Relation.EQUAL_TO.equals(totalHits.relation())); + + crb.setResponseDocs(responseDocs); + + return ResponseBuilder.STAGE_DONE; + } + + @Override + public void handleResponses(ResponseBuilder rb, ShardRequest sreq) { + if (rb instanceof CompoundResponseBuilder crb) { + for (var rb_i : crb.responseBuilders) { + if (rb_i.isThisFromMe(sreq)) { + super.handleResponses(rb_i, sreq); Review Comment: Are we using mergeIds on each of the crb and overriding the rb.resultIds? ########## solr/core/src/java/org/apache/solr/handler/component/CompoundQueryComponent.java: ########## @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.handler.component; + +import java.io.IOException; +import java.util.HashMap; +import org.apache.lucene.search.ScoreDoc; +import org.apache.lucene.search.TopDocs; +import org.apache.lucene.search.TotalHits; +import org.apache.solr.common.SolrDocumentList; +import org.apache.solr.common.params.CommonParams; + +public class CompoundQueryComponent extends QueryComponent { + public static final String COMPONENT_NAME = "compound_query"; + + @Override + public void prepare(ResponseBuilder rb) throws IOException { + if (rb instanceof CompoundResponseBuilder crb) { + final var params = rb.req.getParams(); + if (params.get(CompoundResponseBuilder.RRF_PREFIX) == null) { + for (var prefix : params.get(CompoundResponseBuilder.RRF_PREFIX + ".list").split(",")) { + crb.responseBuilders.add(new CompoundResponseBuilder.Inner(crb, prefix)); + } + for (var rb_i : crb.responseBuilders) { + super.prepare(rb_i); + } + } else { + super.prepare(rb); + } + } + } + + @Override + public int distributedProcess(ResponseBuilder rb) throws IOException { + int nextStage = ResponseBuilder.STAGE_DONE; + if (rb instanceof CompoundResponseBuilder crb) { + if (rb.getStage() < CompoundResponseBuilder.STAGE_FUSION) { + for (var rb_i : crb.responseBuilders) { + nextStage = Math.min(nextStage, super.distributedProcess(rb_i)); + } + } else if (rb.getStage() == CompoundResponseBuilder.STAGE_FUSION) { + nextStage = doFusion(crb); + } + } + return nextStage; + } + + private int doFusion(CompoundResponseBuilder crb) { + final SolrDocumentList responseDocs = new SolrDocumentList(); + final TopDocs[] hits = new TopDocs[crb.responseBuilders.size()]; + for (int crb_idx = 0; crb_idx < crb.responseBuilders.size(); ++crb_idx) { + + final SolrDocumentList sdl = crb.responseBuilders.get(crb_idx).getResponseDocs(); Review Comment: I am wondering where is this being populated? -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
