本文整理汇总了C#中Lucene.Net.Index.IndexWriter.UpdateBinaryDocValue方法的典型用法代码示例。如果您正苦于以下问题:C# IndexWriter.UpdateBinaryDocValue方法的具体用法?C# IndexWriter.UpdateBinaryDocValue怎么用?C# IndexWriter.UpdateBinaryDocValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.IndexWriter
的用法示例。
在下文中一共展示了IndexWriter.UpdateBinaryDocValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestUpdateAndDeleteSameDocument
public virtual void TestUpdateAndDeleteSameDocument()
{
// update and delete same document in same commit session
Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
conf.SetMaxBufferedDocs(10); // control segment flushing
IndexWriter writer = new IndexWriter(dir, conf);
writer.AddDocument(Doc(0));
writer.AddDocument(Doc(1));
if (Random().NextBoolean())
{
writer.Commit();
}
writer.DeleteDocuments(new Term("id", "doc-0"));
writer.UpdateBinaryDocValue(new Term("id", "doc-0"), "val", ToBytes(17L));
DirectoryReader reader;
if (Random().NextBoolean()) // not NRT
{
writer.Dispose();
reader = DirectoryReader.Open(dir);
} // NRT
else
{
reader = DirectoryReader.Open(writer, true);
writer.Dispose();
}
AtomicReader r = (AtomicReader)reader.Leaves[0].Reader;
Assert.IsFalse(r.LiveDocs.Get(0));
Assert.AreEqual(1, GetValue(r.GetBinaryDocValues("val"), 0, new BytesRef())); // deletes are currently applied first
reader.Dispose();
dir.Dispose();
}
示例2: TestUpdatesAreFlushed
public virtual void TestUpdatesAreFlushed()
{
Directory dir = NewDirectory();
IndexWriter writer = new IndexWriter(dir, (IndexWriterConfig)NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false)).SetRAMBufferSizeMB(0.00000001));
writer.AddDocument(Doc(0)); // val=1
writer.AddDocument(Doc(1)); // val=2
writer.AddDocument(Doc(3)); // val=2
writer.Commit();
Assert.AreEqual(1, writer.FlushDeletesCount);
writer.UpdateBinaryDocValue(new Term("id", "doc-0"), "val", ToBytes(5));
Assert.AreEqual(2, writer.FlushDeletesCount);
writer.UpdateBinaryDocValue(new Term("id", "doc-1"), "val", ToBytes(6));
Assert.AreEqual(3, writer.FlushDeletesCount);
writer.UpdateBinaryDocValue(new Term("id", "doc-2"), "val", ToBytes(7));
Assert.AreEqual(4, writer.FlushDeletesCount);
writer.Config.SetRAMBufferSizeMB(1000d);
writer.UpdateBinaryDocValue(new Term("id", "doc-2"), "val", ToBytes(7));
Assert.AreEqual(4, writer.FlushDeletesCount);
writer.Dispose();
dir.Dispose();
}
示例3: TestUpdateBinaryDVFieldWithSameNameAsPostingField
public virtual void TestUpdateBinaryDVFieldWithSameNameAsPostingField()
{
// this used to fail because FieldInfos.Builder neglected to update
// globalFieldMaps.docValueTypes map
Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.Add(new StringField("f", "mock-value", Store.NO));
doc.Add(new BinaryDocValuesField("f", ToBytes(5L)));
writer.AddDocument(doc);
writer.Commit();
writer.UpdateBinaryDocValue(new Term("f", "mock-value"), "f", ToBytes(17L));
writer.Dispose();
DirectoryReader r = DirectoryReader.Open(dir);
BinaryDocValues bdv = ((AtomicReader)r.Leaves[0].Reader).GetBinaryDocValues("f");
Assert.AreEqual(17, GetValue(bdv, 0, new BytesRef()));
r.Dispose();
dir.Dispose();
}
示例4: TestUpdateSameDocMultipleTimes
public virtual void TestUpdateSameDocMultipleTimes()
{
Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.Add(new StringField("key", "doc", Store.NO));
doc.Add(new BinaryDocValuesField("bdv", ToBytes(5L)));
writer.AddDocument(doc); // flushed document
writer.Commit();
writer.AddDocument(doc); // in-memory document
writer.UpdateBinaryDocValue(new Term("key", "doc"), "bdv", ToBytes(17L)); // update existing field
writer.UpdateBinaryDocValue(new Term("key", "doc"), "bdv", ToBytes(3L)); // update existing field 2nd time in this commit
writer.Dispose();
DirectoryReader reader = DirectoryReader.Open(dir);
AtomicReader r = SlowCompositeReaderWrapper.Wrap(reader);
BinaryDocValues bdv = r.GetBinaryDocValues("bdv");
BytesRef scratch = new BytesRef();
for (int i = 0; i < r.MaxDoc; i++)
{
Assert.AreEqual(3, GetValue(bdv, i, scratch));
}
reader.Dispose();
dir.Dispose();
}
示例5: TestUpdateDocumentByMultipleTerms
public virtual void TestUpdateDocumentByMultipleTerms()
{
// make sure the order of updates is respected, even when multiple terms affect same document
Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.Add(new StringField("k1", "v1", Store.NO));
doc.Add(new StringField("k2", "v2", Store.NO));
doc.Add(new BinaryDocValuesField("bdv", ToBytes(5L)));
writer.AddDocument(doc); // flushed document
writer.Commit();
writer.AddDocument(doc); // in-memory document
writer.UpdateBinaryDocValue(new Term("k1", "v1"), "bdv", ToBytes(17L));
writer.UpdateBinaryDocValue(new Term("k2", "v2"), "bdv", ToBytes(3L));
writer.Dispose();
DirectoryReader reader = DirectoryReader.Open(dir);
AtomicReader r = SlowCompositeReaderWrapper.Wrap(reader);
BinaryDocValues bdv = r.GetBinaryDocValues("bdv");
BytesRef scratch = new BytesRef();
for (int i = 0; i < r.MaxDoc; i++)
{
Assert.AreEqual(3, GetValue(bdv, i, scratch));
}
reader.Dispose();
dir.Dispose();
}
示例6: TestDocumentWithNoValue
public virtual void TestDocumentWithNoValue()
{
Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
IndexWriter writer = new IndexWriter(dir, conf);
for (int i = 0; i < 2; i++)
{
Document doc = new Document();
doc.Add(new StringField("dvUpdateKey", "dv", Store.NO));
if (i == 0) // index only one document with value
{
doc.Add(new BinaryDocValuesField("bdv", ToBytes(5L)));
}
writer.AddDocument(doc);
}
writer.Commit();
// update all docs' bdv field
writer.UpdateBinaryDocValue(new Term("dvUpdateKey", "dv"), "bdv", ToBytes(17L));
writer.Dispose();
DirectoryReader reader = DirectoryReader.Open(dir);
AtomicReader r = (AtomicReader)reader.Leaves[0].Reader;
BinaryDocValues bdv = r.GetBinaryDocValues("bdv");
BytesRef scratch = new BytesRef();
for (int i = 0; i < r.MaxDoc; i++)
{
Assert.AreEqual(17, GetValue(bdv, i, scratch));
}
reader.Dispose();
dir.Dispose();
}
示例7: TestUpdateNonBinaryDocValuesField
public virtual void TestUpdateNonBinaryDocValuesField()
{
// we don't support adding new fields or updating existing non-binary-dv
// fields through binary updates
Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.Add(new StringField("key", "doc", Store.NO));
doc.Add(new StringField("foo", "bar", Store.NO));
writer.AddDocument(doc); // flushed document
writer.Commit();
writer.AddDocument(doc); // in-memory document
try
{
writer.UpdateBinaryDocValue(new Term("key", "doc"), "bdv", ToBytes(17L));
Assert.Fail("should not have allowed creating new fields through update");
}
catch (System.ArgumentException e)
{
// ok
}
try
{
writer.UpdateBinaryDocValue(new Term("key", "doc"), "foo", ToBytes(17L));
Assert.Fail("should not have allowed updating an existing field to binary-dv");
}
catch (System.ArgumentException e)
{
// ok
}
writer.Dispose();
dir.Dispose();
}
示例8: TestDeleteUnusedUpdatesFiles
public virtual void TestDeleteUnusedUpdatesFiles()
{
Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.Add(new StringField("id", "d0", Store.NO));
doc.Add(new BinaryDocValuesField("f", ToBytes(1L)));
writer.AddDocument(doc);
// create first gen of update files
writer.UpdateBinaryDocValue(new Term("id", "d0"), "f", ToBytes(2L));
writer.Commit();
int numFiles = dir.ListAll().Length;
DirectoryReader r = DirectoryReader.Open(dir);
BytesRef scratch = new BytesRef();
Assert.AreEqual(2L, GetValue(((AtomicReader)r.Leaves[0].Reader).GetBinaryDocValues("f"), 0, scratch));
r.Dispose();
// create second gen of update files, first gen should be deleted
writer.UpdateBinaryDocValue(new Term("id", "d0"), "f", ToBytes(5L));
writer.Commit();
Assert.AreEqual(numFiles, dir.ListAll().Length);
r = DirectoryReader.Open(dir);
Assert.AreEqual(5L, GetValue(((AtomicReader)r.Leaves[0].Reader).GetBinaryDocValues("f"), 0, scratch));
r.Dispose();
writer.Dispose();
dir.Dispose();
}
示例9: TestUpdateFewSegments
public virtual void TestUpdateFewSegments()
{
Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
conf.SetMaxBufferedDocs(2); // generate few segments
conf.SetMergePolicy(NoMergePolicy.COMPOUND_FILES); // prevent merges for this test
IndexWriter writer = new IndexWriter(dir, conf);
int numDocs = 10;
long[] expectedValues = new long[numDocs];
for (int i = 0; i < numDocs; i++)
{
writer.AddDocument(Doc(i));
expectedValues[i] = i + 1;
}
writer.Commit();
// update few docs
for (int i = 0; i < numDocs; i++)
{
if (Random().NextDouble() < 0.4)
{
long value = (i + 1) * 2;
writer.UpdateBinaryDocValue(new Term("id", "doc-" + i), "val", ToBytes(value));
expectedValues[i] = value;
}
}
DirectoryReader reader;
if (Random().NextBoolean()) // not NRT
{
writer.Dispose();
reader = DirectoryReader.Open(dir);
} // NRT
else
{
reader = DirectoryReader.Open(writer, true);
writer.Dispose();
}
BytesRef scratch = new BytesRef();
foreach (AtomicReaderContext context in reader.Leaves)
{
AtomicReader r = context.AtomicReader;
BinaryDocValues bdv = r.GetBinaryDocValues("val");
Assert.IsNotNull(bdv);
for (int i = 0; i < r.MaxDoc; i++)
{
long expected = expectedValues[i + context.DocBase];
long actual = GetValue(bdv, i, scratch);
Assert.AreEqual(expected, actual);
}
}
reader.Dispose();
dir.Dispose();
}
示例10: TestChangeCodec
public virtual void TestChangeCodec()
{
Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
conf.SetMergePolicy(NoMergePolicy.COMPOUND_FILES); // disable merges to simplify test assertions.
conf.SetCodec(new Lucene46CodecAnonymousInnerClassHelper2(this));
IndexWriter writer = new IndexWriter(dir, (IndexWriterConfig)conf.Clone());
Document doc = new Document();
doc.Add(new StringField("id", "d0", Store.NO));
doc.Add(new BinaryDocValuesField("f1", ToBytes(5L)));
doc.Add(new BinaryDocValuesField("f2", ToBytes(13L)));
writer.AddDocument(doc);
writer.Dispose();
// change format
conf.SetCodec(new Lucene46CodecAnonymousInnerClassHelper3(this));
writer = new IndexWriter(dir, (IndexWriterConfig)conf.Clone());
doc = new Document();
doc.Add(new StringField("id", "d1", Store.NO));
doc.Add(new BinaryDocValuesField("f1", ToBytes(17L)));
doc.Add(new BinaryDocValuesField("f2", ToBytes(2L)));
writer.AddDocument(doc);
writer.UpdateBinaryDocValue(new Term("id", "d0"), "f1", ToBytes(12L));
writer.Dispose();
DirectoryReader reader = DirectoryReader.Open(dir);
AtomicReader r = SlowCompositeReaderWrapper.Wrap(reader);
BinaryDocValues f1 = r.GetBinaryDocValues("f1");
BinaryDocValues f2 = r.GetBinaryDocValues("f2");
BytesRef scratch = new BytesRef();
Assert.AreEqual(12L, GetValue(f1, 0, scratch));
Assert.AreEqual(13L, GetValue(f2, 0, scratch));
Assert.AreEqual(17L, GetValue(f1, 1, scratch));
Assert.AreEqual(2L, GetValue(f2, 1, scratch));
reader.Dispose();
dir.Dispose();
}
示例11: TestAddIndexes
public virtual void TestAddIndexes()
{
Directory dir1 = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
IndexWriter writer = new IndexWriter(dir1, conf);
int numDocs = AtLeast(50);
int numTerms = TestUtil.NextInt(Random(), 1, numDocs / 5);
HashSet<string> randomTerms = new HashSet<string>();
while (randomTerms.Count < numTerms)
{
randomTerms.Add(TestUtil.RandomSimpleString(Random()));
}
// create first index
for (int i = 0; i < numDocs; i++)
{
Document doc = new Document();
doc.Add(new StringField("id", RandomInts.RandomFrom(Random(), randomTerms), Store.NO));
doc.Add(new BinaryDocValuesField("bdv", ToBytes(4L)));
doc.Add(new BinaryDocValuesField("control", ToBytes(8L)));
writer.AddDocument(doc);
}
if (Random().NextBoolean())
{
writer.Commit();
}
// update some docs to a random value
long value = Random().Next();
Term term = new Term("id", RandomInts.RandomFrom(Random(), randomTerms));
writer.UpdateBinaryDocValue(term, "bdv", ToBytes(value));
writer.UpdateBinaryDocValue(term, "control", ToBytes(value * 2));
writer.Dispose();
Directory dir2 = NewDirectory();
conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
writer = new IndexWriter(dir2, conf);
if (Random().NextBoolean())
{
writer.AddIndexes(dir1);
}
else
{
DirectoryReader reader = DirectoryReader.Open(dir1);
writer.AddIndexes(reader);
reader.Dispose();
}
writer.Dispose();
DirectoryReader reader_ = DirectoryReader.Open(dir2);
BytesRef scratch = new BytesRef();
foreach (AtomicReaderContext context in reader_.Leaves)
{
AtomicReader r = context.AtomicReader;
BinaryDocValues bdv = r.GetBinaryDocValues("bdv");
BinaryDocValues control = r.GetBinaryDocValues("control");
for (int i = 0; i < r.MaxDoc; i++)
{
Assert.AreEqual(GetValue(bdv, i, scratch) * 2, GetValue(control, i, scratch));
}
}
reader_.Dispose();
IOUtils.Close(dir1, dir2);
}
示例12: TestUpdateDifferentDocsInDifferentGens
public virtual void TestUpdateDifferentDocsInDifferentGens()
{
// update same document multiple times across generations
Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
conf.SetMaxBufferedDocs(4);
IndexWriter writer = new IndexWriter(dir, conf);
int numDocs = AtLeast(10);
for (int i = 0; i < numDocs; i++)
{
Document doc = new Document();
doc.Add(new StringField("id", "doc" + i, Store.NO));
long value = Random().Next();
doc.Add(new BinaryDocValuesField("f", ToBytes(value)));
doc.Add(new BinaryDocValuesField("cf", ToBytes(value * 2)));
writer.AddDocument(doc);
}
int numGens = AtLeast(5);
BytesRef scratch = new BytesRef();
for (int i = 0; i < numGens; i++)
{
int doc = Random().Next(numDocs);
Term t = new Term("id", "doc" + doc);
long value = Random().NextLong();
writer.UpdateBinaryDocValue(t, "f", ToBytes(value));
writer.UpdateBinaryDocValue(t, "cf", ToBytes(value * 2));
DirectoryReader reader = DirectoryReader.Open(writer, true);
foreach (AtomicReaderContext context in reader.Leaves)
{
AtomicReader r = context.AtomicReader;
BinaryDocValues fbdv = r.GetBinaryDocValues("f");
BinaryDocValues cfbdv = r.GetBinaryDocValues("cf");
for (int j = 0; j < r.MaxDoc; j++)
{
Assert.AreEqual(GetValue(cfbdv, j, scratch), GetValue(fbdv, j, scratch) * 2);
}
}
reader.Dispose();
}
writer.Dispose();
dir.Dispose();
}
示例13: TestSimple
public virtual void TestSimple()
{
Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
// make sure random config doesn't flush on us
conf.SetMaxBufferedDocs(10);
conf.SetRAMBufferSizeMB(IndexWriterConfig.DISABLE_AUTO_FLUSH);
IndexWriter writer = new IndexWriter(dir, conf);
writer.AddDocument(Doc(0)); // val=1
writer.AddDocument(Doc(1)); // val=2
if (Random().NextBoolean()) // randomly commit before the update is sent
{
writer.Commit();
}
writer.UpdateBinaryDocValue(new Term("id", "doc-0"), "val", ToBytes(2)); // doc=0, exp=2
DirectoryReader reader;
if (Random().NextBoolean()) // not NRT
{
writer.Dispose();
reader = DirectoryReader.Open(dir);
} // NRT
else
{
reader = DirectoryReader.Open(writer, true);
writer.Dispose();
}
Assert.AreEqual(1, reader.Leaves.Count);
AtomicReader r = (AtomicReader)reader.Leaves[0].Reader;
BinaryDocValues bdv = r.GetBinaryDocValues("val");
BytesRef scratch = new BytesRef();
Assert.AreEqual(2, GetValue(bdv, 0, scratch));
Assert.AreEqual(2, GetValue(bdv, 1, scratch));
reader.Dispose();
dir.Dispose();
}
示例14: TestUpdateOldSegments
public virtual void TestUpdateOldSegments()
{
Codec[] oldCodecs = new Codec[] { new Lucene40RWCodec(), new Lucene41RWCodec(), new Lucene42RWCodec(), new Lucene45RWCodec() };
Directory dir = NewDirectory();
bool oldValue = OLD_FORMAT_IMPERSONATION_IS_ACTIVE;
// create a segment with an old Codec
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
conf.SetCodec(oldCodecs[Random().Next(oldCodecs.Length)]);
OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true;
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.Add(new StringField("id", "doc", Store.NO));
doc.Add(new BinaryDocValuesField("f", ToBytes(5L)));
writer.AddDocument(doc);
writer.Dispose();
conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
writer = new IndexWriter(dir, conf);
writer.UpdateBinaryDocValue(new Term("id", "doc"), "f", ToBytes(4L));
OLD_FORMAT_IMPERSONATION_IS_ACTIVE = false;
try
{
writer.Dispose();
Assert.Fail("should not have succeeded to update a segment written with an old Codec");
}
catch (System.NotSupportedException e)
{
writer.Rollback();
}
finally
{
OLD_FORMAT_IMPERSONATION_IS_ACTIVE = oldValue;
}
dir.Dispose();
}
示例15: TestMultipleDocValuesTypes
public virtual void TestMultipleDocValuesTypes()
{
Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
conf.SetMaxBufferedDocs(10); // prevent merges
IndexWriter writer = new IndexWriter(dir, conf);
for (int i = 0; i < 4; i++)
{
Document doc = new Document();
doc.Add(new StringField("dvUpdateKey", "dv", Store.NO));
doc.Add(new NumericDocValuesField("ndv", i));
doc.Add(new BinaryDocValuesField("bdv", new BytesRef(Convert.ToString(i))));
doc.Add(new SortedDocValuesField("sdv", new BytesRef(Convert.ToString(i))));
doc.Add(new SortedSetDocValuesField("ssdv", new BytesRef(Convert.ToString(i))));
doc.Add(new SortedSetDocValuesField("ssdv", new BytesRef(Convert.ToString(i * 2))));
writer.AddDocument(doc);
}
writer.Commit();
// update all docs' bdv field
writer.UpdateBinaryDocValue(new Term("dvUpdateKey", "dv"), "bdv", ToBytes(17L));
writer.Dispose();
DirectoryReader reader = DirectoryReader.Open(dir);
AtomicReader r = (AtomicReader)reader.Leaves[0].Reader;
NumericDocValues ndv = r.GetNumericDocValues("ndv");
BinaryDocValues bdv = r.GetBinaryDocValues("bdv");
SortedDocValues sdv = r.GetSortedDocValues("sdv");
SortedSetDocValues ssdv = r.GetSortedSetDocValues("ssdv");
BytesRef scratch = new BytesRef();
for (int i = 0; i < r.MaxDoc; i++)
{
Assert.AreEqual(i, ndv.Get(i));
Assert.AreEqual(17, GetValue(bdv, i, scratch));
sdv.Get(i, scratch);
Assert.AreEqual(new BytesRef(Convert.ToString(i)), scratch);
ssdv.Document = i;
long ord = ssdv.NextOrd();
ssdv.LookupOrd(ord, scratch);
Assert.AreEqual(i, Convert.ToInt32(scratch.Utf8ToString()));
if (i != 0)
{
ord = ssdv.NextOrd();
ssdv.LookupOrd(ord, scratch);
Assert.AreEqual(i * 2, Convert.ToInt32(scratch.Utf8ToString()));
}
Assert.AreEqual(SortedSetDocValues.NO_MORE_ORDS, ssdv.NextOrd());
}
reader.Dispose();
dir.Dispose();
}