There is a custom code which triggers on rebuilding indexes. The method will extract all content from each page rendering's datasources and store in the content field.
When I debug, I see that the datasource content is correctly extracted. However, in the search method, the same content is not found.
//This function is triggered when rebuilding indexes is performed in CMS
public class SubcontentField : IComputedIndexField
{
public object ComputeFieldValue(IIndexable indexable)
{
var sitecoreIndexable = indexable as SitecoreIndexableItem;
if (sitecoreIndexable == null)
{
return null;
}
//it is assumed that the home item is the same in master & web databases
Item homeItem = GetHomeItem(SiteName, MasterDatabaseName);
List<string> contentToAdd = new List<string>();
//add values (of only the page items that are under home) to the computed field.
if (homeItem != null && (sitecoreIndexable.Item.ID == homeItem.ID || sitecoreIndexable.Item.Paths.IsDescendantOf(homeItem)))
{
// find renderings with datasources set
IEnumerable<Item> customDataSources = ExtractRenderingDataSourceItems(sitecoreIndexable.Item);
IEnumerable<Item> relatedItems = customDataSources.SelectMany(GetRelatedItems);
// extract text from data sources
contentToAdd = customDataSources.SelectMany(GetItemContent).ToList();
contentToAdd.AddRange(relatedItems.SelectMany(GetItemContent));
if (contentToAdd.Count == 0) return null;
}
return string.Join("|", contentToAdd);
}
}
Search Method:
private void GetSearchResults(string keywords)
{
using (var context = ContentSearchManager.GetIndex(index).CreateSearchContext())
{
IQueryable<SearchResultItem> query = context.GetQueryable<SearchResultItem>()
.Where(x => x.Content.Contains(keywords) && x.Language == Sitecore.Context.Language.Name);
if (query != null && query.Count() > 0)
{
}
}
}
I have checked for a particular keyword when rebuilding the web_index and when searched for the same, the query
is always null.
We are using Azure Search
.