cpoerschke commented on code in PR #2382: URL: https://github.com/apache/solr/pull/2382#discussion_r1840661574
########## solr/modules/monitor/src/java/org/apache/solr/monitor/search/SolrMonitorQueryCollector.java: ########## @@ -0,0 +1,104 @@ +/* + * + * * 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.monitor.search; + +import java.io.IOException; +import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.monitor.QCEVisitor; +import org.apache.lucene.search.ConstantScoreQuery; +import org.apache.lucene.search.ScoreMode; +import org.apache.solr.monitor.MonitorDataValues; +import org.apache.solr.monitor.SolrMonitorQueryDecoder; +import org.apache.solr.monitor.cache.MonitorQueryCache; +import org.apache.solr.search.DelegatingCollector; + +class SolrMonitorQueryCollector extends DelegatingCollector { + + private final MonitorQueryCache monitorQueryCache; + private final SolrMonitorQueryDecoder queryDecoder; + private final SolrMatcherSink matcherSink; + private final MonitorDataValues dataValues = new MonitorDataValues(); + private String lastQueryId; + + SolrMonitorQueryCollector(CollectorContext collectorContext) { + this.monitorQueryCache = collectorContext.queryCache; + this.queryDecoder = collectorContext.queryDecoder; + this.matcherSink = collectorContext.solrMatcherSink; + } + + @Override + public void collect(int doc) throws IOException { + dataValues.advanceTo(doc); + var entry = getEntry(dataValues); + var queryId = dataValues.getQueryId(); + var originalMatchQuery = entry.getMatchQuery(); + + var matchQuery = new ConstantScoreQuery(originalMatchQuery); + + boolean isMatch = matcherSink.matchQuery(queryId, matchQuery, entry.getMetadata()); + if (isMatch && !queryId.equals(lastQueryId)) { + lastQueryId = queryId; + super.collect(doc); + } Review Comment: Seeking to better understand the `lastQueryId` logic here: * could this method be called from multiple threads concurrently? * could the equality check happen earlier? what would happen if there was no check and the `doc` was always collected if there's a match? ```suggestion if (!queryId.equals(lastQueryId)) { var originalMatchQuery = entry.getMatchQuery(); var matchQuery = new ConstantScoreQuery(originalMatchQuery); boolean isMatch = matcherSink.matchQuery(queryId, matchQuery, entry.getMetadata()); if (isMatch) { lastQueryId = queryId; super.collect(doc); } } ``` vs. ```suggestion var originalMatchQuery = entry.getMatchQuery(); var matchQuery = new ConstantScoreQuery(originalMatchQuery); boolean isMatch = matcherSink.matchQuery(queryId, matchQuery, entry.getMetadata()); if (isMatch) { super.collect(doc); } ``` -- 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: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org