public virtual void TestSimple() { Directory dir = NewDirectory(); RandomIndexWriter w = new RandomIndexWriter(Random, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMergePolicy(NewLogMergePolicy())); Document doc = new Document(); Field field = NewTextField("field", "", Field.Store.NO); doc.Add(field); field.SetStringValue("a b c"); w.AddDocument(doc); field.SetStringValue("d e f"); w.AddDocument(doc); field.SetStringValue("a f"); w.AddDocument(doc); IndexReader r = w.GetReader(); w.Dispose(); AtomicReader ar = SlowCompositeReaderWrapper.Wrap(r); DocTermOrds dto = new DocTermOrds(ar, ar.LiveDocs, "field"); SortedSetDocValues iter = dto.GetIterator(ar); iter.SetDocument(0); Assert.AreEqual(0, iter.NextOrd()); Assert.AreEqual(1, iter.NextOrd()); Assert.AreEqual(2, iter.NextOrd()); Assert.AreEqual(SortedSetDocValues.NO_MORE_ORDS, iter.NextOrd()); iter.SetDocument(1); Assert.AreEqual(3, iter.NextOrd()); Assert.AreEqual(4, iter.NextOrd()); Assert.AreEqual(5, iter.NextOrd()); Assert.AreEqual(SortedSetDocValues.NO_MORE_ORDS, iter.NextOrd()); iter.SetDocument(2); Assert.AreEqual(0, iter.NextOrd()); Assert.AreEqual(5, iter.NextOrd()); Assert.AreEqual(SortedSetDocValues.NO_MORE_ORDS, iter.NextOrd()); r.Dispose(); dir.Dispose(); }
public virtual void TestSimple() { Directory dir = NewDirectory(); RandomIndexWriter w = new RandomIndexWriter(Random(), dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMergePolicy(NewLogMergePolicy())); Document doc = new Document(); Field field = NewTextField("field", "", Field.Store.NO); doc.Add(field); field.StringValue = "a b c"; w.AddDocument(doc); field.StringValue = "d e f"; w.AddDocument(doc); field.StringValue = "a f"; w.AddDocument(doc); IndexReader r = w.Reader; w.Dispose(); AtomicReader ar = SlowCompositeReaderWrapper.Wrap(r); DocTermOrds dto = new DocTermOrds(ar, ar.LiveDocs, "field"); SortedSetDocValues iter = dto.GetIterator(ar); iter.Document = 0; Assert.AreEqual(0, iter.NextOrd()); Assert.AreEqual(1, iter.NextOrd()); Assert.AreEqual(2, iter.NextOrd()); Assert.AreEqual(SortedSetDocValues.NO_MORE_ORDS, iter.NextOrd()); iter.Document = 1; Assert.AreEqual(3, iter.NextOrd()); Assert.AreEqual(4, iter.NextOrd()); Assert.AreEqual(5, iter.NextOrd()); Assert.AreEqual(SortedSetDocValues.NO_MORE_ORDS, iter.NextOrd()); iter.Document = 2; Assert.AreEqual(0, iter.NextOrd()); Assert.AreEqual(5, iter.NextOrd()); Assert.AreEqual(SortedSetDocValues.NO_MORE_ORDS, iter.NextOrd()); r.Dispose(); dir.Dispose(); }
private void Verify(AtomicReader r, int[][] idToOrds, BytesRef[] termsArray, BytesRef prefixRef) { DocTermOrds dto = new DocTermOrds(r, r.LiveDocs, "field", prefixRef, int.MaxValue, TestUtil.NextInt32(Random, 2, 10)); FieldCache.Int32s docIDToID = FieldCache.DEFAULT.GetInt32s(r, "id", false); /* * for(int docID=0;docID<subR.MaxDoc;docID++) { * System.out.println(" docID=" + docID + " id=" + docIDToID[docID]); * } */ if (VERBOSE) { Console.WriteLine("TEST: verify prefix=" + (prefixRef == null ? "null" : prefixRef.Utf8ToString())); Console.WriteLine("TEST: all TERMS:"); TermsEnum allTE = MultiFields.GetTerms(r, "field").GetIterator(null); int ord = 0; while (allTE.Next() != null) { Console.WriteLine(" ord=" + (ord++) + " term=" + allTE.Term.Utf8ToString()); } } //final TermsEnum te = subR.Fields.Terms("field").iterator(); TermsEnum te = dto.GetOrdTermsEnum(r); if (dto.NumTerms == 0) { if (prefixRef == null) { Assert.IsNull(MultiFields.GetTerms(r, "field")); } else { Terms terms = MultiFields.GetTerms(r, "field"); if (terms != null) { TermsEnum termsEnum = terms.GetIterator(null); TermsEnum.SeekStatus result = termsEnum.SeekCeil(prefixRef); if (result != TermsEnum.SeekStatus.END) { Assert.IsFalse(StringHelper.StartsWith(termsEnum.Term, prefixRef), "term=" + termsEnum.Term.Utf8ToString() + " matches prefix=" + prefixRef.Utf8ToString()); } else { // ok } } else { // ok } } return; } if (VERBOSE) { Console.WriteLine("TEST: TERMS:"); te.SeekExact(0); while (true) { Console.WriteLine(" ord=" + te.Ord + " term=" + te.Term.Utf8ToString()); if (te.Next() == null) { break; } } } SortedSetDocValues iter = dto.GetIterator(r); for (int docID = 0; docID < r.MaxDoc; docID++) { if (VERBOSE) { Console.WriteLine("TEST: docID=" + docID + " of " + r.MaxDoc + " (id=" + docIDToID.Get(docID) + ")"); } iter.SetDocument(docID); int[] answers = idToOrds[docIDToID.Get(docID)]; int upto = 0; long ord; while ((ord = iter.NextOrd()) != SortedSetDocValues.NO_MORE_ORDS) { te.SeekExact(ord); BytesRef expected = termsArray[answers[upto++]]; if (VERBOSE) { Console.WriteLine(" exp=" + expected.Utf8ToString() + " actual=" + te.Term.Utf8ToString()); } Assert.AreEqual(expected, te.Term, "expected=" + expected.Utf8ToString() + " actual=" + te.Term.Utf8ToString() + " ord=" + ord); } Assert.AreEqual(answers.Length, upto); } }
private void Verify(AtomicReader r, int[][] idToOrds, BytesRef[] termsArray, BytesRef prefixRef) { DocTermOrds dto = new DocTermOrds(r, r.LiveDocs, "field", prefixRef, int.MaxValue, TestUtil.NextInt(Random(), 2, 10)); FieldCache.Ints docIDToID = FieldCache.DEFAULT.GetInts(r, "id", false); /* for(int docID=0;docID<subR.MaxDoc;docID++) { System.out.println(" docID=" + docID + " id=" + docIDToID[docID]); } */ if (VERBOSE) { Console.WriteLine("TEST: verify prefix=" + (prefixRef == null ? "null" : prefixRef.Utf8ToString())); Console.WriteLine("TEST: all TERMS:"); TermsEnum allTE = MultiFields.GetTerms(r, "field").Iterator(null); int ord = 0; while (allTE.Next() != null) { Console.WriteLine(" ord=" + (ord++) + " term=" + allTE.Term().Utf8ToString()); } } //final TermsEnum te = subR.Fields.Terms("field").iterator(); TermsEnum te = dto.GetOrdTermsEnum(r); if (dto.NumTerms() == 0) { if (prefixRef == null) { Assert.IsNull(MultiFields.GetTerms(r, "field")); } else { Terms terms = MultiFields.GetTerms(r, "field"); if (terms != null) { TermsEnum termsEnum = terms.Iterator(null); TermsEnum.SeekStatus result = termsEnum.SeekCeil(prefixRef); if (result != TermsEnum.SeekStatus.END) { Assert.IsFalse(StringHelper.StartsWith(termsEnum.Term(), prefixRef), "term=" + termsEnum.Term().Utf8ToString() + " matches prefix=" + prefixRef.Utf8ToString()); } else { // ok } } else { // ok } } return; } if (VERBOSE) { Console.WriteLine("TEST: TERMS:"); te.SeekExact(0); while (true) { Console.WriteLine(" ord=" + te.Ord() + " term=" + te.Term().Utf8ToString()); if (te.Next() == null) { break; } } } SortedSetDocValues iter = dto.GetIterator(r); for (int docID = 0; docID < r.MaxDoc; docID++) { if (VERBOSE) { Console.WriteLine("TEST: docID=" + docID + " of " + r.MaxDoc + " (id=" + docIDToID.Get(docID) + ")"); } iter.Document = docID; int[] answers = idToOrds[docIDToID.Get(docID)]; int upto = 0; long ord; while ((ord = iter.NextOrd()) != SortedSetDocValues.NO_MORE_ORDS) { te.SeekExact(ord); BytesRef expected = termsArray[answers[upto++]]; if (VERBOSE) { Console.WriteLine(" exp=" + expected.Utf8ToString() + " actual=" + te.Term().Utf8ToString()); } Assert.AreEqual(expected, te.Term(), "expected=" + expected.Utf8ToString() + " actual=" + te.Term().Utf8ToString() + " ord=" + ord); } Assert.AreEqual(answers.Length, upto); } }