I’m learning the new Sitecore.ContentSearch LINQ to Sitecore.ContentSearch API in Sitecore 7. I understand that Sitecore recommends using the new LINQ API on top of the existing Sitecore.Search API, but I am struggling to make even the simplest of the queries.
Take, for example, the following search query: "hello world" .
Using the Sitecore.Search API, the terms “hello world” are usually passed through QueryParser , which will result in documents matching the word “hello” OR “peace”. Documents containing both conditions will be rated higher than those with only one.
How to execute the same query using LINQ?
Here is what I tried:
var results = SearchContext.GetQueryable<MyResultItem>(); var terms = searchTerm.Split(' ');
UPDATE
I am convinced that I am missing something very simple. Of course, with all the work that went into the new search API, this simple use case was not missed ... right?
As a workaround, I tried to open sitecore_web_index by default using the existing SearchManager, however this will not work.
Unfortunately, I had to resort to the existing API until I could figure it out. I will definitely update this question with my findings.
UPDATE 2
I found the Sitecore.ContentSearch.Utilities.LinqHelper class, which partially solves the problem. You can use it to dynamically build a query similar to BooleanQuery in Lucene.Net, however its parameters are limited and this adds a bit of overhead.
source share