We recently upgraded from 7.2 to 8.1 Update 2. We experienced that Sort by Relevance in Lucene search is not working when we are using Contains, StartsWith, EndsWith, Equals, Like, and MatchWildcard operators while building the search querying _fullpath.
string sitePath = “/sitecore/content/home”;var results = SearchContext().GetQueryable<CustomResult>().Where(r => (r.Path.Contains(sitePath + “/”));
- Sitecore.ContentSearch Linq layer
- A number of Linq operators did not always return the expected results when passing a phrase as the parameter. This applied to the Contains, StartsWith, EndsWith, Equals, Like, and MatchWildcard operators. This has been fixed by making these operators use an analyzer and by making the operators create the correct multi-term query for phrase queries. As a result of this change, you might see a different set of results returned when using these operators. (389868, 396185, 396135)
- The EndsWith() operator now requires the specified field to be stored in the index with termvector offsets. If the field is not stored with termvector offsets, a warning will be written to the log file, and the operator will return 0 results. (389868)
Note: This fix was reworked in the 7.2 Initial Release. The EndsWith() operator now throws an exception if it is called for a field that is not stored in the index with termvector offsets (ref. no. 397998) . [Added March 11, 2014]
Please refer to the release notes at the URL mentioned below and search for (389868, 396185, 396135) :
It’s a recommended way to query _path field instead of querying _fullpath. Hence the code above can be written as:-
var results = SearchContext().GetQueryable<CustomResult>().Where(r => (r.Paths.Contains(new Sitecore.Data.ID(“<<Item ID of the root Item>>”))
Hope this helps.