当前位置: 首页>>代码示例>>C#>>正文


C# IndexSearcher.Query方法代码示例

本文整理汇总了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();
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:LukeMapper,代码行数:101,代码来源:Program.cs


注:本文中的Lucene.Net.Search.IndexSearcher.Query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。