简体   繁体   English

使用Sitecore搜索解析Lucene查询

[英]Parse lucene query using Sitecore Search

I'm using Sitecore search for items in the database. 我正在使用Sitecore搜索数据库中的项目。

What I want to do is to parse the Lucene query and use standart Sitecore search to return results. 我想做的是解析Lucene查询,并使用标准的Sitecore搜索返回结果。

I know I can do this using QueryParser, but I want to stick to standart Sitecore functionality (like already existing indexes sitecore_web_index) if it's possible. 我知道我可以使用QueryParser做到这一点,但我想尽可能坚持使用标准的Sitecore功能(例如已经存在的索引sitecore_web_index)。

Does Sitecore have such possobility? Sitecore是否具有这种可能性?

You can get pretty far using the power of the Predicate Builder in Sitecore 7. I'm not sure there is a real easy way to do the parse, but if you use the PB and some logic that should get you where you need to be. 使用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 http://www.sitecore.net/learn/blogs/technical-blogs/sitecore-7-development-team/posts/2013/05/sitecore-7-predicate-builder.aspx

In Sitecore 8.2 (perhaps also newer/older) 在Sitecore 8.2中(也许也较新/较旧)

You can use the QueryBuilder fieldtype and execute the query using the LinqHelper. 您可以使用QueryBuilder字段类型,并使用LinqHelper执行查询。 This applies to both Solr and Lucene. 这适用于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"]);              
        }

the method will yield the results as a collection of SearchResultItems and you can do with them as you please. 该方法将产生结果作为SearchResultItems的集合,您可以根据需要使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM