public virtual void TestNext() { 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; Scorer ts = weight.Scorer(context, (context.AtomicReader).LiveDocs); Assert.IsTrue(ts.NextDoc() != DocIdSetIterator.NO_MORE_DOCS, "next did not return a doc"); Assert.IsTrue(ts.Score() == 1.6931472f, "score is not correct"); Assert.IsTrue(ts.NextDoc() != DocIdSetIterator.NO_MORE_DOCS, "next did not return a doc"); Assert.IsTrue(ts.Score() == 1.6931472f, "score is not correct"); Assert.IsTrue(ts.NextDoc() == DocIdSetIterator.NO_MORE_DOCS, "next returned a doc and it should not have"); }
public override void Collect(int doc) { //System.out.println("Q1: Doc=" + doc + " score=" + score); float score = scorer.Score(); Assert.IsTrue(score == 1.0f); base.Collect(doc); }
public override void Collect(int doc, IState state) { //System.out.println("Q2: Doc=" + doc + " score=" + score); float score = scorer.Score(null); Assert.IsTrue(score == 1.0f + doc); base.Collect(doc, null); }
/// <summary> Just like {@link #Search(Weight, Filter, int, Sort)}, but you choose /// whether or not the fields in the returned {@link FieldDoc} instances /// should be set by specifying fillFields.<br/> /// /// <p/> /// NOTE: this does not compute scores by default. If you need scores, create /// a {@link TopFieldCollector} instance by calling /// {@link TopFieldCollector#create} and then pass that to /// {@link #Search(Weight, Filter, Collector)}. /// <p/> /// </summary> public virtual TopFieldDocs Search(Weight weight, Filter filter, int nDocs, Sort sort, bool fillFields) { nDocs = Math.Min(nDocs, reader.MaxDoc()); SortField[] fields = sort.fields; bool legacy = false; for (int i = 0; i < fields.Length; i++) { SortField field = fields[i]; System.String fieldname = field.GetField(); int type = field.GetType(); // Resolve AUTO into its true type if (type == SortField.AUTO) { int autotype = SortField.DetectFieldType(reader, fieldname); if (autotype == SortField.STRING) { fields[i] = new SortField(fieldname, field.GetLocale(), field.GetReverse()); } else { fields[i] = new SortField(fieldname, autotype, field.GetReverse()); } } if (field.GetUseLegacySearch()) { legacy = true; } } if (legacy) { // Search the single top-level reader TopDocCollector collector = new TopFieldDocCollector(reader, sort, nDocs); HitCollectorWrapper hcw = new HitCollectorWrapper(collector); hcw.SetNextReader(reader, 0); if (filter == null) { Scorer scorer = weight.Scorer(reader, true, true); if (scorer != null) { scorer.Score(hcw); } } else { SearchWithFilter(reader, weight, filter, hcw); } return((TopFieldDocs)collector.TopDocs()); } TopFieldCollector collector2 = TopFieldCollector.Create(sort, nDocs, fillFields, fieldSortDoTrackScores, fieldSortDoMaxScore, !weight.ScoresDocsOutOfOrder()); Search(weight, filter, collector2); return((TopFieldDocs)collector2.TopDocs()); }
public override float Score() { if (Doc() > lastScoredDoc) { lastScoredDoc = Doc(); Enclosing_Instance.coordinator.nrMatchers++; } return(scorer.Score()); }
public override void Collect(int doc) { float score = scorer.Score(); doc = doc + base_Renamed; docs.Add(new TestHit(enclosingInstance, doc, score)); Assert.IsTrue(score > 0, "score " + score + " is not greater than 0"); Assert.IsTrue(doc == 0 || doc == 5, "Doc: " + doc + " does not equal 0 or doc does not equal 5"); }
public override float Score() { Debug.Assert(Iterating()); float score = @in.Score(); Debug.Assert(!float.IsNaN(score)); Debug.Assert(!float.IsNaN(score)); return(score); }
// inherit javadoc public override void Search(Weight weight, Filter filter, HitCollector results) { Scorer scorer = weight.Scorer(reader); if (scorer == null) { return; } if (filter == null) { scorer.Score(results); return; } DocIdSetIterator filterDocIdIterator = filter.GetDocIdSet(reader).Iterator(); // CHECKME: use ConjunctionScorer here? bool more = filterDocIdIterator.Next() && scorer.SkipTo(filterDocIdIterator.Doc()); while (more) { int filterDocId = filterDocIdIterator.Doc(); if (filterDocId > scorer.Doc() && !scorer.SkipTo(filterDocId)) { more = false; } else { int scorerDocId = scorer.Doc(); if (scorerDocId == filterDocId) // permitted by filter { results.Collect(scorerDocId, scorer.Score()); more = filterDocIdIterator.Next(); } else { more = filterDocIdIterator.SkipTo(scorerDocId); } } } }
public override float Score() { int doc = Scorer.DocID(); if (doc != CurDoc) { CurScore = Scorer.Score(); CurDoc = doc; } return(CurScore); }
public override void Collect(int doc) { float score = sc.Score(); LastDoc[0] = doc; try { if (scorer == null) { Weight w = s.CreateNormalizedWeight(q); AtomicReaderContext context = ReaderContextArray[leafPtr]; scorer = w.Scorer(context, (context.AtomicReader).LiveDocs); } int op = Order[(Opidx[0]++) % Order.Length]; // System.out.println(op==skip_op ? // "skip("+(sdoc[0]+1)+")":"next()"); bool more = op == Skip_op?scorer.Advance(scorer.DocID() + 1) != DocIdSetIterator.NO_MORE_DOCS : scorer.NextDoc() != DocIdSetIterator.NO_MORE_DOCS; int scorerDoc = scorer.DocID(); float scorerScore = scorer.Score(); float scorerScore2 = scorer.Score(); float scoreDiff = Math.Abs(score - scorerScore); float scorerDiff = Math.Abs(scorerScore2 - scorerScore); if (!more || doc != scorerDoc || scoreDiff > MaxDiff || scorerDiff > MaxDiff) { StringBuilder sbord = new StringBuilder(); for (int i = 0; i < Order.Length; i++) { sbord.Append(Order[i] == Skip_op ? " skip()" : " next()"); } throw new Exception("ERROR matching docs:" + "\n\t" + (doc != scorerDoc ? "--> " : "") + "doc=" + doc + ", scorerDoc=" + scorerDoc + "\n\t" + (!more ? "--> " : "") + "tscorer.more=" + more + "\n\t" + (scoreDiff > MaxDiff ? "--> " : "") + "scorerScore=" + scorerScore + " scoreDiff=" + scoreDiff + " maxDiff=" + MaxDiff + "\n\t" + (scorerDiff > MaxDiff ? "--> " : "") + "scorerScore2=" + scorerScore2 + " scorerDiff=" + scorerDiff + "\n\thitCollector.Doc=" + doc + " score=" + score + "\n\t Scorer=" + scorer + "\n\t Query=" + q + " " + q.GetType().Name + "\n\t Searcher=" + s + "\n\t Order=" + sbord + "\n\t Op=" + (op == Skip_op ? " skip()" : " next()")); } } catch (IOException e) { throw new Exception(e.Message, e); } }
public override void Collect(int doc) { BucketTable table = BucketTable; int i = doc & BucketTable.MASK; Bucket bucket = table.Buckets[i]; if (bucket.Doc != doc) // invalid bucket { bucket.Doc = doc; // set doc bucket.Score = Scorer_Renamed.Score(); // initialize score bucket.Bits = Mask; // initialize mask bucket.Coord = 1; // initialize coord bucket.Next = table.First; // push onto valid list table.First = bucket; } // valid bucket else { bucket.Score += Scorer_Renamed.Score(); // increment score bucket.Bits |= Mask; // add bits in mask bucket.Coord++; // increment coord } }
public override void Collect(int doc) { ++totalHits; if (queueFull) { if ((reverseMul * comparator.CompareBottom(doc)) <= 0) { // since docs are visited in doc Id order, if compare is 0, it means // this document is largest than anything else in the queue, and // therefore not competitive. return; } // Compute the score only if the hit is competitive. float score = scorer.Score(); // This hit is competitive - replace bottom element in queue & adjustTop comparator.Copy(bottom.slot, doc); updateBottom(doc, score); comparator.SetBottom(bottom.slot); } else { // Compute the score only if the hit is competitive. float score = scorer.Score(); // Startup transient: queue hasn't gathered numHits yet int slot = totalHits - 1; // Copy hit into queue comparator.Copy(slot, doc); Add(slot, doc, score); if (queueFull) { comparator.SetBottom(bottom.slot); } } }
public override float Score() { int doc = DocID(); if (doc >= lastScoredDoc) { if (doc > lastScoredDoc) { lastDocScore = scorer.Score(); lastScoredDoc = doc; } Enclosing_Instance.coordinator.nrMatchers++; } return(lastDocScore); }
public override float Score() { int doc = DocID(); if (doc >= LastScoredDoc) { if (doc > LastScoredDoc) { LastDocScore = Scorer.Score(); LastScoredDoc = doc; } OuterInstance.coordinator.NrMatchers++; } return(LastDocScore); }
public override void Collect(int doc, IState state) { //System.out.println("doc="+doc); float score = this.scorer.Score(null); try { for (int i = lastDoc[0] + 1; i <= doc; i++) { Weight w = q.Weight(s, null); Scorer scorer = w.Scorer(reader, true, false, null); Assert.IsTrue(scorer.Advance(i, null) != DocIdSetIterator.NO_MORE_DOCS, "query collected " + doc + " but skipTo(" + i + ") says no more docs!"); Assert.AreEqual(doc, scorer.DocID(), "query collected " + doc + " but skipTo(" + i + ") got to " + scorer.DocID()); float skipToScore = scorer.Score(null); Assert.AreEqual(skipToScore, scorer.Score(null), maxDiff, "unstable skipTo(" + i + ") score!"); Assert.AreEqual(score, skipToScore, maxDiff, "query assigned doc " + doc + " a score of <" + score + "> but skipTo(" + i + ") has <" + skipToScore + ">!"); } lastDoc[0] = doc; } catch (System.IO.IOException e) { throw new System.SystemException("", e); } }
public override void Collect(int doc, IState state) { float score = sc.Score(null); lastDoc[0] = doc; try { if (scorer == null) { Weight w = q.Weight(s, null); scorer = w.Scorer(reader, true, false, null); } int op = order[(opidx[0]++) % order.Length]; // System.out.println(op==skip_op ? // "skip("+(sdoc[0]+1)+")":"next()"); bool more = op == skip_op ? scorer.Advance(scorer.DocID() + 1, null) != DocIdSetIterator.NO_MORE_DOCS : scorer.NextDoc(null) != DocIdSetIterator.NO_MORE_DOCS; int scorerDoc = scorer.DocID(); float scorerScore = scorer.Score(null); float scorerScore2 = scorer.Score(null); float scoreDiff = System.Math.Abs(score - scorerScore); float scorerDiff = System.Math.Abs(scorerScore2 - scorerScore); if (!more || doc != scorerDoc || scoreDiff > maxDiff || scorerDiff > maxDiff) { System.Text.StringBuilder sbord = new System.Text.StringBuilder(); for (int i = 0; i < order.Length; i++) { sbord.Append(order[i] == skip_op?" skip()":" next()"); } throw new System.SystemException("ERROR matching docs:" + "\n\t" + (doc != scorerDoc ? "--> " : "") + "scorerDoc=" + scorerDoc + "\n\t" + (!more ? "--> " : "") + "tscorer.more=" + more + "\n\t" + (scoreDiff > maxDiff ? "--> " : "") + "scorerScore=" + scorerScore + " scoreDiff=" + scoreDiff + " maxDiff=" + maxDiff + "\n\t" + (scorerDiff > maxDiff ? "--> " : "") + "scorerScore2=" + scorerScore2 + " scorerDiff=" + scorerDiff + "\n\thitCollector.doc=" + doc + " score=" + score + "\n\t Scorer=" + scorer + "\n\t Query=" + q + " " + q.GetType().FullName + "\n\t Searcher=" + s + "\n\t Order=" + sbord + "\n\t Op=" + (op == skip_op ? " skip()" : " next()")); } } catch (System.IO.IOException e) { throw new System.SystemException("", e); } }
public override void Collect(int doc) { DocIDs[Buffered] = doc; Scores[Buffered] = Scorer_Renamed.Score(); try { Freqs[Buffered] = Scorer_Renamed.Freq(); } catch (System.NotSupportedException) { Freqs[Buffered] = -1; } if (++Buffered == BufferSize) { Flush(); } }
public override void Collect(int doc) { Explanation exp = null; doc = doc + base_Renamed; try { exp = s.Explain(q, doc); } catch (System.IO.IOException e) { throw new System.SystemException("exception in hitcollector of [[" + d + "]] for #" + doc, e); } Assert.IsNotNull(exp, "Explanation of [[" + d + "]] for #" + doc + " is null"); Lucene.Net.Search.CheckHits.VerifyExplanation(d, doc, scorer.Score(), deep, exp); }
// inherit javadoc public override void Search(Weight weight, Filter filter, HitCollector results) { HitCollector collector = results; if (filter != null) { System.Collections.BitArray bits = filter.Bits(reader); collector = new AnonymousClassHitCollector(bits, results, this); } Scorer scorer = weight.Scorer(reader); if (scorer == null) { return; } scorer.Score(collector); }
public override void Collect(int doc) { Explanation exp = null; doc = doc + @base; try { exp = s.Explain(q, doc); } catch (IOException e) { throw new Exception("exception in hitcollector of [[" + d + "]] for #" + doc, e); } Assert.IsNotNull(exp, "Explanation of [[" + d + "]] for #" + doc + " is null"); VerifyExplanation(d, doc, Scorer_Renamed.Score(), Deep, exp); Assert.IsTrue(exp.IsMatch, "Explanation of [[" + d + "]] for #" + doc + " does not indicate match: " + exp.ToString()); }
private void AssertNext(Scorer expected, Scorer actual) { if (actual == null) { Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, expected.NextDoc()); return; } int doc; while ((doc = expected.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { Assert.AreEqual(doc, actual.NextDoc()); Assert.AreEqual(expected.Freq(), actual.Freq()); float expectedScore = expected.Score(); float actualScore = actual.Score(); Assert.AreEqual(expectedScore, actualScore, CheckHits.ExplainToleranceDelta(expectedScore, actualScore)); } Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, actual.NextDoc()); }
/// <summary>Returns the score of the current document matching the query. /// Initially invalid, until <see cref="NextDoc()" /> is called the first time. /// </summary> /// <returns> The score of the required scorer, eventually increased by the score /// of the optional scorer when it also matches the current document. /// </returns> public override float Score(IState state) { int curDoc = reqScorer.DocID(); float reqScore = reqScorer.Score(state); if (optScorer == null) { return(reqScore); } int optScorerDoc = optScorer.DocID(); if (optScorerDoc < curDoc && (optScorerDoc = optScorer.Advance(curDoc, state)) == NO_MORE_DOCS) { optScorer = null; return(reqScore); } return(optScorerDoc == curDoc?reqScore + optScorer.Score(state):reqScore); }
/// <summary> /// Returns the score of the current document matching the query. /// Initially invalid, until <seealso cref="#nextDoc()"/> is called the first time. </summary> /// <returns> The score of the required scorer, eventually increased by the score /// of the optional scorer when it also matches the current document. </returns> public override float Score() { // TODO: sum into a double and cast to float if we ever send required clauses to BS1 int curDoc = ReqScorer.DocID(); float reqScore = ReqScorer.Score(); if (OptScorer == null) { return(reqScore); } int optScorerDoc = OptScorer.DocID(); if (optScorerDoc < curDoc && (optScorerDoc = OptScorer.Advance(curDoc)) == NO_MORE_DOCS) { OptScorer = null; return(reqScore); } return(optScorerDoc == curDoc ? reqScore + OptScorer.Score() : reqScore); }
public override bool Next() { bool more; do { while (bucketTable.first != null) { // more queued current = bucketTable.first; bucketTable.first = current.next; // pop the queue // check prohibited & required if ((current.bits & prohibitedMask) == 0 && (current.bits & requiredMask) == requiredMask) { return(true); } } // refill the queue more = false; end += BucketTable.SIZE; for (SubScorer sub = scorers; sub != null; sub = sub.next) { Scorer scorer = sub.scorer; while (!sub.done && scorer.Doc() < end) { sub.collector.Collect(scorer.Doc(), scorer.Score()); sub.done = !scorer.Next(); } if (!sub.done) { more = true; } } }while (bucketTable.first != null || more); return(false); }
public override void Collect(int doc) { scores[doc + base_Renamed] = scorer.Score(); }
public override void Collect(int doc) { ++totalHits; if (queueFull) { // Fastmatch: return if this hit is not competitive for (int i = 0; ; i++) { int c = reverseMul[i] * comparators[i].CompareBottom(doc); if (c < 0) { // Definitely not competitive. return; } else if (c > 0) { // Definitely competitive. break; } else if (i == comparators.Length - 1) { // Here c=0. If we're at the last comparator, this doc is not // competitive, since docs are visited in doc Id order, which means // this doc cannot compete with any other document in the queue. return; } } // This hit is competitive - replace bottom element in queue & adjustTop for (int i = 0; i < comparators.Length; i++) { comparators[i].Copy(bottom.slot, doc); } // Compute score only if it is competitive. float score = scorer.Score(); UpdateBottom(doc, score); for (int i = 0; i < comparators.Length; i++) { comparators[i].SetBottom(bottom.slot); } } else { // Startup transient: queue hasn't gathered numHits yet int slot = totalHits - 1; // Copy hit into queue for (int i = 0; i < comparators.Length; i++) { comparators[i].Copy(slot, doc); } // Compute score only if it is competitive. float score = scorer.Score(); Add(slot, doc, score); if (queueFull) { for (int i = 0; i < comparators.Length; i++) { comparators[i].SetBottom(bottom.slot); } } } }
public override void Collect(int doc, IState state) { //System.out.println("Doc=" + doc + " score=" + score); Assert.AreEqual(2.0f, scorer.Score(null)); }
public override int CompareBottom(int doc, IState state) { float score = scorer.Score(state); return(bottom > score?-1:(bottom < score?1:0)); }
/// <summary>Returns the score of the current document matching the query. /// Initially invalid, until {@link #Next()} is called the first time. /// </summary> /// <returns> The score of the required scorer. /// </returns> public override float Score() { return(reqScorer.Score()); // reqScorer may be null when next() or skipTo() already return false }
public override void Collect(int doc, IState state) { Assert.AreEqual(1.0f, scorer.Score(null)); }