public override SpanFilterResult BitSpans(IndexReader reader) { OpenBitSet bits = new OpenBitSet(reader.MaxDoc); Lucene.Net.Search.Spans.Spans spans = internalQuery.GetSpans(reader); IList<SpanFilterResult.PositionInfo> tmp = new List<SpanFilterResult.PositionInfo>(20); int currentDoc = - 1; SpanFilterResult.PositionInfo currentInfo = null; while (spans.Next()) { int doc = spans.Doc(); bits.Set(doc); if (currentDoc != doc) { currentInfo = new SpanFilterResult.PositionInfo(doc); tmp.Add(currentInfo); currentDoc = doc; } currentInfo.AddPosition(spans.Start(), spans.End()); } return new SpanFilterResult(bits, tmp); }
public virtual void TestFilterWorks() { Directory dir = new RAMDirectory(); IndexWriter writer = new IndexWriter(dir, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED, null); for (int i = 0; i < 500; i++) { Document document = new Document(); document.Add(new Field("field", English.IntToEnglish(i) + " equals " + English.IntToEnglish(i), Field.Store.NO, Field.Index.ANALYZED)); writer.AddDocument(document, null); } writer.Close(); IndexReader reader = IndexReader.Open(dir, true, null); SpanTermQuery query = new SpanTermQuery(new Term("field", English.IntToEnglish(10).Trim())); SpanQueryFilter filter = new SpanQueryFilter(query); SpanFilterResult result = filter.BitSpans(reader, null); DocIdSet docIdSet = result.DocIdSet; Assert.IsTrue(docIdSet != null, "docIdSet is null and it shouldn't be"); AssertContainsDocId("docIdSet doesn't contain docId 10", docIdSet, 10); var spans = result.Positions; Assert.IsTrue(spans != null, "spans is null and it shouldn't be"); int size = GetDocIdSetSize(docIdSet); Assert.IsTrue(spans.Count == size, "spans Size: " + spans.Count + " is not: " + size); for (System.Collections.IEnumerator iterator = spans.GetEnumerator(); iterator.MoveNext();) { SpanFilterResult.PositionInfo info = (SpanFilterResult.PositionInfo)iterator.Current; Assert.IsTrue(info != null, "info is null and it shouldn't be"); //The doc should indicate the bit is on AssertContainsDocId("docIdSet doesn't contain docId " + info.Doc, docIdSet, info.Doc); //There should be two positions in each Assert.IsTrue(info.Positions.Count == 2, "info.getPositions() Size: " + info.Positions.Count + " is not: " + 2); } reader.Close(); }
public override SpanFilterResult BitSpans(IndexReader reader) { System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0 ? reader.MaxDoc() / 64 : reader.MaxDoc() / 64 + 1) * 64); Lucene.Net.Search.Spans.Spans spans = query.GetSpans(reader); System.Collections.IList tmp = new System.Collections.ArrayList(20); int currentDoc = -1; SpanFilterResult.PositionInfo currentInfo = null; while (spans.Next()) { int doc = spans.Doc(); bits.Set(doc, true); if (currentDoc != doc) { currentInfo = new SpanFilterResult.PositionInfo(doc); tmp.Add(currentInfo); currentDoc = doc; } currentInfo.AddPosition(spans.Start(), spans.End()); } return(new SpanFilterResult(bits, tmp)); }
public override SpanFilterResult BitSpans(IndexReader reader) { System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0 ? reader.MaxDoc() / 64 : reader.MaxDoc() / 64 + 1) * 64); Lucene.Net.Search.Spans.Spans spans = query.GetSpans(reader); System.Collections.IList tmp = new System.Collections.ArrayList(20); int currentDoc = - 1; SpanFilterResult.PositionInfo currentInfo = null; while (spans.Next()) { int doc = spans.Doc(); bits.Set(doc, true); if (currentDoc != doc) { currentInfo = new SpanFilterResult.PositionInfo(doc); tmp.Add(currentInfo); currentDoc = doc; } currentInfo.AddPosition(spans.Start(), spans.End()); } return new SpanFilterResult(bits, tmp); }
public override SpanFilterResult BitSpans(IndexReader reader, IState state) { OpenBitSet bits = new OpenBitSet(reader.MaxDoc); Lucene.Net.Search.Spans.Spans spans = internalQuery.GetSpans(reader, state); IList <SpanFilterResult.PositionInfo> tmp = new List <SpanFilterResult.PositionInfo>(20); int currentDoc = -1; SpanFilterResult.PositionInfo currentInfo = null; while (spans.Next(state)) { int doc = spans.Doc(); bits.Set(doc); if (currentDoc != doc) { currentInfo = new SpanFilterResult.PositionInfo(doc); tmp.Add(currentInfo); currentDoc = doc; } currentInfo.AddPosition(spans.Start(), spans.End()); } return(new SpanFilterResult(bits, tmp)); }