Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

getDocSet optimized for TermQuery

Yonik Seeley0fcfe874c944
diff --git a/CHANGES.txt b/CHANGES.txt
index fa410c5d1f2..9fe670ac870 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -80,6 +80,9 @@ Optimizations
Iteration is faster, and BitDocSet.intersectionSize(BitDocSet) and unionSize
is between 3 and 4 times faster. (yonik, SOLR-15)
4. much faster unionSize when one of the sets is a HashDocSet: O(smaller_set_size)
+ 5. Optimized getDocSet() for term queries resulting in a 36% speedup of facet.field
+ queries where DocSets aren't cached (for example, if the number of terms in the field
+ is larger than the filter cache.) (yonik)
Bug Fixes
1. Fixed delete-by-id for field types who's indexed form is different
diff --git a/src/java/org/apache/solr/search/SolrIndexSearcher.java b/src/java/org/apache/solr/search/SolrIndexSearcher.java
index 77db98744c6..73197b1ed49 100644
--- a/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -458,12 +458,23 @@ public class SolrIndexSearcher extends Searcher implements SolrInfoMBean {
}
-
protected DocSet getDocSetNC(Query query, DocSet filter) throws IOException {
if (filter==null) {
DocSetHitCollector hc = new DocSetHitCollector(maxDoc());
- searcher.search(query,null,hc);
+ if (query instanceof TermQuery) {
+ Term t = ((TermQuery)query).getTerm();
+ TermDocs tdocs = null;
+ try {
+ tdocs = reader.termDocs(t);
+ while (tdocs.next()) hc.collect(tdocs.doc(),0.0f);
+ } finally {
+ if (tdocs!=null) tdocs.close();
+ }
+ } else {
+ searcher.search(query,null,hc);
+ }
return hc.getDocSet();
+
} else {
// FUTURE: if the filter is sorted by docid, could use skipTo (SkipQueryFilter)
final DocSetHitCollector hc = new DocSetHitCollector(maxDoc());
@@ -1041,7 +1052,6 @@ public class SolrIndexSearcher extends Searcher implements SolrInfoMBean {
/**
* A simple utility method for to build a filterList from a query
* @param filter
- * @return
*/
private List<Query> buildQueryList(Query filter) {
List<Query> filterList = null;