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


C# QueryParser.Query方法代码示例

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


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

示例1: GetItems

    /// <summary>
    /// Gets the items from the GetIndexes()
    /// </summary>
    /// <param name="queryString">
    /// The query string.
    /// </param>
    /// <param name="useQueryParser">
    /// if set to <c>true</c> [use query parser].
    /// </param>
    /// <returns>
    /// Returns Query Result
    /// </returns>
    public QueryResult GetItems(string queryString, bool useQueryParser)
    {
      // Result object used to pass result and errormessages back to sender.
      QueryResult result = new QueryResult();

      List<string> indexes = this.GetIndexes();
      string[] resultItemIds = null;
      foreach (string indexName in indexes)
      {
        string database = "master";
        HighResTimer timer = new HighResTimer(true);

        // get the specified index
        Sitecore.Search.Index searchIndex = SearchManager.GetIndex(indexName);

        // get the database to perform the search in..
        Database db = Factory.GetDatabase(database);

        SearchHits hits;
        try
        {
          if (useQueryParser)
          {
            using (IndexSearchContext searchContext = searchIndex.CreateSearchContext())
            {
              // get a new standard analyser so we can create a query..
              Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
              QueryParser queryParser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, queryString, analyzer);
              Query qry = queryParser.Query("_content");
              hits = searchContext.Search(qry, int.MaxValue);
            }
          }
          else
          {
            using (IndexSearchContext searchContext = searchIndex.CreateSearchContext())
            {
              // perform the search and get the results back as a Hits list..
              hits = searchContext.Search(queryString, int.MaxValue);
            }
          }

          result.Success = true;
          
          resultItemIds = new string[hits.Length];

          int i = 0;

          foreach (Document document in hits.Documents)
          {
            string str = document.Get("_docID");
            resultItemIds[i++] = str;
          }
        }
        catch (ParseException e)
        {
          result.ErrorMessage = e.Message;
          result.ParseException = e;
          result.Success = false;
        }
      }

      result.Result = resultItemIds;
      return result;
    }
开发者ID:HydAu,项目名称:sitecore8ecommerce,代码行数:76,代码来源:StructuredTree.cs


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