I have to implement Azure
search but would like to try with Lucene first in the local setup. I am following this example by @kamsar
1.Created the SubcontentField
class
2.Created the patch config
and
3.Rebuilt the index for sitecore_web_index
[ Did not add any custom field/template IDs in the Lucene configs. Using the default ones as it is without any changes. ]
Here is my code which is triggered, when a user clicks the search button on the page.
string keywords = <keywords entered by user>;
using (var context = ContentSearchManager.GetIndex("sitecore_web_index").CreateSearchContext())
{
var query = context.GetQueryable<SearchResultItem>()
.Where(x => x.Content.Contains(keywords) &&
x.Language == Sitecore.Context.Language.Name);
List<SearchResultItem> lst = query.ToList();
}
Now I search using a keyword "stories". There is a rendering on the home page, which has the title "Stories". I am expecting the Home page item in one of the result items inside lst
.
But there are other items like controller rendering, media library, etc that have the name "stories".
I would like to get the list of page items that have the keyword used in any of the renderings for that page.
As suggested in the article, should I search in any particular field? Could someone please guide me on how to get my desired results here?
Using sc8.2 u3 with MVC
UPDATE:
I did this to see if there really was home page in the returned list
var query = context.GetQueryable<SearchResultItem>()
.Where(x => x.ItemId == SitecoreUtility.GetHomeItem().ID &&
x.Language == Sitecore.Context.Language.Name);
List<SearchResultItem> lst = query.ToList();
string sss = lst[0].Content;
It did return one result, but "sss" got only one word which was "Home". So I'm doubting if the example from the article really worked for me, I mean did it really get all content fields values into one field.