本文整理汇总了C#中Indexer.Refresh方法的典型用法代码示例。如果您正苦于以下问题:C# Indexer.Refresh方法的具体用法?C# Indexer.Refresh怎么用?C# Indexer.Refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Indexer
的用法示例。
在下文中一共展示了Indexer.Refresh方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IndexerTest
public void IndexerTest()
{
using (var indexer = new Indexer(this.Directory)) {
var guids = new List<Guid>();
guids.Add(IndexTest(indexer, TestDir + "Tika.rtf", "almonds"));
guids.Add(IndexTest(indexer, TestDir + "Tika.pdf", "almonds"));
guids.Add(IndexTest(indexer, TestDir + "Tika.docx", "almonds"));
guids.Add(IndexTest(indexer, TestDir + "Tika.odt", "almonds"));
guids.Add(IndexTest(indexer, TestDir + "Tika.pptx", "almonds"));
guids.Add(IndexTest(indexer, TestDir + "Tika.xlsx", "almonds"));
foreach (var guid in guids) {
indexer.Writer.DeleteDocuments(new Term("Id", guid.ToString()));
indexer.Refresh();
var docs = indexer.Searcher
.Search(new TermQuery(new Term(indexer.DocumentContentField, "almonds")), 1000)
#if LuceneV290
.scoreDocs
.Select(sd => indexer.Searcher.Doc(sd.doc))
#else
.ScoreDocs
.Select(sd => indexer.Searcher.Doc(sd.Doc))
#endif
.ToArray();
Assert.IsFalse(docs.Any(d => d.GetField("Id").AsString() == guid.ToString()));
}
}
}
示例2: IndexTest
public Guid IndexTest(Indexer indexer, string path, string contains)
{
contains = contains.ToLower();
var file = ReadFile(path);
var doc = indexer.CreateDocument(file.Item2);
doc.Add(new Field("Id", file.Item1.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
indexer.Writer.AddDocument(doc);
indexer.Writer.Commit();
indexer.Refresh();
var parser = new QueryParser(indexer.Version, indexer.DocumentContentField, indexer.Analyser);
var query = parser.Parse(contains);
var topDocs = indexer.Searcher.Search(query, 1000);
//topDocs = indexer.Searcher.Search(query, topDocs.totalHits);
var docs = topDocs
#if LuceneV290
.scoreDocs
.Select(sd => indexer.Searcher.Doc(sd.doc))
#else
.ScoreDocs
.Select(sd => indexer.Searcher.Doc(sd.Doc))
#endif
.ToArray();
Assert.IsTrue(docs.Any(d => d.GetField("Id").AsString() == file.Item1.ToString()));
return file.Item1;
}