kotman12 commented on code in PR #2382:
URL: https://github.com/apache/solr/pull/2382#discussion_r1840998844


##########
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:
   I can revert .. this was also driven by user feedback. Lucene-monitor 
decomposes top-level disjunctions, i.e. `this or that` into two separate 
queries `this` and `that` which roll up to the same queryId but are indexed as 
separate documents for performance reasons. Basically I wanted to deduplicate 
and was under the impression that query/leaf collectors _weren't_ thread-safe 
and would always be called by a single thread at a time. But perhaps thats not 
true or its too much of an implementation detail. I haven't yet considered 
where else this deduplication could go...



-- 
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

Reply via email to