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


##########
solr/modules/monitor/src/java/org/apache/solr/monitor/search/ReverseSearchComponent.java:
##########
@@ -0,0 +1,223 @@
+/*
+ *
+ *  * 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 static org.apache.solr.monitor.MonitorConstants.MONITOR_DOCUMENTS_KEY;
+import static 
org.apache.solr.monitor.search.PresearcherFactory.DEFAULT_ALIAS_PREFIX;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.function.BiPredicate;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.monitor.DocumentBatchVisitor;
+import org.apache.lucene.monitor.MonitorFields;
+import org.apache.lucene.monitor.Presearcher;
+import org.apache.lucene.monitor.QueryDecomposer;
+import org.apache.lucene.monitor.QueryMatch;
+import org.apache.lucene.monitor.TermFilteredPresearcher;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.MatchAllDocsQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.util.BytesRef;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.handler.component.QueryComponent;
+import org.apache.solr.handler.component.ResponseBuilder;
+import org.apache.solr.handler.loader.JsonLoader;
+import org.apache.solr.monitor.AliasingPresearcher;
+import org.apache.solr.monitor.SolrMonitorQueryDecoder;
+import org.apache.solr.monitor.cache.MonitorQueryCache;
+import org.apache.solr.monitor.cache.SharedMonitorCache;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.schema.SchemaField;
+import org.apache.solr.update.DocumentBuilder;
+import org.apache.solr.util.SolrPluginUtils;
+import org.apache.solr.util.plugin.SolrCoreAware;
+
+public class ReverseSearchComponent extends QueryComponent implements 
SolrCoreAware {
+
+  public static final String COMPONENT_NAME = "reverseSearch";
+
+  private static final String SOLR_MONITOR_CACHE_NAME_KEY = 
"solrMonitorCacheName";
+  private static final String SOLR_MONITOR_CACHE_NAME_DEFAULT = 
"solrMonitorCache";
+  private String solrMonitorCacheName = SOLR_MONITOR_CACHE_NAME_DEFAULT;
+
+  private QueryDecomposer queryDecomposer;
+  private Presearcher presearcher;
+  private PresearcherFactory.PresearcherParameters presearcherParameters;
+
+  @Override
+  public void init(NamedList<?> args) {
+    super.init(args);
+    Object solrMonitorCacheName = args.remove(SOLR_MONITOR_CACHE_NAME_KEY);
+    if (solrMonitorCacheName != null) {
+      this.solrMonitorCacheName = (String) solrMonitorCacheName;
+    }
+    presearcherParameters = new PresearcherFactory.PresearcherParameters();
+    SolrPluginUtils.invokeSetters(presearcherParameters, args);
+  }
+
+  @Override
+  public void prepare(ResponseBuilder rb) throws IOException {
+    super.prepare(rb);
+    var req = rb.req;
+    var documentBatch = documentBatch(req);
+    var matcherSink =
+        new SyncSolrMatcherSink<>(
+            QueryMatch.SIMPLE_MATCHER::createMatcher,
+            new IndexSearcher(documentBatch.get()),
+            matchingQueries -> {
+              if (rb.isDebug()) {
+                rb.req
+                    .getContext()
+                    .put(
+                        ReverseSearchDebugComponent.ReverseSearchDebugInfo.KEY,
+                        new ReverseSearchDebugComponent.ReverseSearchDebugInfo(
+                            matchingQueries.getQueriesRun()));
+              }
+            });
+    Query preFilterQuery = presearcher.buildQuery(documentBatch.get(), 
getTermAcceptor(rb.req));
+    List<Query> mutableFilters =
+        
Optional.ofNullable(rb.getFilters()).map(ArrayList::new).orElseGet(ArrayList::new);
+    rb.setQuery(new MatchAllDocsQuery());
+    mutableFilters.add(preFilterQuery);
+    var searcher = req.getSearcher();
+    MonitorQueryCache solrMonitorCache =
+        (SharedMonitorCache) searcher.getCache(this.solrMonitorCacheName);
+    SolrMonitorQueryDecoder queryDecoder = new 
SolrMonitorQueryDecoder(req.getCore());

Review Comment:
   From code reading
   ```suggestion
       SolrMonitorQueryDecoder queryDecoder = new 
SolrMonitorQueryDecoder(this.queryDecomposer);
   ```
   
   looks possible here, will attempt to do that.
   
   edit: never mind, it looked tempting to remove the SolrCore (and thus solr) 
dependency from the class but the core is needed for the 
`SharedMonitorCacheLatestRegenerator` code path.



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

Reply via email to