/// <summary> Create a TimeLimitedCollector wrapper over another HitCollector with a specified timeout.</summary> /// <param name="hc">the wrapped HitCollector /// </param> /// <param name="timeAllowed">max time allowed for collecting hits after which {@link TimeExceededException} is thrown /// </param> public TimeLimitedCollector(HitCollector hc, long timeAllowed) { InitBlock(); this.hc = hc; t0 = TIMER_THREAD.GetMilliseconds(); this.timeout = t0 + timeAllowed; }
protected internal override bool Score(HitCollector c, int end) { Similarity similarity = GetSimilarity(); // cache sim in local float[] normDecoder = Similarity.GetNormDecoder(); while (doc < end) { // for docs in window int f = freqs[pointer]; float score = f < SCORE_CACHE_SIZE?scoreCache[f]:similarity.Tf(f) * weightValue; // cache miss score *= normDecoder[norms[doc] & 0xFF]; // normalize for field c.Collect(doc, score); // 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); }
/// <summary>Scores and collects all matching documents.</summary> /// <param name="hc">The collector to which all matching documents are passed through /// {@link HitCollector#Collect(int, float)}. /// <br>When this method is used the {@link #Explain(int)} method should not be used. /// </param> public override void Score(HitCollector hc) { if (allowDocsOutOfOrder && requiredScorers.Count == 0 && prohibitedScorers.Count < 32) { // fall back to BooleanScorer, scores documents somewhat out of order BooleanScorer bs = new BooleanScorer(GetSimilarity(), minNrShouldMatch); System.Collections.IEnumerator si = optionalScorers.GetEnumerator(); while (si.MoveNext()) { bs.Add((Scorer)si.Current, false, false); } si = prohibitedScorers.GetEnumerator(); while (si.MoveNext()) { bs.Add((Scorer)si.Current, false, true); } bs.Score(hc); } else { if (countingSumScorer == null) { InitCountingSumScorer(); } while (countingSumScorer.Next()) { hc.Collect(countingSumScorer.Doc(), Score()); } } }
/// <summary>Scores and collects all matching documents.</summary> /// <param name="hc">The collector to which all matching documents are passed through /// {@link HitCollector#Collect(int, float)}. /// <br>When this method is used the {@link #Explain(int)} method should not be used. /// </param> public virtual void Score(HitCollector hc) { while (Next()) { hc.Collect(Doc(), Score()); } }
/// <summary>Scores and collects all matching documents.</summary> /// <param name="hc">The collector to which all matching documents are passed through /// {@link HitCollector#Collect(int, float)}. /// <br>When this method is used the {@link #Explain(int)} method should not be used. /// </param> public override void Score(HitCollector hc) { while (Next()) { hc.Collect(currentDoc, currentScore); } }
protected internal override bool Score(HitCollector c, int end) { Similarity similarity = GetSimilarity(); // cache sim in local float[] normDecoder = Similarity.GetNormDecoder(); while (doc < end) { // for docs in window int f = freqs[pointer]; float score = f < SCORE_CACHE_SIZE ? scoreCache[f] : similarity.Tf(f) * weightValue; // cache miss score *= normDecoder[norms[doc] & 0xFF]; // normalize for field c.Collect(doc, score); // 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; }
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; }
// inherit javadoc public override void Search(Weight weight, Filter filter, HitCollector results) { for (int i = 0; i < searchables.Length; i++) { int start = starts[i]; searchables[i].Search(weight, filter, new AnonymousClassHitCollector(results, start, this)); } }
/// <summary>Expert: Collects matching documents in a range. Hook for optimization. /// Note that {@link #Next()} must be called once before this method is called /// for the first time. /// </summary> /// <param name="hc">The collector to which all matching documents are passed through /// {@link HitCollector#Collect(int, float)}. /// </param> /// <param name="max">Do not score documents past this. /// </param> /// <returns> true if more matching documents may remain. /// </returns> protected internal virtual bool Score(HitCollector hc, int max) { while (Doc() < max) { hc.Collect(Doc(), Score()); if (!Next()) return false; } return true; }
/// <summary>Scores and collects all matching documents.</summary> /// <param name="hc">The collector to which all matching documents are passed through /// {@link HitCollector#Collect(int, float)}. /// <br>When this method is used the {@link #Explain(int)} method should not be used. /// </param> public override void Score(HitCollector hc) { if (countingSumScorer == null) { InitCountingSumScorer(); } while (countingSumScorer.Next()) { hc.Collect(countingSumScorer.Doc(), Score()); } }
/// <summary>Expert: Collects matching documents in a range. Hook for optimization. /// Note that {@link #Next()} must be called once before this method is called /// for the first time. /// </summary> /// <param name="hc">The collector to which all matching documents are passed through /// {@link HitCollector#Collect(int, float)}. /// </param> /// <param name="max">Do not score documents past this. /// </param> /// <returns> true if more matching documents may remain. /// </returns> protected internal virtual bool Score(HitCollector hc, int max) { while (Doc() < max) { hc.Collect(Doc(), Score()); if (!Next()) { return(false); } } return(true); }
/// <summary>Expert: Collects matching documents in a range. Hook for optimization. /// Note that {@link #Next()} must be called once before this method is called /// for the first time. /// </summary> /// <param name="hc">The collector to which all matching documents are passed through /// {@link HitCollector#Collect(int, float)}. /// </param> /// <param name="max">Do not score documents past this. /// </param> /// <returns> true if more matching documents may remain. /// </returns> protected internal override bool Score(HitCollector hc, int max) { while (currentDoc < max) { hc.Collect(currentDoc, currentScore); if (!Next()) { return(false); } } return(true); }
private void DoTestTimeout(bool multiThreaded, bool greedy) { // setup MyHitCollector myHc = new MyHitCollector(this); myHc.SetSlowDown(SLOW_DOWN); HitCollector tlCollector = CreateTimedCollector(myHc, TIME_ALLOWED, greedy); // search TimeLimitedCollector.TimeExceededException timoutException = null; try { Search(tlCollector); } catch (TimeLimitedCollector.TimeExceededException x) { timoutException = x; } catch (System.Exception e) { Assert.IsTrue(false, "Unexpected exception: " + e); //==fail } // must get exception Assert.IsNotNull(timoutException, "Timeout expected!"); // greediness affect last doc collected int exceptionDoc = timoutException.GetLastDocCollected(); int lastCollected = myHc.GetLastDocCollected(); Assert.IsTrue(exceptionDoc > 0, "doc collected at timeout must be > 0!"); if (greedy) { Assert.IsTrue(exceptionDoc == lastCollected, "greedy=" + greedy + " exceptionDoc=" + exceptionDoc + " != lastCollected=" + lastCollected); Assert.IsTrue(myHc.HitCount() > 0, "greedy, but no hits found!"); } else { Assert.IsTrue(exceptionDoc > lastCollected, "greedy=" + greedy + " exceptionDoc=" + exceptionDoc + " not > lastCollected=" + lastCollected); } // verify that elapsed time at exception is within valid limits Assert.AreEqual(timoutException.GetTimeAllowed(), TIME_ALLOWED); // a) Not too early Assert.IsTrue(timoutException.GetTimeElapsed() > TIME_ALLOWED - TimeLimitedCollector.GetResolution(), "elapsed=" + timoutException.GetTimeElapsed() + " <= (allowed-resolution)=" + (TIME_ALLOWED - TimeLimitedCollector.GetResolution())); // b) Not too late. // This part is problematic in a busy test system, so we just print a warning. // We already verified that a timeout occurred, we just can't be picky about how long it took. if (timoutException.GetTimeElapsed() > MaxTime(multiThreaded)) { System.Console.Out.WriteLine("Informative: timeout exceeded (no action required: most probably just " + " because the test machine is slower than usual): " + "lastDoc=" + exceptionDoc + " ,&& allowed=" + timoutException.GetTimeAllowed() + " ,&& elapsed=" + timoutException.GetTimeElapsed() + " >= " + MaxTimeStr(multiThreaded)); } }
/// <summary>Expert: Collects matching documents in a range. /// <br>Note that {@link #Next()} must be called once before this method is /// called for the first time. /// </summary> /// <param name="hc">The collector to which all matching documents are passed through /// {@link HitCollector#Collect(int, float)}. /// </param> /// <param name="max">Do not score documents past this. /// </param> /// <returns> true if more matching documents may remain. /// </returns> protected internal override bool Score(HitCollector hc, int max) { // null pointer exception when Next() was not called before: int docNr = countingSumScorer.Doc(); while (docNr < max) { hc.Collect(docNr, Score()); if (!countingSumScorer.Next()) { return(false); } docNr = countingSumScorer.Doc(); } return(true); }
// 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); }
// 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); } } } }
private void DoTestSearch() { int totalResults = 0; int totalTLCResults = 0; try { MyHitCollector myHc = new MyHitCollector(this); Search(myHc); totalResults = myHc.HitCount(); myHc = new MyHitCollector(this); long oneHour = 3600000; HitCollector tlCollector = CreateTimedCollector(myHc, oneHour, false); Search(tlCollector); totalTLCResults = myHc.HitCount(); } catch (System.Exception e) { System.Console.Error.WriteLine(e.StackTrace); Assert.IsTrue(false, "Unexpected exception: " + e); //==fail } Assert.AreEqual(totalResults, totalTLCResults, "Wrong number of results!"); }
protected internal override bool Score(HitCollector c, int end) { return(Score(new HitCollectorWrapper(c), end, doc)); }
public override void Score(HitCollector hc) { Score(new HitCollectorWrapper(hc)); }
public virtual void Search(Weight weight, Filter filter, HitCollector results) { Search(weight, filter, new HitCollectorWrapper(results)); }
public override void Search(Query query, Filter filter, HitCollector results) { Search(query, filter, new HitCollectorWrapper(results)); }
public virtual void Search(Query query, HitCollector results) { Search(CreateWeight(query), null, new HitCollectorWrapper(results)); }
/// <summary>Scores and collects all matching documents.</summary> /// <param name="hc">The collector to which all matching documents are passed through /// {@link HitCollector#Collect(int, float)}. /// <br>When this method is used the {@link #Explain(int)} method should not be used. /// </param> public override void Score(HitCollector hc) { if (allowDocsOutOfOrder && requiredScorers.Count == 0 && prohibitedScorers.Count < 32) { // fall back to BooleanScorer, scores documents somewhat out of order BooleanScorer bs = new BooleanScorer(GetSimilarity(), minNrShouldMatch); System.Collections.IEnumerator si = optionalScorers.GetEnumerator(); while (si.MoveNext()) { bs.Add((Scorer) si.Current, false, false); } si = prohibitedScorers.GetEnumerator(); while (si.MoveNext()) { bs.Add((Scorer) si.Current, false, true); } bs.Score(hc); } else { if (countingSumScorer == null) { InitCountingSumScorer(); } while (countingSumScorer.Next()) { hc.Collect(countingSumScorer.Doc(), Score()); } } }
protected internal override bool Score(HitCollector hc, int max) { if (coordFactors == null) ComputeCoordFactors(); bool more; Bucket tmp; 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; } hc.Collect(current.doc, current.score * coordFactors[current.coord]); } 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) { if (!sub.done) { sub.done = !sub.scorer.Score(sub.collector, end); if (!sub.done) more = true; } } current = bucketTable.first; } while (current != null || more); return false; }
// 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 HitCollectorWrapper(HitCollector collector) { this.collector = collector; }
public override void Search(Weight weight, Filter filter, HitCollector results) { throw new System.NotSupportedException(); }
// this implementation should be removed when the deprecated // Searchable#search(Query,Filter,HitCollector) is removed public virtual void Search(Query query, Filter filter, HitCollector results) { local.Search(query, filter, results); }
private void Search(HitCollector collector) { searcher.Search(query, collector); }
/// <summary>Lower-level search API. /// /// <p>{@link HitCollector#Collect(int,float)} is called for every non-zero /// scoring document. /// <br>HitCollector-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 ({@link /// Searcher#Search(Query)}) 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, a bitset used to eliminate some documents /// </param> /// <param name="results">to receive hits /// </param> /// <throws> BooleanQuery.TooManyClauses </throws> public virtual void Search(Query query, Filter filter, HitCollector results) { Search(CreateWeight(query), filter, results); }
protected internal virtual bool Score(HitCollector hc, int max) { return Score(new HitCollectorWrapper(hc), max, DocID()); }
/// <summary>Expert: Collects matching documents in a range. /// <br>Note that {@link #Next()} must be called once before this method is /// called for the first time. /// </summary> /// <param name="hc">The collector to which all matching documents are passed through /// {@link HitCollector#Collect(int, float)}. /// </param> /// <param name="max">Do not score documents past this. /// </param> /// <returns> true if more matching documents may remain. /// </returns> protected internal override bool Score(HitCollector hc, int max) { // null pointer exception when Next() was not called before: int docNr = countingSumScorer.Doc(); while (docNr < max) { hc.Collect(docNr, Score()); if (!countingSumScorer.Next()) { return false; } docNr = countingSumScorer.Doc(); } return true; }
public virtual void Score(HitCollector hc) { Score(new HitCollectorWrapper(hc)); }
public override void Score(HitCollector hc) { Next(); Score(hc, System.Int32.MaxValue); }
public override void Search(Query query, Filter filter, HitCollector results) { CheckExplanations(query); base.Search(query, filter, results); }
/// <summary>Lower-level search API. /// /// <p>{@link HitCollector#Collect(int,float)} is called for every non-zero /// scoring document. /// /// <p>Applications should only use this if they need <i>all</i> of the /// matching documents. The high-level search API ({@link /// Searcher#Search(Query)}) is usually more efficient, as it skips /// non-high-scoring hits. /// <p>Note: The <code>score</code> 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, HitCollector results) { Search(query, (Filter)null, results); }
protected internal override bool Score(HitCollector hc, int max) { if (coordFactors == null) { ComputeCoordFactors(); } bool more; Bucket tmp; 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; } hc.Collect(current.doc, current.score * coordFactors[current.coord]); } 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) { if (!sub.done) { sub.done = !sub.scorer.Score(sub.collector, end); if (!sub.done) { more = true; } } } current = bucketTable.first; }while (current != null || more); return(false); }
/* The following abstract methods were added as a workaround for GCJ bug #15411. * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15411 */ abstract public void Search(Weight weight, Filter filter, HitCollector results);
public virtual void Search(Weight weight, Filter filter, HitCollector results) { local.Search(weight, filter, results); }
// 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); }
protected internal override bool Score(HitCollector hc, int max) { return(Score(new HitCollectorWrapper(hc), max, DocID())); }
protected internal override bool Score(HitCollector c, int end) { return Score(new HitCollectorWrapper(c), end, doc); }
/// <summary>Lower-level search API. /// /// <p>{@link HitCollector#Collect(int,float)} is called for every non-zero /// scoring document. /// /// <p>Applications should only use this if they need <i>all</i> of the /// matching documents. The high-level search API ({@link /// Searcher#Search(Query)}) is usually more efficient, as it skips /// non-high-scoring hits. /// <p>Note: The <code>score</code> 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, HitCollector results) { Search(query, (Filter) null, results); }
/// <summary>Expert: Collects matching documents in a range. Hook for optimization. /// Note that {@link #Next()} must be called once before this method is called /// for the first time. /// </summary> /// <param name="hc">The collector to which all matching documents are passed through /// {@link HitCollector#Collect(int, float)}. /// </param> /// <param name="max">Do not score documents past this. /// </param> /// <returns> true if more matching documents may remain. /// </returns> protected internal override bool Score(HitCollector hc, int max) { while (currentDoc < max) { hc.Collect(currentDoc, currentScore); if (!Next()) { return false; } } return true; }