Beispiel #1
0
 public virtual void TestMixupMultiValued()
 {
     Directory dir = NewDirectory();
     RandomIndexWriter writer = new RandomIndexWriter(Random(), dir);
     Document doc = new Document();
     Field field = new TextField("field", "", Field.Store.NO);
     TokenStream ts = new MockTokenizer(new StringReader("here we go"), MockTokenizer.WHITESPACE, true);
     Assert.IsFalse(ts.HasAttribute<PayloadAttribute>());
     field.TokenStream = ts;
     doc.Add(field);
     Field field2 = new TextField("field", "", Field.Store.NO);
     Token withPayload = new Token("withPayload", 0, 11);
     withPayload.Payload = new BytesRef("test");
     ts = new CannedTokenStream(withPayload);
     Assert.IsTrue(ts.HasAttribute<IPayloadAttribute>());
     field2.TokenStream = ts;
     doc.Add(field2);
     Field field3 = new TextField("field", "", Field.Store.NO);
     ts = new MockTokenizer(new StringReader("nopayload"), MockTokenizer.WHITESPACE, true);
     Assert.IsFalse(ts.HasAttribute<PayloadAttribute>());
     field3.TokenStream = ts;
     doc.Add(field3);
     writer.AddDocument(doc);
     DirectoryReader reader = writer.Reader;
     SegmentReader sr = GetOnlySegmentReader(reader);
     DocsAndPositionsEnum de = sr.TermPositionsEnum(new Term("field", "withPayload"));
     de.NextDoc();
     de.NextPosition();
     Assert.AreEqual(new BytesRef("test"), de.Payload);
     writer.Dispose();
     reader.Dispose();
     dir.Dispose();
 }
Beispiel #2
0
 public virtual void TestMixupDocs()
 {
     Directory dir = NewDirectory();
     IndexWriterConfig iwc = NewIndexWriterConfig(TEST_VERSION_CURRENT, null);
     iwc.SetMergePolicy(NewLogMergePolicy());
     RandomIndexWriter writer = new RandomIndexWriter(Random(), dir, iwc);
     Document doc = new Document();
     Field field = new TextField("field", "", Field.Store.NO);
     TokenStream ts = new MockTokenizer(new StringReader("here we go"), MockTokenizer.WHITESPACE, true);
     Assert.IsFalse(ts.HasAttribute<PayloadAttribute>());
     field.TokenStream = ts;
     doc.Add(field);
     writer.AddDocument(doc);
     Token withPayload = new Token("withPayload", 0, 11);
     withPayload.Payload = new BytesRef("test");
     ts = new CannedTokenStream(withPayload);
     Assert.IsTrue(ts.HasAttribute<IPayloadAttribute>());
     field.TokenStream = ts;
     writer.AddDocument(doc);
     ts = new MockTokenizer(new StringReader("another"), MockTokenizer.WHITESPACE, true);
     Assert.IsFalse(ts.HasAttribute<PayloadAttribute>());
     field.TokenStream = ts;
     writer.AddDocument(doc);
     DirectoryReader reader = writer.Reader;
     AtomicReader sr = SlowCompositeReaderWrapper.Wrap(reader);
     DocsAndPositionsEnum de = sr.TermPositionsEnum(new Term("field", "withPayload"));
     de.NextDoc();
     de.NextPosition();
     Assert.AreEqual(new BytesRef("test"), de.Payload);
     writer.Dispose();
     reader.Dispose();
     dir.Dispose();
 }