1
votes

I'm using Sitecore search for items in the database.

What I want to do is to parse the Lucene query and use standart Sitecore search to return results.

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.

Does Sitecore have such possobility?

2
Which version of Sitecore are you using? - jammykam
Im using Sitecore 7.2 - Jack Spektor
I don't have time for an answer, but look at the Sitecore.ContentSearch API: sitecore-community.github.io/docs/documentation/Search/… - jammykam
I can't find in documentation how to parse a query from string and run using Sitecore 7.2 API, so I asked a question here. - Jack Spektor
Ahhh, sorry, I missed the "parsing Lucene to Sitecore" part. Can you provide examples of what you are trying to parse. Why can'y you use Sitecore query directly? - jammykam

2 Answers

1
votes

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.

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

0
votes

In Sitecore 8.2 (perhaps also newer/older)

You can use the QueryBuilder fieldtype and execute the query using the LinqHelper. This applies to both Solr and 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.