diff --git a/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java b/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java index 56b5771c8f1..f0cc31961b2 100644 --- a/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java @@ -313,7 +313,6 @@ public class BooleanQuery extends Query implements Iterable { return super.bulkScorer(context, scoreDocsInOrder, acceptDocs); } - List required = new ArrayList(); List prohibited = new ArrayList(); List optional = new ArrayList(); Iterator cIter = clauses.iterator(); @@ -328,11 +327,7 @@ public class BooleanQuery extends Query implements Iterable { // 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 { } // 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 diff --git a/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java b/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java index 41f70fa0cdd..173bb44760b 100644 --- a/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java @@ -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,30 +165,20 @@ 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 requiredScorers, List optionalScorers, List prohibitedScorers, - int maxCoord) throws IOException { - + BooleanScorer(BooleanWeight weight, boolean disableCoord, int minNrShouldMatch, + List optionalScorers, List 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,9 +209,12 @@ 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 // a BooleanScorer inside another (even though @@ -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; diff --git a/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java b/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java index 3524b9b9bd2..0fea8639c6b 100644 --- a/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java +++ b/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java @@ -77,8 +77,6 @@ public class MultiTermQueryWrapperFilter 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 @@ -106,7 +104,6 @@ public class MultiTermQueryWrapperFilter 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); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java b/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java index 69d71afe71b..358a513bacb 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java @@ -96,7 +96,7 @@ public class TestBooleanScorer extends LuceneTestCase { } }}; - BooleanScorer bs = new BooleanScorer(weight, false, 1, Collections.emptyList(), Arrays.asList(scorers), Collections.emptyList(), scorers.length); + BooleanScorer bs = new BooleanScorer(weight, false, 1, Arrays.asList(scorers), Collections.emptyList(), scorers.length); final List hits = new ArrayList<>(); bs.score(new SimpleCollector() { diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java index b454128f034..421dcb9daf7 100644 --- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java +++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java @@ -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. * - *

This suggester supports payloads. Matches are sorted only + *

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. * *

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