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


C# TermQuery.ToString方法代码示例

本文整理汇总了C#中Lucene.Net.Search.TermQuery.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# TermQuery.ToString方法的具体用法?C# TermQuery.ToString怎么用?C# TermQuery.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lucene.Net.Search.TermQuery的用法示例。


在下文中一共展示了TermQuery.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestSimpleBrowser

        public void TestSimpleBrowser()
        {
            var query = new TermQuery(new Term("name", "asp.net"));
            Console.WriteLine(string.Format("query: <{0}>", query.ToString()));
            var request = new BrowseRequest()
            {
                Count = 10,
                Offset = 0,
                Query = query,
                Sort = new Lucene.Net.Search.Sort(new SortField("price", SortField.DOUBLE, false)).GetSort()
            };

            var facetHandlers = new IFacetHandler[] { new SimpleFacetHandler("category") };
            var browser = new BoboBrowser(BoboIndexReader.GetInstance(IndexReader.Open(_indexDir, true), facetHandlers));
            var facetSpec = new FacetSpec() { OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc, MinHitCount = 1 };
            request.SetFacetSpec("category", facetSpec);

            var result = browser.Browse(request);
            Console.WriteLine(string.Format("total hits:{0}", result.NumHits));
            Console.WriteLine("===========================");
            foreach (var facet in result.FacetMap["category"].GetFacets())
            {
                var category = _categories.First(k => k.Value == int.Parse(facet.Value.ToString()));
                Console.WriteLine("{0}:({1})", category.Key, facet.FacetValueHitCount);
            }
            Console.WriteLine("===========================");
            for (var i = 0; i < result.Hits.Length; i++)
            {
                var doc = browser.Doc(result.Hits[i].DocId);
                var category = _categories.First(k => k.Value == int.Parse(doc.GetField("category").StringValue)).Key;
                Console.WriteLine(string.Format("{2} - {0} ${1} by {3}", doc.GetField("name").StringValue, doc.GetField("price").StringValue, category, doc.GetField("author").StringValue));
            }
        }
开发者ID:yao-yi,项目名称:BoboBrowse.Net,代码行数:33,代码来源:BasicTests.cs

示例2: DoTest

        private void DoTest(Random random, PrintWriter @out, bool useCompoundFiles, int MAX_DOCS)
        {
            Directory directory = newDirectory();
              Analyzer analyzer = new MockAnalyzer(random);
              IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
              MergePolicy mp = conf.MergePolicy;
              mp.NoCFSRatio = useCompoundFiles ? 1.0 : 0.0;
              IndexWriter writer = new IndexWriter(directory, conf);
              if (VERBOSE)
              {
            Console.WriteLine("TEST: now build index MAX_DOCS=" + MAX_DOCS);
              }

              for (int j = 0; j < MAX_DOCS; j++)
              {
            Document d = new Document();
            d.Add(newTextField(PRIORITY_FIELD, HIGH_PRIORITY, Field.Store.YES));
            d.Add(newTextField(ID_FIELD, Convert.ToString(j), Field.Store.YES));
            writer.addDocument(d);
              }
              writer.Dispose();

              // try a search without OR
              IndexReader reader = DirectoryReader.Open(directory);
              IndexSearcher searcher = newSearcher(reader);

              Query query = new TermQuery(new Term(PRIORITY_FIELD, HIGH_PRIORITY));
              @out.println("Query: " + query.ToString(PRIORITY_FIELD));
              if (VERBOSE)
              {
            Console.WriteLine("TEST: search query=" + query);
              }

              Sort sort = new Sort(SortField.FIELD_SCORE, new SortField(ID_FIELD, SortField.Type.INT));

              ScoreDoc[] hits = searcher.Search(query, null, MAX_DOCS, sort).scoreDocs;
              PrintHits(@out, hits, searcher);
              CheckHits(hits, MAX_DOCS, searcher);

              // try a new search with OR
              searcher = newSearcher(reader);
              hits = null;

              BooleanQuery booleanQuery = new BooleanQuery();
              booleanQuery.Add(new TermQuery(new Term(PRIORITY_FIELD, HIGH_PRIORITY)), BooleanClause.Occur_e.SHOULD);
              booleanQuery.Add(new TermQuery(new Term(PRIORITY_FIELD, MED_PRIORITY)), BooleanClause.Occur_e.SHOULD);
              @out.println("Query: " + booleanQuery.ToString(PRIORITY_FIELD));

              hits = searcher.search(booleanQuery, null, MAX_DOCS, sort).scoreDocs;
              PrintHits(@out, hits, searcher);
              CheckHits(hits, MAX_DOCS, searcher);

              reader.Close();
              directory.Close();
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:55,代码来源:TestSearchForDuplicates.cs


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