Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-7815: Removed LuceneQueryOptimizer.

Adrien Grand3b63fbe07a8e
diff --git a/solr/core/src/java/org/apache/solr/search/LuceneQueryOptimizer.java b/solr/core/src/java/org/apache/solr/search/LuceneQueryOptimizer.java
deleted file mode 100644
index 92cc97d87c4..00000000000
--- a/solr/core/src/java/org/apache/solr/search/LuceneQueryOptimizer.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * 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.search;
-
-/* Copyright (c) 2003 The Nutch Organization. All rights reserved. */
-/* Use subject to the conditions in http://www.nutch.org/LICENSE.txt. */
-
-
-import org.apache.lucene.search.*;
-import org.apache.lucene.search.BooleanClause.Occur;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.io.IOException;
-
-/** Utility which converts certain query clauses into {@link QueryWrapperFilter}s and
- * caches these. Only required {@link TermQuery}s whose boost is zero and
- * whose term occurs in at least a certain fraction of documents are converted
- * to cached filters. This accelerates query constraints like language,
- * document format, etc., which do not affect ranking but might otherwise slow
- * search considerably. */
-// Taken from Nutch and modified - YCS
-class LuceneQueryOptimizer {
- private LinkedHashMap cache; // an LRU cache of QueryFilter
-
- private float threshold;
-
- /** Construct an optimizer that caches and uses filters for required {@link
- * TermQuery}s whose boost is zero.
- * @param cacheSize the number of QueryFilters to cache
- * @param threshold the fraction of documents which must contain term
- */
- public LuceneQueryOptimizer(final int cacheSize, float threshold) {
- this.cache = new LinkedHashMap(cacheSize, 0.75f, true) {
- @Override
- protected boolean removeEldestEntry(Map.Entry eldest) {
- return size() > cacheSize; // limit size of cache
- }
- };
- this.threshold = threshold;
- }
-
- public TopDocs optimize(BooleanQuery original,
- SolrIndexSearcher searcher,
- int numHits,
- Query[] queryOut,
- Filter[] filterOut
- )
- throws IOException {
-
- BooleanQuery.Builder query = new BooleanQuery.Builder();
- BooleanQuery.Builder filterQuery = null;
-
- for (BooleanClause c : original.clauses()) {
-
-/***
-System.out.println("required="+c.required);
-System.out.println("boost="+c.query.getBoost());
-System.out.println("isTermQuery="+(c.query instanceof TermQuery));
-if (c.query instanceof TermQuery) {
- System.out.println("term="+((TermQuery)c.query).getTerm());
- System.out.println("docFreq="+searcher.docFreq(((TermQuery)c.query).getTerm()));
-}
-***/
- Query q = c.getQuery();
- if (c.isRequired() // required
- && q.getBoost() == 0.0f // boost is zero
- && q instanceof TermQuery // TermQuery
- && (searcher.docFreq(((TermQuery)q).getTerm())
- / (float)searcher.maxDoc()) >= threshold) { // check threshold
- if (filterQuery == null)
- filterQuery = new BooleanQuery.Builder();
- filterQuery.add(q, BooleanClause.Occur.MUST); // filter it
-//System.out.println("WooHoo... qualified to be hoisted to a filter!");
- } else {
- query.add(c); // query it
- }
- }
-
- Filter filter = null;
- if (filterQuery != null) {
- synchronized (cache) { // check cache
- filter = (Filter)cache.get(filterQuery);
- }
- if (filter == null) { // miss
- filter = new QueryWrapperFilter(new CachingWrapperQuery(filterQuery.build())); // construct new entry
- synchronized (cache) {
- cache.put(filterQuery, filter); // cache it
- }
- }
- }
-
- // YCS: added code to pass out optimized query and filter
- // so they can be used with Hits
- if (queryOut != null && filterOut != null) {
- queryOut[0] = query.build(); filterOut[0] = filter;
- return null;
- } else {
- query.add(filter, Occur.FILTER);
- return searcher.search(query.build(), numHits);
- }
-
- }
-}
diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
index bbe2e6d0d04..4249d11add0 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -131,8 +131,6 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,SolrIn
private final SolrCache<Integer,StoredDocument> documentCache;
private final SolrCache<String,UnInvertedField> fieldValueCache;
- private final LuceneQueryOptimizer optimizer;
-
// map of generic caches - not synchronized since it's read-only after the constructor.
private final HashMap<String, SolrCache> cacheMap;
private static final HashMap<String, SolrCache> noGenericCaches=new HashMap<>(0);
@@ -296,10 +294,6 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,SolrIn
cacheMap = noGenericCaches;
cacheList= noCaches;
}
-
- // TODO: This option has been dead/noop since 3.1, should we re-enable it?
-// optimizer = solrConfig.filtOptEnabled ? new LuceneQueryOptimizer(solrConfig.filtOptCacheSize,solrConfig.filtOptThreshold) : null;
- optimizer = null;
fieldNames = new HashSet<>();
fieldInfos = leafReader.getFieldInfos();