mirror of https://github.com/apache/lucene.git
woops, not just yet
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1587852 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
26967b0114
commit
87defc3464
|
@ -313,7 +313,6 @@ public class BooleanQuery extends Query implements Iterable<BooleanClause> {
|
|||
return super.bulkScorer(context, scoreDocsInOrder, acceptDocs);
|
||||
}
|
||||
|
||||
List<Scorer> required = new ArrayList<Scorer>();
|
||||
List<BulkScorer> prohibited = new ArrayList<BulkScorer>();
|
||||
List<BulkScorer> optional = new ArrayList<BulkScorer>();
|
||||
Iterator<BooleanClause> cIter = clauses.iterator();
|
||||
|
@ -328,11 +327,7 @@ public class BooleanQuery extends Query implements Iterable<BooleanClause> {
|
|||
// TODO: there are some cases where BooleanScorer
|
||||
// would handle conjunctions faster than
|
||||
// BooleanScorer2...
|
||||
// return super.bulkScorer(context, scoreDocsInOrder, acceptDocs);
|
||||
Scorer requiredSubScorer = w.scorer(context, acceptDocs);
|
||||
if ( requiredSubScorer == null ) return null;
|
||||
required.add(requiredSubScorer);
|
||||
|
||||
return super.bulkScorer(context, scoreDocsInOrder, acceptDocs);
|
||||
} else if (c.isProhibited()) {
|
||||
prohibited.add(subScorer);
|
||||
} else {
|
||||
|
@ -341,7 +336,7 @@ public class BooleanQuery extends Query implements Iterable<BooleanClause> {
|
|||
}
|
||||
|
||||
// Check if we can and should return a BooleanScorer
|
||||
return new BooleanScorer(this, disableCoord, minNrShouldMatch, required, optional, prohibited, maxCoord);
|
||||
return new BooleanScorer(this, disableCoord, minNrShouldMatch, optional, prohibited, maxCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -61,7 +61,7 @@ import org.apache.lucene.search.BooleanQuery.BooleanWeight;
|
|||
|
||||
final class BooleanScorer extends BulkScorer {
|
||||
|
||||
private /*static*/ final class BooleanScorerCollector extends SimpleCollector {
|
||||
private static final class BooleanScorerCollector extends SimpleCollector {
|
||||
private BucketTable bucketTable;
|
||||
private int mask;
|
||||
private Scorer scorer;
|
||||
|
@ -77,19 +77,18 @@ final class BooleanScorer extends BulkScorer {
|
|||
final int i = doc & BucketTable.MASK;
|
||||
final Bucket bucket = table.buckets[i];
|
||||
|
||||
final int coord = (mask & REQUIRED_MASK) == REQUIRED_MASK ? requiredNrMatchers : 1;
|
||||
if (bucket.doc != doc) { // invalid bucket
|
||||
bucket.doc = doc; // set doc
|
||||
bucket.score = scorer.score(); // initialize score
|
||||
bucket.bits = mask; // initialize mask
|
||||
bucket.coord = /*1*/coord; // initialize coord
|
||||
bucket.coord = 1; // initialize coord
|
||||
|
||||
bucket.next = table.first; // push onto valid list
|
||||
table.first = bucket;
|
||||
} else { // valid bucket
|
||||
bucket.score += scorer.score(); // increment score
|
||||
bucket.bits |= mask; // add bits in mask
|
||||
bucket.coord/*++*/+= coord; // increment coord
|
||||
bucket.coord++; // increment coord
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,7 +116,7 @@ final class BooleanScorer extends BulkScorer {
|
|||
}
|
||||
|
||||
/** A simple hash table of document scores within a range. */
|
||||
/*static*/ final class BucketTable {
|
||||
static final class BucketTable {
|
||||
public static final int SIZE = 1 << 11;
|
||||
public static final int MASK = SIZE - 1;
|
||||
|
||||
|
@ -141,7 +140,8 @@ final class BooleanScorer extends BulkScorer {
|
|||
|
||||
static final class SubScorer {
|
||||
public BulkScorer scorer;
|
||||
public boolean required = false;
|
||||
// TODO: re-enable this if BQ ever sends us required clauses
|
||||
//public boolean required = false;
|
||||
public boolean prohibited;
|
||||
public LeafCollector collector;
|
||||
public SubScorer next;
|
||||
|
@ -149,9 +149,13 @@ final class BooleanScorer extends BulkScorer {
|
|||
|
||||
public SubScorer(BulkScorer scorer, boolean required, boolean prohibited,
|
||||
LeafCollector collector, SubScorer next) {
|
||||
if (required) {
|
||||
throw new IllegalArgumentException("this scorer cannot handle required=true");
|
||||
}
|
||||
this.scorer = scorer;
|
||||
this.more = true;
|
||||
this.required = required;
|
||||
// TODO: re-enable this if BQ ever sends us required clauses
|
||||
//this.required = required;
|
||||
this.prohibited = prohibited;
|
||||
this.collector = collector;
|
||||
this.next = next;
|
||||
|
@ -161,31 +165,21 @@ final class BooleanScorer extends BulkScorer {
|
|||
private SubScorer scorers = null;
|
||||
private BucketTable bucketTable = new BucketTable();
|
||||
private final float[] coordFactors;
|
||||
// TODO: re-enable this if BQ ever sends us required clauses
|
||||
//private int requiredMask = 0;
|
||||
private final int minNrShouldMatch;
|
||||
private int end;
|
||||
private Bucket current;
|
||||
// Any time a prohibited clause matches we set bit 0:
|
||||
private static final int PROHIBITED_MASK = 1;
|
||||
// Any time a prohibited clause matches we set bit 1:
|
||||
private static final int REQUIRED_MASK = 2;
|
||||
private final int requiredNrMatchers;
|
||||
|
||||
private final Weight weight;
|
||||
|
||||
BooleanScorer(BooleanWeight weight, boolean disableCoord, int minNrShouldMatch,
|
||||
List<Scorer> requiredScorers, List<BulkScorer> optionalScorers, List<BulkScorer> prohibitedScorers,
|
||||
int maxCoord) throws IOException {
|
||||
|
||||
List<BulkScorer> optionalScorers, List<BulkScorer> prohibitedScorers, int maxCoord) throws IOException {
|
||||
this.minNrShouldMatch = minNrShouldMatch;
|
||||
this.weight = weight;
|
||||
|
||||
this.requiredNrMatchers = requiredScorers.size();
|
||||
if ( this.requiredNrMatchers > 0 ) {
|
||||
BulkScorer requiredScorer = new Weight.DefaultBulkScorer(new ConjunctionScorer(
|
||||
this.weight, requiredScorers.toArray(new Scorer[requiredScorers.size()])));
|
||||
scorers = new SubScorer(requiredScorer, true, false, bucketTable.newCollector(REQUIRED_MASK), scorers);
|
||||
}
|
||||
|
||||
for (BulkScorer scorer : optionalScorers) {
|
||||
scorers = new SubScorer(scorer, false, false, bucketTable.newCollector(0), scorers);
|
||||
}
|
||||
|
@ -194,8 +188,7 @@ final class BooleanScorer extends BulkScorer {
|
|||
scorers = new SubScorer(scorer, false, true, bucketTable.newCollector(PROHIBITED_MASK), scorers);
|
||||
}
|
||||
|
||||
// TODO: required add requriredScorer.size().
|
||||
coordFactors = new float[requiredScorers.size() + optionalScorers.size() + 1];
|
||||
coordFactors = new float[optionalScorers.size() + 1];
|
||||
for (int i = 0; i < coordFactors.length; i++) {
|
||||
coordFactors[i] = disableCoord ? 1.0f : weight.coord(i, maxCoord);
|
||||
}
|
||||
|
@ -216,8 +209,11 @@ final class BooleanScorer extends BulkScorer {
|
|||
while (current != null) { // more queued
|
||||
|
||||
// check prohibited & required
|
||||
if ((current.bits & PROHIBITED_MASK) == 0 &&
|
||||
(requiredNrMatchers == 0 || (current.bits & REQUIRED_MASK) == REQUIRED_MASK)) {
|
||||
if ((current.bits & PROHIBITED_MASK) == 0) {
|
||||
|
||||
// TODO: re-enable this if BQ ever sends us required
|
||||
// clauses
|
||||
//&& (current.bits & requiredMask) == requiredMask) {
|
||||
|
||||
// NOTE: Lucene always passes max =
|
||||
// Integer.MAX_VALUE today, because we never embed
|
||||
|
@ -233,7 +229,7 @@ final class BooleanScorer extends BulkScorer {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (current.coord >= minNrShouldMatch + requiredNrMatchers) {
|
||||
if (current.coord >= minNrShouldMatch) {
|
||||
fs.score = (float) (current.score * coordFactors[current.coord]);
|
||||
fs.doc = current.doc;
|
||||
fs.freq = current.coord;
|
||||
|
|
|
@ -78,8 +78,6 @@ public class MultiTermQueryWrapperFilter<Q extends MultiTermQuery> extends Filte
|
|||
/** Returns the field name for this query */
|
||||
public final String getField() { return query.getField(); }
|
||||
|
||||
public static long rewriteTermCount;
|
||||
|
||||
/**
|
||||
* Returns a DocIdSet with documents that should be permitted in search
|
||||
* results.
|
||||
|
@ -106,7 +104,6 @@ public class MultiTermQueryWrapperFilter<Q extends MultiTermQuery> extends Filte
|
|||
final FixedBitSet bitSet = new FixedBitSet(context.reader().maxDoc());
|
||||
DocsEnum docsEnum = null;
|
||||
do {
|
||||
rewriteTermCount++;
|
||||
// System.out.println(" iter termCount=" + termCount + " term=" +
|
||||
// enumerator.term().toBytesString());
|
||||
docsEnum = termsEnum.docs(acceptDocs, docsEnum, DocsEnum.FLAG_NONE);
|
||||
|
|
|
@ -96,7 +96,7 @@ public class TestBooleanScorer extends LuceneTestCase {
|
|||
}
|
||||
}};
|
||||
|
||||
BooleanScorer bs = new BooleanScorer(weight, false, 1, Collections.<Scorer>emptyList(), Arrays.asList(scorers), Collections.<BulkScorer>emptyList(), scorers.length);
|
||||
BooleanScorer bs = new BooleanScorer(weight, false, 1, Arrays.asList(scorers), Collections.<BulkScorer>emptyList(), scorers.length);
|
||||
|
||||
final List<Integer> hits = new ArrayList<>();
|
||||
bs.score(new SimpleCollector() {
|
||||
|
|
|
@ -93,16 +93,17 @@ import org.apache.lucene.util.Version;
|
|||
* on prefix matches to any tokens in the indexed text.
|
||||
* This also highlights the tokens that match.
|
||||
*
|
||||
* <p>This suggester supports payloads. Matches are sorted only
|
||||
* <p>This just uses an ordinary Lucene index. It
|
||||
* supports payloads, and records these as a
|
||||
* {@link BinaryDocValues} field. Matches are sorted only
|
||||
* by the suggest weight; it would be nice to support
|
||||
* blended score + weight sort in the future. This means
|
||||
* this suggester best applies when there is a strong
|
||||
* a-priori ranking of all the suggestions.
|
||||
* apriori ranking of all the suggestions.
|
||||
*
|
||||
* <p>This suggester supports contexts, however the
|
||||
* contexts must be valid utf8 (arbitrary binary terms will
|
||||
* not work).
|
||||
*
|
||||
* @lucene.experimental */
|
||||
|
||||
public class AnalyzingInfixSuggester extends Lookup implements Closeable {
|
||||
|
@ -140,18 +141,14 @@ public class AnalyzingInfixSuggester extends Lookup implements Closeable {
|
|||
private static final Sort SORT = new Sort(new SortField("weight", SortField.Type.LONG, true));
|
||||
|
||||
/** Create a new instance, loading from a previously built
|
||||
* AnalyzingInfixSuggester directory, if it exists. This directory must be
|
||||
* private to the infix suggester (i.e., not an external
|
||||
* Lucene index). Note that {@link #close}
|
||||
* directory, if it exists. Note that {@link #close}
|
||||
* will also close the provided directory. */
|
||||
public AnalyzingInfixSuggester(Version matchVersion, Directory dir, Analyzer analyzer) throws IOException {
|
||||
this(matchVersion, dir, analyzer, analyzer, DEFAULT_MIN_PREFIX_CHARS);
|
||||
}
|
||||
|
||||
/** Create a new instance, loading from a previously built
|
||||
* AnalyzingInfixSuggester directory, if it exists. This directory must be
|
||||
* private to the infix suggester (i.e., not an external
|
||||
* Lucene index). Note that {@link #close}
|
||||
* directory, if it exists. Note that {@link #close}
|
||||
* will also close the provided directory.
|
||||
*
|
||||
* @param minPrefixChars Minimum number of leading characters
|
||||
|
|
Loading…
Reference in New Issue