// firstDocID is ignored since nextDoc() sets 'doc' public /*protected internal*/ override bool Score(Collector c, int end, int firstDocID) { c.SetScorer(this); while (doc < end) { // for docs in window c.Collect(doc); // collect score if (++pointer >= pointerMax) { pointerMax = termDocs.Read(docs, freqs); // refill buffers if (pointerMax != 0) { pointer = 0; } else { termDocs.Close(); // close stream doc = System.Int32.MaxValue; // set to sentinel value return false; } } doc = docs[pointer]; } return true; }
private void SearchWithFilter(IndexReader reader, Weight weight, Filter filter, Collector collector) { DocIdSet docIdSet = filter.GetDocIdSet(reader); if (docIdSet == null) return; Scorer scorer = weight.Scorer(reader, true, false); if (scorer == null) return; scorer.DocID(); DocIdSetIterator docIdSetIterator = docIdSet.Iterator(); if (docIdSetIterator == null) return; int target = docIdSetIterator.NextDoc(); int num = scorer.Advance(target); collector.SetScorer(scorer); while (true) { while (num != target) { if (num > target) target = docIdSetIterator.Advance(num); else num = scorer.Advance(target); } if (num != DocIdSetIterator.NO_MORE_DOCS && !((GroupCollector)collector).GroupLimitReached) { collector.Collect(num); target = docIdSetIterator.NextDoc(); num = scorer.Advance(target); } else break; } }
internal AssertingCollector(Random random, Collector @in, bool inOrder) { this.Random = random; this.@in = @in; this.InOrder = inOrder; LastCollected = -1; }
/// <summary> Create a TimeLimitedCollector wrapper over another <see cref="Collector" /> with a specified timeout.</summary> /// <param name="collector">the wrapped <see cref="Collector" /> /// </param> /// <param name="timeAllowed">max time allowed for collecting hits after which <see cref="TimeExceededException" /> is thrown /// </param> public TimeLimitingCollector(Collector collector, long timeAllowed) { InitBlock(); this.collector = collector; t0 = TIMER_THREAD.GetMilliseconds(); this.timeout = t0 + timeAllowed; }
public override bool Score(Collector collector, int max) { RandomOrderCollector randomCollector = new RandomOrderCollector(Random, collector); bool remaining = @in.Score(randomCollector, max); randomCollector.Flush(); return remaining; }
/// <summary>Scores and collects all matching documents.</summary> /// <param name="collector">The collector to which all matching documents are passed. /// <br/>When this method is used the {@link #Explain(int)} method should not be used. /// </param> public virtual void Score(Collector collector) { collector.SetScorer(this); int doc; while ((doc = NextDoc()) != NO_MORE_DOCS) { collector.Collect(doc); } }
internal RandomOrderCollector(Random random, Collector @in) { if ([email protected]()) { throw new System.ArgumentException(); } this.@in = @in; this.Random = random; BufferSize = 1 + random.Next(100); DocIDs = new int[BufferSize]; Scores = new float[BufferSize]; Freqs = new int[BufferSize]; Buffered = 0; }
// Prevent extension from non-internal classes private CachingCollector(Collector other, double maxRAMMB, bool cacheScores) { this.Other = other; CachedDocs = new List<int[]>(); CurDocs = new int[INITIAL_ARRAY_SIZE]; CachedDocs.Add(CurDocs); int bytesPerDoc = RamUsageEstimator.NUM_BYTES_INT; if (cacheScores) { bytesPerDoc += RamUsageEstimator.NUM_BYTES_FLOAT; } MaxDocsToCache = (int)((maxRAMMB * 1024 * 1024) / bytesPerDoc); }
public override void Score(Collector collector) { if (Random.NextBoolean()) { try { bool remaining = @in.Score(collector, DocsEnum.NO_MORE_DOCS); Debug.Assert(!remaining); } catch (System.NotSupportedException e) { @in.Score(collector); } } else { @in.Score(collector); } }
public override void Search(Weight weight, Filter filter, Collector collector) { if (filter == null) { for (int index = 0; index < this.subReaders.Length; ++index) { collector.SetNextReader(this.subReaders[index], this.docStarts[index]); Scorer scorer = weight.Scorer(this.subReaders[index], !collector.AcceptsDocsOutOfOrder, true); if (scorer != null) this.SearchWithScorer(this.subReaders[index], weight, scorer, collector); } } else { for (int index = 0; index < this.subReaders.Length; ++index) { collector.SetNextReader(this.subReaders[index], this.docStarts[index]); this.SearchWithFilter(this.subReaders[index], weight, filter, collector); } } }
public SubScorer(Scorer scorer, bool required, bool prohibited, Collector collector, SubScorer next) { this.scorer = scorer; this.required = required; this.prohibited = prohibited; this.collector = collector; this.next = next; }
/// <summary> /// Searches for documents mapped from the given type using the specified query and Collector. /// </summary> /// <param name="searcher"> /// The Searcher to search on. /// </param> /// <param name="type"> /// The type of the object to search documents for. /// </param> /// <param name="query"> /// The Query which selects the documents. /// </param> /// <param name="results"> /// The Collector to use to gather results. /// </param> public static void Search(this Searcher searcher, Type type, Query query, Collector results) { searcher.Search(query, ObjectMapping.GetTypeFilter(type), results); }
private void SearchWithFilter(IndexReader reader, Weight weight, Filter filter, Collector collector, IState state) { System.Diagnostics.Debug.Assert(filter != null); Scorer scorer = weight.Scorer(reader, true, false, state); if (scorer == null) { return; } int docID = scorer.DocID(); System.Diagnostics.Debug.Assert(docID == -1 || docID == DocIdSetIterator.NO_MORE_DOCS); // CHECKME: use ConjunctionScorer here? DocIdSet filterDocIdSet = filter.GetDocIdSet(reader, state); if (filterDocIdSet == null) { // this means the filter does not accept any documents. return; } DocIdSetIterator filterIter = filterDocIdSet.Iterator(state); if (filterIter == null) { // this means the filter does not accept any documents. return; } int filterDoc = filterIter.NextDoc(state); int scorerDoc = scorer.Advance(filterDoc, state); collector.SetScorer(scorer); while (true) { if (scorerDoc == filterDoc) { // Check if scorer has exhausted, only before collecting. if (scorerDoc == DocIdSetIterator.NO_MORE_DOCS) { break; } collector.Collect(scorerDoc, state); filterDoc = filterIter.NextDoc(state); scorerDoc = scorer.Advance(filterDoc, state); } else if (scorerDoc > filterDoc) { filterDoc = filterIter.Advance(scorerDoc, state); } else { scorerDoc = scorer.Advance(filterDoc, state); } } }
/// <summary>Lower-level search API. /// /// <p/><see cref="Collector.Collect(int)" /> is called for every matching /// document. /// <br/>Collector-based access to remote indexes is discouraged. /// /// <p/>Applications should only use this if they need <i>all</i> of the /// matching documents. The high-level search API (<see cref="Searcher.Search(Query, Filter, int)" />) /// is usually more efficient, as it skips /// non-high-scoring hits. /// /// </summary> /// <param name="query">to match documents /// </param> /// <param name="filter">if non-null, used to permit documents to be collected. /// </param> /// <param name="results">to receive hits /// </param> /// <throws> BooleanQuery.TooManyClauses </throws> public virtual void Search(Query query, Filter filter, Collector results) { Search(CreateWeight(query), filter, results); }
/// <summary>Lower-level search API. /// /// <p/><see cref="Collector.Collect(int)" /> is called for every matching /// document. /// <br/>Collector-based access to remote indexes is discouraged. /// /// <p/>Applications should only use this if they need <i>all</i> of the /// matching documents. The high-level search API (<see cref="Searcher.Search(Query, Filter, int)" />) /// is usually more efficient, as it skips /// non-high-scoring hits. /// /// </summary> /// <param name="query">to match documents /// </param> /// <param name="filter">if non-null, used to permit documents to be collected. /// </param> /// <param name="results">to receive hits /// </param> /// <throws> BooleanQuery.TooManyClauses </throws> public virtual void Search(Query query, Filter filter, Collector results) { Search(CreateWeight(query), filter, results); }
// inherit javadoc public override void Search(Weight weight, Filter filter, Collector collector) { for (int i = 0; i < searchables.Length; i++) { int start = starts[i]; Collector hc = new AnonymousClassCollector(collector, start, this); searchables[i].Search(weight, filter, hc); } }
/// <summary> Expert: Collects matching documents in a range. Hook for optimization. /// Note, <code>firstDocID</code> is added to ensure that {@link #NextDoc()} /// was called before this method. /// /// </summary> /// <param name="collector">The collector to which all matching documents are passed. /// </param> /// <param name="max">Do not score documents past this. /// </param> /// <param name="firstDocID"> /// The first document ID (ensures {@link #NextDoc()} is called before /// this method. /// </param> /// <returns> true if more matching documents may remain. /// </returns> public /*protected internal*/ virtual bool Score(Collector collector, int max, int firstDocID) { collector.SetScorer(this); int doc = firstDocID; while (doc < max) { collector.Collect(doc); doc = NextDoc(); } return doc != NO_MORE_DOCS; }
public CountingCollector(Collector other) : this(other, new HashSet <string> { "MUST", "SHOULD", "MUST_NOT" }) { }
protected internal override void Search(IList <AtomicReaderContext> leaves, Weight weight, Collector collector) { Assert.AreEqual(-1, collector.GetType().Name.IndexOf("OutOfOrder")); base.Search(leaves, weight, collector); }
public override void Search(Query query, Collector results, IState state) { CheckExplanations(query); base.Search(query, results, null); }
public override void Score(Collector c) { Score(c, System.Int32.MaxValue, NextDoc()); }
/// <summary> /// Create a TimeLimitedCollector wrapper over another <seealso cref="Collector"/> with a specified timeout. </summary> /// <param name="collector"> the wrapped <seealso cref="Collector"/> </param> /// <param name="clock"> the timer clock </param> /// <param name="ticksAllowed"> max time allowed for collecting /// hits after which <seealso cref="TimeExceededException"/> is thrown </param> public TimeLimitingCollector(Collector collector, Counter clock, long ticksAllowed) { this.collector = collector; this.Clock = clock; this.TicksAllowed = ticksAllowed; }
public virtual void Search(Weight weight, Collector collector) { Search(Ctx, weight, collector); }
public override void Score(Collector collector) { Score(collector, System.Int32.MaxValue, NextDoc()); }
public CountingCollector(Collector other, ISet<string> relationships) { this.Other = other; this.Relationships = relationships; }
public CountingCollector(Collector other, ISet <string> relationships) { this.Other = other; this.Relationships = relationships; }
/// <summary>Scores and collects all matching documents.</summary> /// <param name="collector">The collector to which all matching documents are passed through. /// <br/>When this method is used the <see cref="Explain(int)" /> method should not be used. /// </param> public override void Score(Collector collector) { collector.SetScorer(this); while (NextDoc() != NO_MORE_DOCS) { collector.Collect(currentDoc); } }
protected override void Search(IList <AtomicReaderContext> leaves, Weight weight, Collector collector) { // TODO: shouldn't we AssertingCollector.wrap(collector) here? base.Search(leaves, AssertingWeight.Wrap(Random, weight), collector); }
public abstract void Search(Weight weight, Filter filter, Collector results);
/// <summary>Lower-level search API. /// /// <p/><see cref="Collector.Collect(int)" /> is called for every matching document. /// /// <p/>Applications should only use this if they need <i>all</i> of the matching /// documents. The high-level search API (<see cref="Searcher.Search(Query, int)" /> /// ) is usually more efficient, as it skips non-high-scoring hits. /// <p/>Note: The <c>score</c> passed to this method is a raw score. /// In other words, the score will not necessarily be a float whose value is /// between 0 and 1. /// </summary> /// <throws> BooleanQuery.TooManyClauses </throws> public virtual void Search(Query query, Collector results, IState state) { Search(CreateWeight(query, state), null, results, state); }
public override void Score(Collector collector) { scorer.Score(collector); }
/// <summary>Lower-level search API. /// /// <p/><see cref="Collector.Collect(int)" /> is called for every matching /// document. /// <br/>Collector-based access to remote indexes is discouraged. /// /// <p/>Applications should only use this if they need <i>all</i> of the /// matching documents. The high-level search API (<see cref="Searcher.Search(Query, Filter, int)" />) /// is usually more efficient, as it skips /// non-high-scoring hits. /// /// </summary> /// <param name="query">to match documents /// </param> /// <param name="filter">if non-null, used to permit documents to be collected. /// </param> /// <param name="results">to receive hits /// </param> /// <throws> BooleanQuery.TooManyClauses </throws> public virtual void Search(Query query, Filter filter, Collector results, IState state) { Search(CreateWeight(query, state), filter, results, state); }
public override void Search(Weight weight, Filter filter, Collector results) { throw new System.NotSupportedException(); }
internal NoScoreCachingCollector(Collector other, double maxRAMMB) : base(other, maxRAMMB, false) { }
private void Search(Collector collector) { searcher.Search(query, collector); }
internal NoScoreCachingCollector(Collector other, int maxDocsToCache) : base(other, maxDocsToCache) { }
/// <summary> /// Create a new <seealso cref="CachingCollector"/> that wraps the given collector and /// caches documents and scores up to the specified RAM threshold. /// </summary> /// <param name="other"> /// the Collector to wrap and delegate calls to. </param> /// <param name="cacheScores"> /// whether to cache scores in addition to document IDs. Note that /// this increases the RAM consumed per doc </param> /// <param name="maxRAMMB"> /// the maximum RAM in MB to consume for caching the documents and /// scores. If the collector exceeds the threshold, no documents and /// scores are cached. </param> public static CachingCollector Create(Collector other, bool cacheScores, double maxRAMMB) { return(cacheScores ? (CachingCollector) new ScoreCachingCollector(other, maxRAMMB) : new NoScoreCachingCollector(other, maxRAMMB)); }
/// <summary> /// Create a new <seealso cref="CachingCollector"/> that wraps the given collector and /// caches documents and scores up to the specified max docs threshold. /// </summary> /// <param name="other"> /// the Collector to wrap and delegate calls to. </param> /// <param name="cacheScores"> /// whether to cache scores in addition to document IDs. Note that /// this increases the RAM consumed per doc </param> /// <param name="maxDocsToCache"> /// the maximum number of documents for caching the documents and /// possible the scores. If the collector exceeds the threshold, /// no documents and scores are cached. </param> public static CachingCollector Create(Collector other, bool cacheScores, int maxDocsToCache) { return(cacheScores ? (CachingCollector) new ScoreCachingCollector(other, maxDocsToCache) : new NoScoreCachingCollector(other, maxDocsToCache)); }
// firstDocID is ignored since nextDoc() initializes 'current' public /*protected internal*/ override bool Score(Collector collector, int max, int firstDocID) { bool more; Bucket tmp; BucketScorer bs = new BucketScorer(); // The internal loop will set the score and doc before calling collect. collector.SetScorer(bs); do { bucketTable.first = null; while (current != null) { // more queued // check prohibited & required if ((current.bits & prohibitedMask) == 0 && (current.bits & requiredMask) == requiredMask) { if (current.doc >= max) { tmp = current; current = current.next; tmp.next = bucketTable.first; bucketTable.first = tmp; continue; } if (current.coord >= minNrShouldMatch) { bs.score = current.score * coordFactors[current.coord]; bs.doc = current.doc; collector.Collect(current.doc); } } current = current.next; // pop the queue } if (bucketTable.first != null) { current = bucketTable.first; bucketTable.first = current.next; return true; } // refill the queue more = false; end += BucketTable.SIZE; for (SubScorer sub = scorers; sub != null; sub = sub.next) { int subScorerDocID = sub.scorer.DocID(); if (subScorerDocID != NO_MORE_DOCS) { more |= sub.scorer.Score(sub.collector, end, subScorerDocID); } } current = bucketTable.first; } while (current != null || more); return false; }
/// <summary> /// Replays the cached doc IDs (and scores) to the given Collector. If this /// instance does not cache scores, then Scorer is not set on /// {@code other.setScorer} as well as scores are not replayed. /// </summary> /// <exception cref="InvalidOperationException"> /// if this collector is not cached (i.e., if the RAM limits were too /// low for the number of documents + scores to cache). </exception> /// <exception cref="IllegalArgumentException"> /// if the given Collect's does not support out-of-order collection, /// while the collector passed to the ctor does. </exception> public abstract void Replay(Collector other);
public CountingCollector(Collector other) : this(other, new HashSet<string> { "MUST", "SHOULD", "MUST_NOT" }) { }
public override void Search(Query query, Filter filter, Collector results) { CheckExplanations(query); base.Search(query, filter, results); }
public PositiveScoresOnlyCollector(Collector c) { this.c = c; }
public override bool Score(Collector collector, int max) { collector.Scorer = new FakeScorer(); collector.Collect(0); return(false); }
public override void Search(Query query, Filter filter, Collector results) { throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG); }
public override void Score(Collector collector) { RandomOrderCollector randomCollector = new RandomOrderCollector(Random, collector); @in.Score(randomCollector); randomCollector.Flush(); }
/// <summary>Expert: Collects matching documents in a range. Hook for optimization. /// Note that <see cref="Next()" /> must be called once before this method is called /// for the first time. /// </summary> /// <param name="collector">The collector to which all matching documents are passed through. /// </param> /// <param name="max">Do not score documents past this. /// </param> /// <param name="firstDocID"></param> /// <returns> true if more matching documents may remain. /// </returns> public /*protected internal*/ override bool Score(Collector collector, int max, int firstDocID) { // firstDocID is ignored since nextDoc() sets 'currentDoc' collector.SetScorer(this); while (currentDoc < max) { collector.Collect(currentDoc); if (NextDoc() == NO_MORE_DOCS) { return false; } } return true; }
private void SearchWithFilter(IndexReader reader, Weight weight, Filter filter, Collector collector) { System.Diagnostics.Debug.Assert(filter != null); Scorer scorer = weight.Scorer(reader, true, false); if (scorer == null) { return ; } int docID = scorer.DocID(); System.Diagnostics.Debug.Assert(docID == - 1 || docID == DocIdSetIterator.NO_MORE_DOCS); // CHECKME: use ConjunctionScorer here? DocIdSet filterDocIdSet = filter.GetDocIdSet(reader); if (filterDocIdSet == null) { // this means the filter does not accept any documents. return ; } DocIdSetIterator filterIter = filterDocIdSet.Iterator(); if (filterIter == null) { // this means the filter does not accept any documents. return ; } int filterDoc = filterIter.NextDoc(); int scorerDoc = scorer.Advance(filterDoc); collector.SetScorer(scorer); while (true) { if (scorerDoc == filterDoc) { // Check if scorer has exhausted, only before collecting. if (scorerDoc == DocIdSetIterator.NO_MORE_DOCS) { break; } collector.Collect(scorerDoc); filterDoc = filterIter.NextDoc(); scorerDoc = scorer.Advance(filterDoc); } else if (scorerDoc > filterDoc) { filterDoc = filterIter.Advance(scorerDoc); } else { scorerDoc = scorer.Advance(filterDoc); } } }
public override void Search(Weight weight, Filter filter, Collector results) { throw new System.NotSupportedException(); }
public override void Search(Query query, Filter filter, Collector results) { throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG); }
/// <summary>Lower-level search API. /// /// <p/><see cref="Collector.Collect(int)" /> is called for every matching document. /// /// <p/>Applications should only use this if they need <i>all</i> of the matching /// documents. The high-level search API (<see cref="Searcher.Search(Query, int)" /> /// ) is usually more efficient, as it skips non-high-scoring hits. /// <p/>Note: The <c>score</c> passed to this method is a raw score. /// In other words, the score will not necessarily be a float whose value is /// between 0 and 1. /// </summary> /// <throws> BooleanQuery.TooManyClauses </throws> public virtual void Search(Query query, Collector results) { Search(CreateWeight(query), null, results); }
/// <summary> /// Searches for documents mapped from the given type using the specified query and Collector. /// </summary> /// <typeparam name="TObject"> /// The type of the object to search documents for. /// </typeparam> /// <param name="searcher"> /// The Searcher to search on. /// </param> /// <param name="query"> /// The Query which selects the documents. /// </param> /// <param name="results"> /// The Collector to use to gather results. /// </param> public static void Search <TObject>(this Searcher searcher, Query query, Collector results) { searcher.Search(query, ObjectMapping.GetTypeFilter <TObject>(), results); }
public /*protected internal*/ override bool Score(Collector collector, int max, int firstDocID) { throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG); }
public /*protected internal*/ override bool Score(Collector collector, int max, int firstDocID) { return(scorer.Score(collector, max, firstDocID)); }
/// <summary>Lower-level search API. /// /// <p/><see cref="Collector.Collect(int)" /> is called for every matching document. /// /// <p/>Applications should only use this if they need <i>all</i> of the matching /// documents. The high-level search API (<see cref="Searcher.Search(Query, int)" /> /// ) is usually more efficient, as it skips non-high-scoring hits. /// <p/>Note: The <c>score</c> passed to this method is a raw score. /// In other words, the score will not necessarily be a float whose value is /// between 0 and 1. /// </summary> /// <throws> BooleanQuery.TooManyClauses </throws> public virtual void Search(Query query, Collector results) { Search(CreateWeight(query), null, results); }
/// <summary> /// Searches for documents mapped from the given type using the specified query and Collector. /// </summary> /// <typeparam name="TObject"> /// The type of the object to search documents for. /// </typeparam> /// <param name="searcher"> /// The Searcher to search on. /// </param> /// <param name="kind"> /// The kind of type to restrict the search to. /// </param> /// <param name="query"> /// The Query which selects the documents. /// </param> /// <param name="results"> /// The Collector to use to gather results. /// </param> public static void Search <TObject>(this Searcher searcher, DocumentObjectTypeKind kind, Query query, Collector results) { searcher.Search(query, ObjectMapping.GetTypeFilter <TObject>(kind), results); }
public override void Search(Weight weight, Filter filter, Collector collector) { if (filter == null) { for (int i = 0; i < subReaders.Length; i++) { // search each subreader collector.SetNextReader(subReaders[i], docStarts[i]); Scorer scorer = weight.Scorer(subReaders[i], !collector.AcceptsDocsOutOfOrder(), true); if (scorer != null) { scorer.Score(collector); } } } else { for (int i = 0; i < subReaders.Length; i++) { // search each subreader collector.SetNextReader(subReaders[i], docStarts[i]); SearchWithFilter(subReaders[i], weight, filter, collector); } } }
public PositiveScoresOnlyCollector(Collector c) { this.c = c; }
public EarlyTerminatingSortingCollectorHelper(Collector @in, Sort sort, int numDocsToCollect) : base(@in, sort, numDocsToCollect) { }
public abstract void Search(Weight weight, Filter filter, Collector results);