本文整理汇总了C#中Lucene.Net.Search.IndexSearcher.Query方法的典型用法代码示例。如果您正苦于以下问题:C# IndexSearcher.Query方法的具体用法?C# IndexSearcher.Query怎么用?C# IndexSearcher.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Search.IndexSearcher
的用法示例。
在下文中一共展示了IndexSearcher.Query方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// Initialize Everything
// ----------------------------------------------------------------
var watch = new Stopwatch();
var writer = GetWriter();
var analyzer = new StandardAnalyzer(Version.LUCENE_29);
var query = new TermQuery(new Term("PropString", "teststring"));
int iteratorCount;
IndexReader reader;
IndexSearcher searcher;
List<TestClass1> testObjects;
List<TestClass1> objectResults;
List<Document> documentResults;
List<long> Times = new List<long>();
// Create Test Objects
// ----------------------------------------------------------------
testObjects = new List<TestClass1>();
for (int i = 0; i < ObjectCount; i++)
{
testObjects.Add(new TestClass1(i));
}
// Test speed of writes
// ----------------------------------------------------------------
watch.Reset();
watch.Start();
writer.Write(testObjects.Take(1), analyzer);
watch.Stop();
Console.WriteLine("First Write: {0}ms", watch.ElapsedMilliseconds);
iteratorCount = IteratorCount;
while (iteratorCount-- > 0)
{
watch.Reset();
watch.Start();
writer.Write(testObjects, analyzer);
watch.Stop();
Times.Add(watch.ElapsedMilliseconds);
//Console.WriteLine("{0} Objects Written in {1}ms and {2:#,#} ticks", ObjectCount, watch.ElapsedMilliseconds, watch.ElapsedTicks);
}
Console.WriteLine("Average After Cached: {0}ms", Times.Skip(1).Average());
Times.Clear();
reader = writer.GetReader();
searcher = new IndexSearcher(reader);
// Test speed of reads
// ----------------------------------------------------------------
iteratorCount = IteratorCount;
while (iteratorCount-- > 0)
{
watch.Reset();
watch.Start();
objectResults = searcher.Query<TestClass1>(query, ObjectCount).ToList();
watch.Stop();
Times.Add(watch.ElapsedMilliseconds);
//Console.WriteLine("{0} Objects Read in {1}ms and {2:#,#} ticks", objectResults.Count, watch.ElapsedMilliseconds, watch.ElapsedTicks);
}
Console.WriteLine("First Read: {0}ms", Times[0]);
Console.WriteLine("Average After Cached: {0}ms", Times.Average());
Times.Clear();
// delete all
writer.DeleteAll();
Console.WriteLine("-------------- Native Lucene Methods ---------------");
watch.Reset();
watch.Start();
writer.AddDocument(TestClass1.ToDocument(testObjects[0]));
watch.Stop();
Console.WriteLine("First Write: {0}ms", watch.ElapsedMilliseconds);
iteratorCount = IteratorCount;
while (iteratorCount-- > 0)
{
watch.Reset();
watch.Start();
foreach (var testObject in testObjects)
{
writer.AddDocument(TestClass1.ToDocument(testObject));
}
watch.Stop();
Times.Add(watch.ElapsedMilliseconds);
}
Console.WriteLine("Average After Cached: {0}ms", Times.Average());
Times.Clear();
iteratorCount = IteratorCount;
while (iteratorCount-- > 0)
{
watch.Reset();
watch.Start();
//.........这里部分代码省略.........