【问题标题】:Parse lucene query using Sitecore Search使用 Sitecore Search 解析 lucene 查询
【发布时间】:2015-03-23 22:35:54
【问题描述】:

我正在使用 Sitecore 搜索数据库中的项目。

我要做的是解析 Lucene 查询并使用标准 Sitecore 搜索返回结果。

我知道我可以使用 QueryParser 来做到这一点,但如果可能的话,我想坚持使用标准的 Sitecore 功能(比如已经存在的索引 sitecore_web_index)。

Sitecore 有这种可能吗?

【问题讨论】:

  • 您使用的是哪个版本的 Sitecore?
  • 我使用的是 Sitecore 7.2
  • 我没有时间回答,但请查看Sitecore.ContentSearch API:sitecore-community.github.io/docs/documentation/Search/…
  • 我在文档中找不到如何从字符串解析查询并使用 Sitecore 7.2 API 运行,所以我在这里问了一个问题。
  • 啊,抱歉,我错过了“将 Lucene 解析为 Sitecore”部分。你能提供你试图解析的例子吗?为什么不能直接使用 Sitecore 查询?

标签: asp.net .net lucene sitecore


【解决方案1】:

使用 Sitecore 7 中 Predicate Builder 的强大功能,您可以走得很远。我不确定是否有一种真正简单的方法来进行解析,但如果您使用 PB 和一些逻辑,应该可以让您到达您想要的位置需要。

http://www.sitecore.net/learn/blogs/technical-blogs/sitecore-7-development-team/posts/2013/05/sitecore-7-predicate-builder.aspx

【讨论】:

    【解决方案2】:

    在 Sitecore 8.2 中(可能也较新/较旧)

    您可以使用 QueryBuilder 字段类型并使用 LinqHelper 执行查询。这适用于 Solr 和 Lucene。

            var index = ContentSearchManager.GetIndex("sitecore_web_index");
    
            using (var context = index.CreateSearchContext())
            {
                var solrSearchContext = context as Sitecore.ContentSearch.SolrProvider.SolrSearchContext;
                var results =  Sitecore.ContentSearch.Utilities.LinqHelper.CreateQuery<SearchResultItem>(solrSearchContext, sourceItem["SearchQuery"]);              
            }
    

    该方法会将结果作为 SearchResultItems 的集合生成,您可以随意使用它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-22
      • 2011-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多