public virtual void TestEmptyBucketWithMoreDocs() { // this test checks the logic of nextDoc() when all sub scorers have docs // beyond the first bucket (for example). Currently, the code relies on the // 'more' variable to work properly, and this test ensures that if the logic // changes, we have a test to back it up. Directory directory = NewDirectory(); RandomIndexWriter writer = new RandomIndexWriter(Random(), directory, Similarity, TimeZone); writer.Commit(); IndexReader ir = writer.Reader; writer.Dispose(); IndexSearcher searcher = NewSearcher(ir); BooleanWeight weight = (BooleanWeight)(new BooleanQuery()).CreateWeight(searcher); BulkScorer[] scorers = new BulkScorer[] { new BulkScorerAnonymousInnerClassHelper() }; BooleanScorer bs = new BooleanScorer(weight, false, 1, Arrays.AsList(scorers), new List <BulkScorer>(), scorers.Length); IList <int> hits = new List <int>(); bs.Score(new CollectorAnonymousInnerClassHelper(this, hits)); Assert.AreEqual(1, hits.Count, "should have only 1 hit"); Assert.AreEqual(3000, (int)hits[0], "hit should have been docID=3000"); ir.Dispose(); directory.Dispose(); }
internal SlowMinShouldMatchScorer(BooleanWeight weight, AtomicReader reader, IndexSearcher searcher) : base(weight) { this.Dv = reader.GetSortedSetDocValues("dv"); this.MaxDoc = reader.MaxDoc; BooleanQuery bq = (BooleanQuery)weight.Query; this.MinNrShouldMatch = bq.MinimumNumberShouldMatch; this.Sims = new SimScorer[(int)Dv.ValueCount]; foreach (BooleanClause clause in bq.Clauses) { Debug.Assert(!clause.Prohibited); Debug.Assert(!clause.Required); Term term = ((TermQuery)clause.Query).Term; long ord = Dv.LookupTerm(term.Bytes); if (ord >= 0) { bool success = Ords.Add(ord); Debug.Assert(success); // no dups TermContext context = TermContext.Build(reader.Context, term); SimWeight w = weight.Similarity.ComputeWeight(1f, searcher.CollectionStatistics("field"), searcher.TermStatistics(term, context)); var dummy = w.ValueForNormalization; // ignored w.Normalize(1F, 1F); Sims[(int)ord] = weight.Similarity.DoSimScorer(w, (AtomicReaderContext)reader.Context); } } }
/// <summary> /// Creates a <see cref="Scorer"/> with the given similarity and lists of required, /// prohibited and optional scorers. In no required scorers are added, at least /// one of the optional scorers will have to match during the search. /// </summary> /// <param name="weight"> /// The <see cref="BooleanWeight"/> to be used. </param> /// <param name="disableCoord"> /// If this parameter is <c>true</c>, coordination level matching /// (<see cref="Similarities.Similarity.Coord(int, int)"/>) is not used. </param> /// <param name="minNrShouldMatch"> /// The minimum number of optional added scorers that should match /// during the search. In case no required scorers are added, at least /// one of the optional scorers will have to match during the search. </param> /// <param name="required"> /// The list of required scorers. </param> /// <param name="prohibited"> /// The list of prohibited scorers. </param> /// <param name="optional"> /// The list of optional scorers. </param> /// <param name="maxCoord"> /// The max coord. </param> public BooleanScorer2(BooleanWeight weight, bool disableCoord, int minNrShouldMatch, IList <Scorer> required, IList <Scorer> prohibited, IList <Scorer> optional, int maxCoord) : base(weight) { if (minNrShouldMatch < 0) { throw new System.ArgumentException("Minimum number of optional scorers should not be negative"); } this.minNrShouldMatch = minNrShouldMatch; optionalScorers = optional; requiredScorers = required; prohibitedScorers = prohibited; coordinator = new Coordinator(this, maxCoord, disableCoord); countingSumScorer = MakeCountingSumScorer(disableCoord); }
/// <summary> /// Creates a <see cref="Scorer"/> with the given similarity and lists of required, /// prohibited and optional scorers. In no required scorers are added, at least /// one of the optional scorers will have to match during the search. /// </summary> /// <param name="weight"> /// The <see cref="BooleanWeight"/> to be used. </param> /// <param name="disableCoord"> /// If this parameter is <c>true</c>, coordination level matching /// (<see cref="Similarities.Similarity.Coord(int, int)"/>) is not used. </param> /// <param name="minNrShouldMatch"> /// The minimum number of optional added scorers that should match /// during the search. In case no required scorers are added, at least /// one of the optional scorers will have to match during the search. </param> /// <param name="required"> /// The list of required scorers. </param> /// <param name="prohibited"> /// The list of prohibited scorers. </param> /// <param name="optional"> /// The list of optional scorers. </param> /// <param name="maxCoord"> /// The max coord. </param> public BooleanScorer2(BooleanWeight weight, bool disableCoord, int minNrShouldMatch, IList <Scorer> required, IList <Scorer> prohibited, IList <Scorer> optional, int maxCoord) : base(weight) { if (minNrShouldMatch < 0) { throw new ArgumentOutOfRangeException(nameof(minNrShouldMatch), "Minimum number of optional scorers should not be negative"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention) } this.minNrShouldMatch = minNrShouldMatch; optionalScorers = optional; requiredScorers = required; prohibitedScorers = prohibited; coordinator = new Coordinator(this, maxCoord, disableCoord); countingSumScorer = MakeCountingSumScorer(/* disableCoord // LUCENENET: Not referenced */); }
private Scorer Scorer(string[] values, int minShouldMatch, bool slow) { BooleanQuery bq = new BooleanQuery(); foreach (string value in values) { bq.Add(new TermQuery(new Term("field", value)), Occur.SHOULD); } bq.MinimumNumberShouldMatch = minShouldMatch; BooleanWeight weight = (BooleanWeight)Searcher.CreateNormalizedWeight(bq); if (slow) { return new SlowMinShouldMatchScorer(weight, atomicReader, Searcher); } else { return weight.GetScorer((AtomicReaderContext)atomicReader.Context, null); } }
public BooleanScorer(BooleanWeight weight, bool disableCoord, int minNrShouldMatch, IList <BulkScorer> optionalScorers, IList <BulkScorer> prohibitedScorers, int maxCoord) { this.MinNrShouldMatch = minNrShouldMatch; this.Weight = weight; foreach (BulkScorer scorer in optionalScorers) { Scorers = new SubScorer(scorer, false, false, bucketTable.NewCollector(0), Scorers); } foreach (BulkScorer scorer in prohibitedScorers) { Scorers = new SubScorer(scorer, false, true, bucketTable.NewCollector(PROHIBITED_MASK), Scorers); } CoordFactors = new float[optionalScorers.Count + 1]; for (int i = 0; i < CoordFactors.Length; i++) { CoordFactors[i] = disableCoord ? 1.0f : weight.Coord(i, maxCoord); } }
//private readonly Weight weight; // LUCENENET: Never read internal BooleanScorer(BooleanWeight weight, bool disableCoord, int minNrShouldMatch, IList <BulkScorer> optionalScorers, IList <BulkScorer> prohibitedScorers, int maxCoord) { this.minNrShouldMatch = minNrShouldMatch; //this.weight = weight; // LUCENENET: Never read foreach (BulkScorer scorer in optionalScorers) { scorers = new SubScorer(scorer, false, false, bucketTable.NewCollector(0), scorers); } foreach (BulkScorer scorer in prohibitedScorers) { scorers = new SubScorer(scorer, false, true, bucketTable.NewCollector(PROHIBITED_MASK), scorers); } coordFactors = new float[optionalScorers.Count + 1]; for (int i = 0; i < coordFactors.Length; i++) { coordFactors[i] = disableCoord ? 1.0f : weight.Coord(i, maxCoord); } }
public virtual void TestEmptyBucketWithMoreDocs() { // this test checks the logic of nextDoc() when all sub scorers have docs // beyond the first bucket (for example). Currently, the code relies on the // 'more' variable to work properly, and this test ensures that if the logic // changes, we have a test to back it up. Directory directory = NewDirectory(); RandomIndexWriter writer = new RandomIndexWriter( #if FEATURE_INSTANCE_TESTDATA_INITIALIZATION this, #endif Random, directory); writer.Commit(); IndexReader ir = writer.GetReader(); writer.Dispose(); IndexSearcher searcher = NewSearcher(ir); BooleanWeight weight = (BooleanWeight)(new BooleanQuery()).CreateWeight(searcher); BulkScorer[] scorers = new BulkScorer[] { new BulkScorerAnonymousClass() }; BooleanScorer bs = new BooleanScorer(weight, false, 1, scorers, Collections.EmptyList <BulkScorer>(), scorers.Length); IList <int> hits = new JCG.List <int>(); bs.Score(new CollectorAnonymousClass(this, hits)); Assert.AreEqual(1, hits.Count, "should have only 1 hit"); Assert.AreEqual(3000, (int)hits[0], "hit should have been docID=3000"); ir.Dispose(); directory.Dispose(); }
internal SlowMinShouldMatchScorer(BooleanWeight weight, AtomicReader reader, IndexSearcher searcher) : base(weight) { this.Dv = reader.GetSortedSetDocValues("dv"); this.MaxDoc = reader.MaxDoc(); BooleanQuery bq = (BooleanQuery)weight.Query; this.MinNrShouldMatch = bq.MinimumNumberShouldMatch; this.Sims = new SimScorer[(int)Dv.ValueCount]; foreach (BooleanClause clause in bq.Clauses) { Debug.Assert(!clause.Prohibited); Debug.Assert(!clause.Required); Term term = ((TermQuery)clause.Query).Term; long ord = Dv.LookupTerm(term.Bytes()); if (ord >= 0) { bool success = Ords.Add(ord); Debug.Assert(success); // no dups TermContext context = TermContext.Build(reader.Context, term); SimWeight w = weight.Similarity.ComputeWeight(1f, searcher.CollectionStatistics("field"), searcher.TermStatistics(term, context)); var dummy = w.ValueForNormalization; // ignored w.Normalize(1F, 1F); Sims[(int)ord] = weight.Similarity.DoSimScorer(w, (AtomicReaderContext)reader.Context); } } }
public BooleanScorer(BooleanWeight weight, bool disableCoord, int minNrShouldMatch, IList<BulkScorer> optionalScorers, IList<BulkScorer> prohibitedScorers, int maxCoord) { this.MinNrShouldMatch = minNrShouldMatch; this.Weight = weight; foreach (BulkScorer scorer in optionalScorers) { Scorers = new SubScorer(scorer, false, false, bucketTable.NewCollector(0), Scorers); } foreach (BulkScorer scorer in prohibitedScorers) { Scorers = new SubScorer(scorer, false, true, bucketTable.NewCollector(PROHIBITED_MASK), Scorers); } CoordFactors = new float[optionalScorers.Count + 1]; for (int i = 0; i < CoordFactors.Length; i++) { CoordFactors[i] = disableCoord ? 1.0f : weight.Coord(i, maxCoord); } }
/// <summary> /// Creates a <seealso cref="Scorer"/> with the given similarity and lists of required, /// prohibited and optional scorers. In no required scorers are added, at least /// one of the optional scorers will have to match during the search. /// </summary> /// <param name="weight"> /// The BooleanWeight to be used. </param> /// <param name="disableCoord"> /// If this parameter is true, coordination level matching /// (<seealso cref="Similarity#coord(int, int)"/>) is not used. </param> /// <param name="minNrShouldMatch"> /// The minimum number of optional added scorers that should match /// during the search. In case no required scorers are added, at least /// one of the optional scorers will have to match during the search. </param> /// <param name="required"> /// the list of required scorers. </param> /// <param name="prohibited"> /// the list of prohibited scorers. </param> /// <param name="optional"> /// the list of optional scorers. </param> public BooleanScorer2(BooleanWeight weight, bool disableCoord, int minNrShouldMatch, IList<Scorer> required, IList<Scorer> prohibited, IList<Scorer> optional, int maxCoord) : base(weight) { if (minNrShouldMatch < 0) { throw new System.ArgumentException("Minimum number of optional scorers should not be negative"); } this.MinNrShouldMatch = minNrShouldMatch; OptionalScorers = optional; RequiredScorers = required; ProhibitedScorers = prohibited; coordinator = new Coordinator(this, maxCoord, disableCoord); CountingSumScorer = MakeCountingSumScorer(disableCoord); }