public ConstantBulkScorer(ConstantScoreQuery outerInstance, BulkScorer bulkScorer, Weight weight, float theScore) { this.outerInstance = outerInstance; this.bulkScorer = bulkScorer; this.weight = weight; this.theScore = theScore; }
public override BulkScorer BulkScorer(AtomicReaderContext context, bool scoreDocsInOrder, Bits acceptDocs) { // if the caller asks for in-order scoring or if the weight does not support // out-of order scoring then collection will have to happen in-order. BulkScorer inScorer = @in.BulkScorer(context, scoreDocsInOrder, acceptDocs); if (inScorer == null) { return(null); } if (AssertingBulkScorer.ShouldWrap(inScorer)) { // The incoming scorer already has a specialized // implementation for BulkScorer, so we should use it: inScorer = AssertingBulkScorer.Wrap(new Random(Random.Next()), inScorer); } else if (Random.NextBoolean()) { // Let super wrap this.scorer instead, so we use // AssertingScorer: inScorer = base.BulkScorer(context, scoreDocsInOrder, acceptDocs); } if (scoreDocsInOrder == false && Random.NextBoolean()) { // The caller claims it can handle out-of-order // docs; let's confirm that by pulling docs and // randomly shuffling them before collection: inScorer = new AssertingBulkOutOfOrderScorer(new Random(Random.Next()), inScorer); } return(inScorer); }
/// <summary> /// Lower-level search API. /// /// <p> /// <seealso cref="Collector#collect(int)"/> is called for every document. <br> /// /// <p> /// NOTE: this method executes the searches on all given leaves exclusively. /// To search across all the searchers leaves use <seealso cref="#leafContexts"/>. /// </summary> /// <param name="leaves"> /// the searchers leaves to execute the searches on </param> /// <param name="weight"> /// to match documents </param> /// <param name="collector"> /// to receive hits </param> /// <exception cref="BooleanQuery.TooManyClauses"> If a query would exceed /// <seealso cref="BooleanQuery#getMaxClauseCount()"/> clauses. </exception> protected internal virtual void Search(IList <AtomicReaderContext> leaves, Weight weight, Collector collector) { // TODO: should we make this // threaded...? the Collector could be sync'd? // always use single thread: foreach (AtomicReaderContext ctx in leaves) // search each subreader { try { collector.NextReader = ctx; } catch (CollectionTerminatedException) { // there is no doc of interest in this reader context // continue with the following leaf continue; } BulkScorer scorer = weight.BulkScorer(ctx, !collector.AcceptsDocsOutOfOrder(), ctx.AtomicReader.LiveDocs); if (scorer != null) { try { scorer.Score(collector); } catch (CollectionTerminatedException) { // collection was terminated prematurely // continue with the following leaf } } } }
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(); }
public CollectorAnonymousClass(TestBooleanOr outerInstance, BulkScorer scorer, FixedBitSet hits, AtomicInt32 end) { this.outerInstance = outerInstance; this.scorer = scorer; this.hits = hits; this.end = end; }
public CollectorAnonymousInnerClassHelper(TestBooleanOr outerInstance, BulkScorer scorer, FixedBitSet hits, AtomicInteger end) { this.OuterInstance = outerInstance; this.scorer = scorer; this.Hits = hits; this.End = end; }
public virtual void Test() { Term allTerm = new Term(FIELD, "all"); TermQuery termQuery = new TermQuery(allTerm); Weight weight = IndexSearcher.CreateNormalizedWeight(termQuery); Assert.IsTrue(IndexSearcher.TopReaderContext is AtomicReaderContext); AtomicReaderContext context = (AtomicReaderContext)IndexSearcher.TopReaderContext; BulkScorer ts = weight.GetBulkScorer(context, true, (context.AtomicReader).LiveDocs); // we have 2 documents with the term all in them, one document for all the // other values IList <TestHit> docs = new List <TestHit>(); // must call next first ts.Score(new CollectorAnonymousInnerClassHelper(this, context, docs)); Assert.IsTrue(docs.Count == 2, "docs Size: " + docs.Count + " is not: " + 2); TestHit doc0 = docs[0]; TestHit doc5 = docs[1]; // The scores should be the same Assert.IsTrue(doc0.Score == doc5.Score, doc0.Score + " does not equal: " + doc5.Score); /* * Score should be (based on Default Sim.: All floats are approximate tf = 1 * numDocs = 6 docFreq(all) = 2 idf = ln(6/3) + 1 = 1.693147 idf ^ 2 = * 2.8667 boost = 1 lengthNorm = 1 //there is 1 term in every document coord * = 1 sumOfSquaredWeights = (idf * boost) ^ 2 = 1.693147 ^ 2 = 2.8667 * queryNorm = 1 / (sumOfSquaredWeights)^0.5 = 1 /(1.693147) = 0.590 * * score = 1 * 2.8667 * 1 * 1 * 0.590 = 1.69 */ Assert.IsTrue(doc0.Score == 1.6931472f, doc0.Score + " does not equal: " + 1.6931472f); }
public override BulkScorer GetBulkScorer(AtomicReaderContext context, bool scoreDocsInOrder, IBits acceptDocs) { //DocIdSetIterator disi; if (outerInstance.m_filter != null) { if (Debugging.AssertsEnabled) { Debugging.Assert(outerInstance.m_query == null); } return(base.GetBulkScorer(context, scoreDocsInOrder, acceptDocs)); } else { if (Debugging.AssertsEnabled) { Debugging.Assert(outerInstance.m_query != null && innerWeight != null); } BulkScorer bulkScorer = innerWeight.GetBulkScorer(context, scoreDocsInOrder, acceptDocs); if (bulkScorer == null) { return(null); } return(new ConstantBulkScorer(outerInstance, bulkScorer, this, queryWeight)); } }
public static BulkScorer Wrap(Random random, BulkScorer other) { if (other == null || other is AssertingBulkScorer) { return other; } return new AssertingBulkScorer(random, other); }
public static BulkScorer Wrap(Random random, BulkScorer other) { if (other == null || other is AssertingBulkScorer) { return(other); } return(new AssertingBulkScorer(random, other)); }
public SubScorer(BulkScorer scorer, bool required, bool prohibited, Collector collector, SubScorer next) { if (required) { throw new System.ArgumentException("this scorer cannot handle required=true"); } this.Scorer = scorer; this.More = true; // TODO: re-enable this if BQ ever sends us required clauses //this.required = required; this.Prohibited = prohibited; this.Collector = collector; this.Next = next; }
public override BulkScorer GetBulkScorer(AtomicReaderContext context, bool scoreDocsInOrder, IBits acceptDocs) { if (scoreDocsInOrder || outerInstance.m_minNrShouldMatch > 1) { // TODO: (LUCENE-4872) in some cases BooleanScorer may be faster for minNrShouldMatch // but the same is even true of pure conjunctions... return(base.GetBulkScorer(context, scoreDocsInOrder, acceptDocs)); } IList <BulkScorer> prohibited = new List <BulkScorer>(); IList <BulkScorer> optional = new List <BulkScorer>(); using (IEnumerator <BooleanClause> cIter = outerInstance.clauses.GetEnumerator()) { foreach (Weight w in m_weights) { cIter.MoveNext(); BooleanClause c = cIter.Current; BulkScorer subScorer = w.GetBulkScorer(context, false, acceptDocs); if (subScorer == null) { if (c.IsRequired) { return(null); } } else if (c.IsRequired) { // TODO: there are some cases where BooleanScorer // would handle conjunctions faster than // BooleanScorer2... return(base.GetBulkScorer(context, scoreDocsInOrder, acceptDocs)); } else if (c.IsProhibited) { prohibited.Add(subScorer); } else { optional.Add(subScorer); } } } // Check if we can and should return a BooleanScorer return(new BooleanScorer(this, disableCoord, outerInstance.m_minNrShouldMatch, optional, prohibited, m_maxCoord)); }
public virtual void TestBooleanScorerMax() { Directory dir = NewDirectory(); RandomIndexWriter riw = new RandomIndexWriter(Random(), dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))); int docCount = AtLeast(10000); for (int i = 0; i < docCount; i++) { Document doc = new Document(); doc.Add(NewField("field", "a", TextField.TYPE_NOT_STORED)); riw.AddDocument(doc); } riw.ForceMerge(1); IndexReader r = riw.Reader; riw.Dispose(); IndexSearcher s = NewSearcher(r); BooleanQuery bq = new BooleanQuery(); bq.Add(new TermQuery(new Term("field", "a")), BooleanClause.Occur.SHOULD); bq.Add(new TermQuery(new Term("field", "a")), BooleanClause.Occur.SHOULD); Weight w = s.CreateNormalizedWeight(bq); Assert.AreEqual(1, s.IndexReader.Leaves.Count); BulkScorer scorer = w.BulkScorer(s.IndexReader.Leaves[0], false, null); FixedBitSet hits = new FixedBitSet(docCount); AtomicInteger end = new AtomicInteger(); Collector c = new CollectorAnonymousInnerClassHelper(this, scorer, hits, end); while (end.Get() < docCount) { int inc = TestUtil.NextInt(Random(), 1, 1000); end.AddAndGet(inc); scorer.Score(c, end.Get()); } Assert.AreEqual(docCount, hits.Cardinality()); r.Dispose(); dir.Dispose(); }
public override BulkScorer BulkScorer(AtomicReaderContext context, bool scoreDocsInOrder, Bits acceptDocs) { //DocIdSetIterator disi; if (OuterInstance.filter != null) { Debug.Assert(OuterInstance.query == null); return(base.BulkScorer(context, scoreDocsInOrder, acceptDocs)); } else { Debug.Assert(OuterInstance.query != null && InnerWeight != null); BulkScorer bulkScorer = InnerWeight.BulkScorer(context, scoreDocsInOrder, acceptDocs); if (bulkScorer == null) { return(null); } return(new ConstantBulkScorer(OuterInstance, bulkScorer, this, QueryWeight)); } }
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(); }
public ConstantBulkScorer(ConstantScoreQuery outerInstance, BulkScorer bulkScorer, Weight weight, float theScore) { this.OuterInstance = outerInstance; this.BulkScorer = bulkScorer; this.Weight = weight; this.TheScore = theScore; }
public AssertingBulkOutOfOrderScorer(Random random, BulkScorer @in) { this.@in = @in; this.Random = random; }
private AssertingBulkScorer(Random random, BulkScorer @in) { this.Random = random; this.@in = @in; }
public static bool ShouldWrap(BulkScorer inScorer) { return(SCORE_COLLECTOR.IsOverriddenAsOf(inScorer.GetType()) || SCORE_COLLECTOR_RANGE.IsOverriddenAsOf(inScorer.GetType())); }
public static bool ShouldWrap(BulkScorer inScorer) { return SCORE_COLLECTOR.IsOverriddenAsOf(inScorer.GetType()) || SCORE_COLLECTOR_RANGE.IsOverriddenAsOf(inScorer.GetType()); }
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); 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(); }