SOLR-2205: Search Grouping - test for doc competitiveness before looking up group

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1028464 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2010-10-28 20:38:19 +00:00
parent dd42b928c7
commit d4f2f62c42
5 changed files with 61 additions and 7 deletions

View File

@ -143,6 +143,7 @@ class TopGroupCollector extends GroupCollector {
int spareSlot;
int matches;
boolean groupsFull = false;
public TopGroupCollector(ValueSource groupByVS, Map vsContext, Sort sort, int nGroups) throws IOException {
this.vs = groupByVS;
@ -173,6 +174,29 @@ class TopGroupCollector extends GroupCollector {
@Override
public void collect(int doc) throws IOException {
matches++;
// Doing this before ValueFiller and HashMap are executed
// This allows us to exit this method asap when a doc is not competitive
// As it turns out this happens most of the times.
if (groupsFull) {
for (int i = 0;; i++) {
final int c = reversed[i] * comparators[i].compareBottom(doc);
if (c < 0) {
// Definitely not competitive. So don't even bother to continue
return;
} else if (c > 0) {
// Definitely competitive.
break;
} else if (i == comparators.length - 1) {
// Here c=0. If we're at the last comparator, this doc is not
// competitive, since docs are visited in doc Id order, which means
// this doc cannot compete with any other document in the queue.
return;
}
}
}
// These next two statements are expensive
filler.fillValue(doc);
SearchGroup group = groupMap.get(mval);
if (group == null) {
@ -191,6 +215,7 @@ class TopGroupCollector extends GroupCollector {
}
if (orderedGroups == null) {
groupsFull = true;
buildSet();
}

View File

@ -17,32 +17,33 @@
package org.apache.solr.search;
import org.apache.lucene.document.*;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.FieldSelector;
import org.apache.lucene.document.FieldSelectorResult;
import org.apache.lucene.index.*;
import org.apache.lucene.search.*;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.OpenBitSet;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrInfoMBean;
import org.apache.solr.request.UnInvertedField;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.request.UnInvertedField;
import org.apache.lucene.util.OpenBitSet;
import org.apache.solr.search.function.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URL;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.solr.search.function.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* SolrIndexSearcher adds schema awareness and caching functionality

View File

@ -46,6 +46,18 @@ public abstract class DocValues {
public double doubleVal(int doc) { throw new UnsupportedOperationException(); }
// TODO: should we make a termVal, returns BytesRef?
public String strVal(int doc) { throw new UnsupportedOperationException(); }
/**
* @param doc The doc to retrieve to sort ordinal for
* @return the sort ordinal for the specified doc
* TODO: Maybe we can just use intVal for this...
*/
public int ordVal(int doc) { throw new UnsupportedOperationException(); }
/**
* @return the number of unique sort ordinals this instance has
*/
public int numOrd() { throw new UnsupportedOperationException(); }
public abstract String toString(int doc);
/** @lucene.experimental */

View File

@ -74,6 +74,14 @@ public class OrdFieldSource extends ValueSource {
return (double)termsIndex.getOrd(doc);
}
public int ordVal(int doc) {
return termsIndex.getOrd(doc);
}
public int numOrd() {
return termsIndex.numOrd();
}
public String strVal(int doc) {
// the string value of the ordinal, not the string itself
return Integer.toString(termsIndex.getOrd(doc));

View File

@ -73,6 +73,14 @@ public class ReverseOrdFieldSource extends ValueSource {
return (long)(end - sindex.getOrd(doc));
}
public int ordVal(int doc) {
return (end - sindex.getOrd(doc));
}
public int numOrd() {
return end;
}
public double doubleVal(int doc) {
return (double)(end - sindex.getOrd(doc));
}