mirror of https://github.com/apache/lucene.git
SOLR-7815: Removed LuceneQueryOptimizer.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1692070 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3be6ef209b
commit
3b63fbe07a
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue