/// <summary>Construct a <code>ReqExclScorer</code>.</summary> /// <param name="reqScorer">The scorer that must match, except where /// </param> /// <param name="exclDisi">indicates exclusion. /// </param> public ReqExclScorer(Scorer reqScorer, DocIdSetIterator exclDisi) : base(null) { // No similarity used. this.reqScorer = reqScorer; this.exclDisi = exclDisi; }
private AssertingScorer(Random random, Scorer @in) : base(@in.Weight) { this.Random = random; this.@in = @in; this.DocsEnumIn = new AssertingAtomicReader.AssertingDocsEnum(@in); }
/// <summary>Construct a <code>ReqExclScorer</code>.</summary> /// <param name="reqScorer">The scorer that must match, except where /// </param> /// <param name="exclScorer">indicates exclusion. /// </param> public ReqExclScorer(Scorer reqScorer, Scorer exclScorer) : base(null) { // No similarity used. this.reqScorer = reqScorer; this.exclScorer = exclScorer; }
public virtual Scorer CreateScorer(Scorer innerScorer, IndexReader reader, bool scoreDocsInOrder, bool topScorer) { if(!(reader is BoboIndexReader)) throw new ArgumentException("IndexReader is not BoboIndexReader"); return new FacetBasedBoostingScorer(this, (BoboIndexReader)reader, innerScorer.Similarity, innerScorer); }
public override bool Next() { if (firstTime) { if (!exclScorer.Next()) { exclScorer = null; // exhausted at start } firstTime = false; } if (reqScorer == null) { return false; } if (!reqScorer.Next()) { reqScorer = null; // exhausted, nothing left return false; } if (exclScorer == null) { return true; // reqScorer.next() already returned true } return ToNonExcluded(); }
protected internal DisjunctionScorer(Weight weight, Scorer[] subScorers) : base(weight) { this.SubScorers = subScorers; this.NumScorers = subScorers.Length; Heapify(); }
/// <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, eventually increased by the score /// of the optional scorer when it also matches the current document. /// </returns> public override float Score() { int curDoc = reqScorer.Doc(); float reqScore = reqScorer.Score(); if (firstTimeOptScorer) { firstTimeOptScorer = false; if (!optScorer.SkipTo(curDoc)) { optScorer = null; return reqScore; } } else if (optScorer == null) { return reqScore; } else if ((optScorer.Doc() < curDoc) && (!optScorer.SkipTo(curDoc))) { optScorer = null; return reqScore; } // assert (optScorer != null) && (optScorer.doc() >= curDoc); return (optScorer.Doc() == curDoc)?reqScore + optScorer.Score():reqScore; }
/// <summary>Construct a <code>ReqOptScorer</code>.</summary> /// <param name="reqScorer">The required scorer. This must match. /// </param> /// <param name="optScorer">The optional scorer. This is used for scoring only. /// </param> public ReqOptSumScorer(Scorer reqScorer, Scorer optScorer) : base(null) { // No similarity used. this.reqScorer = reqScorer; this.optScorer = optScorer; }
public override void SetScorer(Scorer scorer) { foreach (DocComparator comparator in _comparators) { comparator.SetScorer(scorer); } }
public override void SetScorer(Scorer scorer) { // Set a ScoreCachingWrappingScorer in case the wrapped Collector will call // score() also. this.scorer = new ScoreCachingWrappingScorer(scorer); c.SetScorer(this.scorer); }
/// <summary> /// Construct a <code>ReqOptScorer</code>. </summary> /// <param name="reqScorer"> The required scorer. this must match. </param> /// <param name="optScorer"> The optional scorer. this is used for scoring only. </param> public ReqOptSumScorer(Scorer reqScorer, Scorer optScorer) : base(reqScorer.weight) { Debug.Assert(reqScorer != null); Debug.Assert(optScorer != null); this.ReqScorer = reqScorer; this.OptScorer = optScorer; }
public override void SetScorer(Scorer _scorer) { this.scorer = _scorer; for (int i = 0; i < hitQueue.comparators.Length; i++) { hitQueue.comparators[i].SetScorer(_scorer); } }
public SubScorer(Scorer scorer, bool required, bool prohibited, HitCollector collector, SubScorer next) { this.scorer = scorer; this.done = !scorer.Next(); this.required = required; this.prohibited = prohibited; this.collector = collector; this.next = next; }
/// <summary>Add the scorer for a subquery</summary> /// <param name="scorer">the scorer of a subquery of our associated DisjunctionMaxQuery /// </param> public virtual void Add(Scorer scorer) { if (scorer.Next()) { // Initialize and retain only if it produces docs subScorers.Add(scorer); more = true; } }
public ConjunctionScorer(Similarity similarity, Scorer[] scorers) : base(similarity) { this.scorers = scorers; coord = similarity.Coord(scorers.Length, scorers.Length); for (int i = 0; i < scorers.Length; i++) { if (scorers[i].NextDoc() == NO_MORE_DOCS) { // If even one of the sub-scorers does not have any documents, this // scorer should not attempt to do any more work. lastDoc = NO_MORE_DOCS; return ; } } // Sort the array the first time... // We don't need to sort the array in any future calls because we know // it will already start off sorted (all scorers on same doc). // note that this comparator is not consistent with equals! System.Array.Sort(scorers, new AnonymousClassComparator(this)); // NOTE: doNext() must be called before the re-sorting of the array later on. // The reason is this: assume there are 5 scorers, whose first docs are 1, // 2, 3, 5, 5 respectively. Sorting (above) leaves the array as is. Calling // doNext() here advances all the first scorers to 5 (or a larger doc ID // they all agree on). // However, if we re-sort before doNext() is called, the order will be 5, 3, // 2, 1, 5 and then doNext() will stop immediately, since the first scorer's // docs equals the last one. So the invariant that after calling doNext() // all scorers are on the same doc ID is broken. if (DoNext() == NO_MORE_DOCS) { // The scorers did not agree on any document. lastDoc = NO_MORE_DOCS; return ; } // If first-time skip distance is any predictor of // scorer sparseness, then we should always try to skip first on // those scorers. // Keep last scorer in it's last place (it will be the first // to be skipped on), but reverse all of the others so that // they will be skipped on in order of original high skip. int end = scorers.Length - 1; int max = end >> 1; for (int i = 0; i < max; i++) { Scorer tmp = scorers[i]; int idx = end - i - 1; scorers[i] = scorers[idx]; scorers[idx] = tmp; } }
public static Scorer Wrap(Random random, Scorer other) { if (other == null || other is AssertingScorer) { return other; } AssertingScorer assertScorer = new AssertingScorer(random, other); ASSERTING_INSTANCES[other] = new WeakReference(assertScorer); return assertScorer; }
/// <summary> /// <code>context</code> must contain a key "scorer" which is a /// <see cref="Lucene.Net.Search.Scorer">Lucene.Net.Search.Scorer</see> /// . /// </summary> /// <exception cref="System.IO.IOException"></exception> public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext) { Scorer v = (Scorer)context["scorer"]; hashCodeObj = v; if (v == null) { throw new InvalidOperationException("Expressions referencing the score can only be used for sorting" ); } return new ScoreFunctionValues(this, v); }
/// <summary> Creates a new instance of DisjunctionMaxScorer /// /// </summary> /// <param name="tieBreakerMultiplier">Multiplier applied to non-maximum-scoring subqueries for a /// document as they are summed into the result. /// </param> /// <param name="similarity">-- not used since our definition involves neither coord nor terms /// directly /// </param> /// <param name="subScorers">The sub scorers this Scorer should iterate on /// </param> /// <param name="numScorers">The actual number of scorers to iterate on. Note that the array's /// length may be larger than the actual number of scorers. /// </param> public DisjunctionMaxScorer(float tieBreakerMultiplier, Similarity similarity, Scorer[] subScorers, int numScorers):base(similarity) { this.tieBreakerMultiplier = tieBreakerMultiplier; // The passed subScorers array includes only scorers which have documents // (DisjunctionMaxQuery takes care of that), and their nextDoc() was already // called. this.subScorers = subScorers; this.numScorers = numScorers; Heapify(); }
internal void Add(Scorer scorer) { if (length >= scorers.Length) { // grow the array Scorer[] temps = new Scorer[scorers.Length * 2]; Array.Copy(scorers, 0, temps, 0, length); scorers = temps; } last += 1; length += 1; scorers[last] = scorer; }
public override int Advance(int target) { if (reqScorer == null) { return doc = NO_MORE_DOCS; } if (exclDisi == null) { return doc = reqScorer.Advance(target); } if (reqScorer.Advance(target) == NO_MORE_DOCS) { reqScorer = null; return doc = NO_MORE_DOCS; } return doc = ToNonExcluded(); }
/// <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() { 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 int NextDoc() { if (reqScorer == null) { return doc; } doc = reqScorer.NextDoc(); if (doc == NO_MORE_DOCS) { reqScorer = null; // exhausted, nothing left return doc; } if (exclDisi == null) { return doc; } return doc = ToNonExcluded(); }
public FacetBasedBoostingScorer(FacetBasedBoostScorerBuilder parent, BoboIndexReader reader, Similarity similarity, Scorer innerScorer) : base(similarity) { _innerScorer = innerScorer; List<BoboDocScorer> list = new List<BoboDocScorer>(); foreach (var boostEntry in parent._boostMaps) { string facetName = boostEntry.Key; IFacetHandler handler = reader.GetFacetHandler(facetName); if (!(handler is IFacetScoreable)) throw new ArgumentException(facetName + " does not implement FacetScoreable"); IFacetScoreable facetScoreable = (IFacetScoreable)handler; BoboDocScorer scorer = facetScoreable.GetDocScorer(reader, parent._scoringFunctionFactory, boostEntry.Value); if (scorer != null) list.Add(scorer); } _facetScorers = list.ToArray(); _docid = -1; }
public virtual Scorer CreateScorer(Scorer innerScorer, IndexReader reader, bool scoreDocsInOrder, bool topScorer) { if (reader is BoboIndexReader) { BoboIndexReader boboReader = (BoboIndexReader)reader; object dataObj = boboReader.GetFacetData(_timeFacetName); if (dataObj is FacetDataCache) { FacetDataCache facetDataCache = (FacetDataCache)(boboReader.GetFacetData(_timeFacetName)); BigSegmentedArray orderArray = facetDataCache.OrderArray; TermLongList termList = (TermLongList)facetDataCache.ValArray; return new RecencyBoostScorer(this, innerScorer, orderArray, termList); } else { throw new InvalidOperationException("underlying facet data must be of type FacetDataCache<long>"); } } else { throw new ArgumentException("reader not instance of " + typeof(BoboIndexReader)); } }
internal void Add(Scorer scorer, bool required, bool prohibited) { int mask = 0; if (required || prohibited) { if (nextMask == 0) throw new System.IndexOutOfRangeException("More than 32 required/prohibited clauses in query."); mask = nextMask; nextMask = nextMask << 1; } else mask = 0; if (!prohibited) maxCoord++; if (prohibited) prohibitedMask |= mask; // update prohibited mask else if (required) requiredMask |= mask; // update required mask scorers = new SubScorer(scorer, required, prohibited, bucketTable.NewCollector(mask), scorers); }
public override void SetScorer(Scorer scorer) { // scorer is not needed }
public override void SetScorer(Scorer scorer) { }
public virtual void SetScorer(Scorer scorer) { Collector.SetScorer(scorer); TqsSet.Clear(); FillLeaves(scorer, TqsSet); }
internal SingleMatchScorer(BooleanScorer2 enclosingInstance, Scorer scorer) : base(scorer.GetSimilarity()) { InitBlock(enclosingInstance); this.scorer = scorer; }
public override void SetScorer(Scorer scorer) { throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG); }
public override void SetScorer(Scorer scorer) { m_other.SetScorer(scorer); }
public void SetScorer(Scorer scorer) { this.scorer = scorer; }
public virtual void TestBS2DisjunctionNextVsAdvance() { Directory d = NewDirectory(); RandomIndexWriter w = new RandomIndexWriter(Random(), d, Similarity, TimeZone); int numDocs = AtLeast(300); for (int docUpto = 0; docUpto < numDocs; docUpto++) { string contents = "a"; if (Random().Next(20) <= 16) { contents += " b"; } if (Random().Next(20) <= 8) { contents += " c"; } if (Random().Next(20) <= 4) { contents += " d"; } if (Random().Next(20) <= 2) { contents += " e"; } if (Random().Next(20) <= 1) { contents += " f"; } Document doc = new Document(); doc.Add(new TextField("field", contents, Field.Store.NO)); w.AddDocument(doc); } w.ForceMerge(1); IndexReader r = w.Reader; IndexSearcher s = NewSearcher(r); w.Dispose(); for (int iter = 0; iter < 10 * RANDOM_MULTIPLIER; iter++) { if (VERBOSE) { Console.WriteLine("iter=" + iter); } IList <string> terms = new List <string>(Arrays.AsList("a", "b", "c", "d", "e", "f")); int numTerms = TestUtil.NextInt(Random(), 1, terms.Count); while (terms.Count > numTerms) { terms.RemoveAt(Random().Next(terms.Count)); } if (VERBOSE) { Console.WriteLine(" terms=" + terms); } BooleanQuery q = new BooleanQuery(); foreach (string term in terms) { q.Add(new BooleanClause(new TermQuery(new Term("field", term)), Occur.SHOULD)); } Weight weight = s.CreateNormalizedWeight(q); Scorer scorer = weight.GetScorer(s.m_leafContexts[0], null); // First pass: just use .NextDoc() to gather all hits IList <ScoreDoc> hits = new List <ScoreDoc>(); while (scorer.NextDoc() != DocIdSetIterator.NO_MORE_DOCS) { hits.Add(new ScoreDoc(scorer.DocID, scorer.GetScore())); } if (VERBOSE) { Console.WriteLine(" " + hits.Count + " hits"); } // Now, randomly next/advance through the list and // verify exact match: for (int iter2 = 0; iter2 < 10; iter2++) { weight = s.CreateNormalizedWeight(q); scorer = weight.GetScorer(s.m_leafContexts[0], null); if (VERBOSE) { Console.WriteLine(" iter2=" + iter2); } int upto = -1; while (upto < hits.Count) { int nextUpto; int nextDoc; int left = hits.Count - upto; if (left == 1 || Random().nextBoolean()) { // next nextUpto = 1 + upto; nextDoc = scorer.NextDoc(); } else { // advance int inc = TestUtil.NextInt(Random(), 1, left - 1); nextUpto = inc + upto; nextDoc = scorer.Advance(hits[nextUpto].Doc); } if (nextUpto == hits.Count) { Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, nextDoc); } else { ScoreDoc hit = hits[nextUpto]; Assert.AreEqual(hit.Doc, nextDoc); // Test for precise float equality: Assert.IsTrue(hit.Score == scorer.GetScore(), "doc " + hit.Doc + " has wrong score: expected=" + hit.Score + " actual=" + scorer.GetScore()); } upto = nextUpto; } } } r.Dispose(); d.Dispose(); }
internal QueryFirstScorer(Weight weight, IBits filterBits, Scorer other) : base(weight) { this.scorer = other; this.filterBits = filterBits; }
public override void SetScorer(Scorer scorer) { collector.SetScorer(scorer); }
public override void SetScorer(Scorer scorer) { _scorer = scorer; }
public override void SetScorer(Scorer scorer) { comparator.SetScorer(scorer); }
internal virtual void FillLeaves(Scorer scorer, ISet<Scorer> set) { if (scorer.Weight.Query is TermQuery) { set.Add(scorer); } else { foreach (ChildScorer child in scorer.Children) { FillLeaves(child.Child, set); } } }
public override void SetScorer(Scorer scorer) { this.scorer = scorer; }
internal PrimaryAdvancedLeapFrogScorer(Weight weight, int firstFilteredDoc, DocIdSetIterator filterIter, Scorer other) : base(weight, filterIter, other, other) { this.firstFilteredDoc = firstFilteredDoc; this.m_primaryDoc = firstFilteredDoc; // initialize to prevent and advance call to move it further }
public override void SetScorer(Scorer scorer) { // Don't do anything. Assign scores in random }
public override void SetScorer(Scorer scorer) { this.scorer = scorer; m_other.SetScorer(cachedScorer); }
public virtual void SetScorer(Scorer scorer) { collector.SetScorer(scorer); }
/// <summary> /// Creates a new instance by wrapping the given scorer. </summary> public ScoreCachingWrappingScorer(Scorer scorer) : base(scorer.m_weight) { this.scorer = scorer; }
// LUCENENET specific - we need to implement these here, since our abstract base class // is now an interface. /// <summary> /// Called before successive calls to <see cref="Collect(int)"/>. Implementations /// that need the score of the current document (passed-in to /// <also cref="Collect(int)"/>), should save the passed-in <see cref="Scorer"/> and call /// <see cref="Scorer.GetScore()"/> when needed. /// </summary> public abstract void SetScorer(Scorer scorer);
public override void SetScorer(Scorer scorer) { this.scorer = scorer; base.SetScorer(scorer); }
public virtual void SetScorer(Scorer scorer) { this.Scorer_Renamed = scorer; }
/// <summary>Returns the scorer to be used for match counting and score summing. /// Uses the given required scorer and the prohibitedScorers. /// </summary> /// <param name="requiredCountingSumScorer">A required scorer already built. /// </param> private Scorer AddProhibitedScorers(Scorer requiredCountingSumScorer) { return((prohibitedScorers.Count == 0)?requiredCountingSumScorer:new ReqExclScorer(requiredCountingSumScorer, ((prohibitedScorers.Count == 1)?prohibitedScorers[0]:new DisjunctionSumScorer(prohibitedScorers)))); }
protected internal LeapFrogScorer(Weight weight, DocIdSetIterator primary, DocIdSetIterator secondary, Scorer scorer) : base(weight) { this.primary = primary; this.secondary = secondary; this.scorer = scorer; }
/// <summary> /// Creates a new ChildScorer node with the specified relationship. /// <p> /// The relationship can be any be any string that makes sense to /// the parent Scorer. /// </summary> public ChildScorer(Scorer child, string relationship) { this.Child = child; this.Relationship = relationship; }
/// <summary> /// Construct a <see cref="ReqExclScorer"/>. </summary> /// <param name="reqScorer"> The scorer that must match, except where </param> /// <param name="exclDisi"> Indicates exclusion. </param> public ReqExclScorer(Scorer reqScorer, DocIdSetIterator exclDisi) : base(reqScorer.m_weight) { this.reqScorer = reqScorer; this.exclDisi = exclDisi; }
public override void SetScorer(Scorer scorer) { this.scorer = scorer; comparator.SetScorer(scorer); }
public virtual void SetScorer(Scorer scorer) { @in.SetScorer(AssertingScorer.GetAssertingScorer(random, scorer)); }
public QueryFirstBulkScorer(Scorer scorer, IBits filterBits) { this.scorer = scorer; this.filterBits = filterBits; }
public virtual void SetScorer(Scorer scorer) { // scorer is not needed }
public virtual void SetScorer(Scorer scorer) { }
internal DocsAndFreqs(Scorer scorer) { this.Scorer = scorer; this.Cost = scorer.GetCost(); this.Doc = -1; }