public virtual void AssertContainsDocId(System.String msg, DocIdSet docIdSet, int docId) { DocIdSetIterator it = docIdSet.Iterator(null); Assert.IsTrue(it.Advance(docId, null) != DocIdSetIterator.NO_MORE_DOCS, msg); Assert.IsTrue(it.DocID() == docId, msg); }
/// <summary> Implementation of the contract to build a DocIdSetIterator.</summary> /// <seealso cref="DocIdSetIterator"> /// </seealso> /// <seealso cref="FilteredDocIdSetIterator"> /// </seealso> // @Override public override DocIdSetIterator Iterator() { return(new FilteredDocIdSetIterator(_innerSet.Iterator(), (docid) => { return this.Match(docid); })); }
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); } } }
internal virtual int GetDocIdSetSize(DocIdSet docIdSet) { int size = 0; DocIdSetIterator it = docIdSet.Iterator(); while (it.NextDoc() != DocIdSetIterator.NO_MORE_DOCS) { size++; } return size; }
/// <summary> /// Presents an Ienumerable version of the DocIdSet Iterator /// </summary> /// <param name="set"></param> /// <returns></returns> public static IEnumerable <int> AsEnumerable(this DocIdSet set) { var disi = set.Iterator(); int doc; while ((doc = disi.NextDoc()) < Int32.MaxValue) { yield return(doc); } }
private HashSet<int> DocIdSetToHashSet(DocIdSet docs) { var result = new HashSet<int>(); var iterator = docs.Iterator(); int docId; while ((docId = iterator.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS) result.Add(docId); return result; }
internal virtual int GetDocIdSetSize(DocIdSet docIdSet) { int size = 0; DocIdSetIterator it = docIdSet.Iterator(null); while (it.NextDoc(null) != DocIdSetIterator.NO_MORE_DOCS) { size++; } return(size); }
/// <summary>Provide the DocIdSet to be cached, using the DocIdSet provided /// by the wrapped Filter. /// This implementation returns the given DocIdSet. /// </summary> protected internal virtual DocIdSet DocIdSetToCache(DocIdSet docIdSet, IndexReader reader) { if (docIdSet.IsCacheable()) { return(docIdSet); } else { DocIdSetIterator it = docIdSet.Iterator(); // null is allowed to be returned by iterator(), // in this case we wrap with the empty set, // which is cacheable. return((it == null) ? DocIdSet.EMPTY_DOCIDSET : new OpenBitSetDISI(it, reader.MaxDoc())); } }
/// <summary>Provide the DocIdSet to be cached, using the DocIdSet provided /// by the wrapped Filter. /// This implementation returns the given DocIdSet. /// </summary> protected internal virtual DocIdSet DocIdSetToCache(DocIdSet docIdSet, IndexReader reader, IState state) { if (docIdSet == null) { // this is better than returning null, as the nonnull result can be cached return(DocIdSet.EMPTY_DOCIDSET); } else if (docIdSet.IsCacheable) { return(docIdSet); } else { DocIdSetIterator it = docIdSet.Iterator(state); // null is allowed to be returned by iterator(), // in this case we wrap with the empty set, // which is cacheable. return((it == null) ? DocIdSet.EMPTY_DOCIDSET : new OpenBitSetDISI(it, reader.MaxDoc, state)); } }
// return a filtering scorer public override Scorer Scorer(IndexReader indexReader, bool scoreDocsInOrder, bool topScorer) { Scorer scorer = weight.Scorer(indexReader, true, false); if (scorer == null) { return(null); } DocIdSet docIdSet = Enclosing_Instance.filter.GetDocIdSet(indexReader); if (docIdSet == null) { return(null); } DocIdSetIterator docIdSetIterator = docIdSet.Iterator(); if (docIdSetIterator == null) { return(null); } return(new AnonymousClassScorer(scorer, docIdSetIterator, this, similarity)); }
public ConstantScorer(ConstantScoreQuery enclosingInstance, Similarity similarity, IndexReader reader, Weight w, IState state) : base(similarity) { InitBlock(enclosingInstance); theScore = w.Value; DocIdSet docIdSet = Enclosing_Instance.internalFilter.GetDocIdSet(reader, state); if (docIdSet == null) { docIdSetIterator = DocIdSet.EMPTY_DOCIDSET.Iterator(state); } else { DocIdSetIterator iter = docIdSet.Iterator(state); if (iter == null) { docIdSetIterator = DocIdSet.EMPTY_DOCIDSET.Iterator(state); } else { docIdSetIterator = iter; } } }
/// <summary>Provide the DocIdSet to be cached, using the DocIdSet provided /// by the wrapped Filter. /// This implementation returns the given DocIdSet. /// </summary> protected internal virtual DocIdSet DocIdSetToCache(DocIdSet docIdSet, IndexReader reader) { if (docIdSet.IsCacheable()) { return docIdSet; } else { DocIdSetIterator it = docIdSet.Iterator(); // null is allowed to be returned by iterator(), // in this case we wrap with the empty set, // which is cacheable. return (it == null) ? DocIdSet.EMPTY_DOCIDSET : new OpenBitSetDISI(it, reader.MaxDoc()); } }
public override Explanation Explain(IndexReader ir, int i) { Explanation inner = weight.Explain(ir, i); if (Enclosing_Instance.GetBoost() != 1) { Explanation preBoost = inner; inner = new Explanation(inner.GetValue() * Enclosing_Instance.GetBoost(), "product of:"); inner.AddDetail(new Explanation(Enclosing_Instance.GetBoost(), "boost")); inner.AddDetail(preBoost); } Filter f = Enclosing_Instance.filter; DocIdSet docIdSet = f.GetDocIdSet(ir); DocIdSetIterator docIdSetIterator = docIdSet == null?DocIdSet.EMPTY_DOCIDSET.Iterator() : docIdSet.Iterator(); if (docIdSetIterator == null) { docIdSetIterator = DocIdSet.EMPTY_DOCIDSET.Iterator(); } if (docIdSetIterator.Advance(i) == i) { return(inner); } else { Explanation result = new Explanation(0.0f, "failure to match filter: " + f.ToString()); result.AddDetail(inner); return(result); } }
private static long CalculateFacetCount(DocIdSet baseBitSet, DocIdSet filterDocSet) { var baseDisi = new OpenBitSetDISI(baseBitSet.Iterator(), 25000); var filterIterator = filterDocSet.Iterator(); baseDisi.InPlaceAnd(filterIterator); var total = baseDisi.Cardinality(); return total; }
/// <summary> Implementation of the contract to build a DocIdSetIterator.</summary> /// <seealso cref="DocIdSetIterator"> /// </seealso> /// <seealso cref="FilteredDocIdSetIterator"> /// </seealso> // @Override public override DocIdSetIterator Iterator(IState state) { return(new AnonymousClassFilteredDocIdSetIterator(this, _innerSet.Iterator(state))); }
public virtual void AssertContainsDocId(System.String msg, DocIdSet docIdSet, int docId) { DocIdSetIterator it = docIdSet.Iterator(); Assert.IsTrue(it.Advance(docId) != DocIdSetIterator.NO_MORE_DOCS, msg); Assert.IsTrue(it.DocID() == docId, msg); }
private void doChain(OpenBitSetDISI result, int logic, DocIdSet dis) { if (dis is OpenBitSet) { // optimized case for OpenBitSets switch (logic) { case OR: result.Or((OpenBitSet)dis); break; case AND: result.And((OpenBitSet)dis); break; case ANDNOT: result.AndNot((OpenBitSet)dis); break; case XOR: result.Xor((OpenBitSet)dis); break; default: doChain(result, DEFAULT, dis); break; } } else { DocIdSetIterator disi; if (dis == null) { disi = DocIdSet.EMPTY_DOCIDSET.Iterator(); } else { disi = dis.Iterator(); if (disi == null) { disi = DocIdSet.EMPTY_DOCIDSET.Iterator(); } } switch (logic) { case OR: result.InPlaceOr(disi); break; case AND: result.InPlaceAnd(disi); break; case ANDNOT: result.InPlaceNot(disi); break; case XOR: result.InPlaceXor(disi); break; default: doChain(result, DEFAULT, dis); break; } } }
public DocsetQuery(DocIdSet docSet) : this(docSet.Iterator()) { }