本文整理汇总了C#中Lucene.Net.Documents.Document.RemoveField方法的典型用法代码示例。如果您正苦于以下问题:C# Document.RemoveField方法的具体用法?C# Document.RemoveField怎么用?C# Document.RemoveField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Documents.Document
的用法示例。
在下文中一共展示了Document.RemoveField方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBinaryField
public virtual void TestBinaryField()
{
Document doc = new Document();
IFieldable stringFld = new Field("string", binaryVal, Field.Store.YES, Field.Index.NO);
IFieldable binaryFld = new Field("binary", System.Text.UTF8Encoding.UTF8.GetBytes(binaryVal), Field.Store.YES);
IFieldable binaryFld2 = new Field("binary", System.Text.UTF8Encoding.UTF8.GetBytes(binaryVal2), Field.Store.YES);
doc.Add(stringFld);
doc.Add(binaryFld);
Assert.AreEqual(2, doc.fields_ForNUnit.Count);
Assert.IsTrue(binaryFld.IsBinary);
Assert.IsTrue(binaryFld.IsStored);
Assert.IsFalse(binaryFld.IsIndexed);
Assert.IsFalse(binaryFld.IsTokenized);
System.String binaryTest = new System.String(System.Text.UTF8Encoding.UTF8.GetChars(doc.GetBinaryValue("binary")));
Assert.IsTrue(binaryTest.Equals(binaryVal));
System.String stringTest = doc.Get("string");
Assert.IsTrue(binaryTest.Equals(stringTest));
doc.Add(binaryFld2);
Assert.AreEqual(3, doc.fields_ForNUnit.Count);
byte[][] binaryTests = doc.GetBinaryValues("binary");
Assert.AreEqual(2, binaryTests.Length);
binaryTest = new System.String(System.Text.UTF8Encoding.UTF8.GetChars(binaryTests[0]));
System.String binaryTest2 = new System.String(System.Text.UTF8Encoding.UTF8.GetChars(binaryTests[1]));
Assert.IsFalse(binaryTest.Equals(binaryTest2));
Assert.IsTrue(binaryTest.Equals(binaryVal));
Assert.IsTrue(binaryTest2.Equals(binaryVal2));
doc.RemoveField("string");
Assert.AreEqual(2, doc.fields_ForNUnit.Count);
doc.RemoveFields("binary");
Assert.AreEqual(0, doc.fields_ForNUnit.Count);
}
示例2: TestSegmentMerges
public virtual void TestSegmentMerges()
{
Directory dir = NewDirectory();
Random random = Random();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random));
IndexWriter writer = new IndexWriter(dir, (IndexWriterConfig)conf.Clone());
int docid = 0;
int numRounds = AtLeast(10);
for (int rnd = 0; rnd < numRounds; rnd++)
{
Document doc = new Document();
doc.Add(new StringField("key", "doc", Store.NO));
doc.Add(new BinaryDocValuesField("bdv", ToBytes(-1)));
int numDocs = AtLeast(30);
for (int i = 0; i < numDocs; i++)
{
doc.RemoveField("id");
doc.Add(new StringField("id", Convert.ToString(docid++), Store.NO));
writer.AddDocument(doc);
}
long value = rnd + 1;
writer.UpdateBinaryDocValue(new Term("key", "doc"), "bdv", ToBytes(value));
if (random.NextDouble() < 0.2) // randomly delete some docs
{
writer.DeleteDocuments(new Term("id", Convert.ToString(random.Next(docid))));
}
// randomly commit or reopen-IW (or nothing), before forceMerge
if (random.NextDouble() < 0.4)
{
writer.Commit();
}
else if (random.NextDouble() < 0.1)
{
writer.Dispose();
writer = new IndexWriter(dir, (IndexWriterConfig)conf.Clone());
}
// add another document with the current value, to be sure forceMerge has
// something to merge (for instance, it could be that CMS finished merging
// all segments down to 1 before the delete was applied, so when
// forceMerge is called, the index will be with one segment and deletes
// and some MPs might now merge it, thereby invalidating test's
// assumption that the reader has no deletes).
doc = new Document();
doc.Add(new StringField("id", Convert.ToString(docid++), Store.NO));
doc.Add(new StringField("key", "doc", Store.NO));
doc.Add(new BinaryDocValuesField("bdv", ToBytes(value)));
writer.AddDocument(doc);
writer.ForceMerge(1, true);
DirectoryReader reader;
if (random.NextBoolean())
{
writer.Commit();
reader = DirectoryReader.Open(dir);
}
else
{
reader = DirectoryReader.Open(writer, true);
}
Assert.AreEqual(1, reader.Leaves.Count);
AtomicReader r = (AtomicReader)reader.Leaves[0].Reader;
Assert.IsNull(r.LiveDocs, "index should have no deletes after forceMerge");
BinaryDocValues bdv = r.GetBinaryDocValues("bdv");
Assert.IsNotNull(bdv);
BytesRef scratch = new BytesRef();
for (int i = 0; i < r.MaxDoc; i++)
{
Assert.AreEqual(value, GetValue(bdv, i, scratch));
}
reader.Dispose();
}
writer.Dispose();
dir.Dispose();
}
示例3: Should_Throw_SearchException_When_Field_Is_Missing
public void Should_Throw_SearchException_When_Field_Is_Missing(string fieldName)
{
// Arrange
LuceneDocument document = new LuceneDocument();
document.Add(CreateField("id", "123"));
document.Add(CreateField("title", "the title"));
document.Add(CreateField("contentsummary", "the summary"));
document.Add(CreateField("tags", "tag1 tag2"));
document.Add(CreateField("createdby", "gandhi"));
document.Add(CreateField("contentlength", "999"));
document.Add(CreateField("createdon", DateTime.Today.ToString()));
document.RemoveField(fieldName);
ScoreDoc scoreDoc = new ScoreDoc(0, 1f);
// Act + Assert
SearchResultViewModel model = new SearchResultViewModel(document, scoreDoc);
}