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