I'm using Sitecore 9.0.2 with Azure Search and Solr.
I have the weirdest search issue I've seen in a while. Take the following steps:
- Restart the application (
iisreset
or similar) - Rebuild the search index (completes successfully)
- Change an item and publish
- View the index directly and see the item was updated
- Load a page that executes a search query and see the expected items returned
- Change an item and publish
- View the index directly again and see the item was not updated
- Restart the application again
- View the index directly and see the item was updated
I could execute steps 3 and 4 over and over and the updates continue to flow to the index until I execute step 5.
Below is my code:
public IEnumerable<ISitecoreItem> GetRelatedItems(IDataSource dataSource)
{
var relatedItems = new List<ISitecoreItem>();
using (var index = ContentSearchManager.GetIndex(indexName))
{
var remainingMaxItems = MaxItems;
foreach (var root in dataSource.RelatedRootItems)
{
relatedItems.AddRange(GetItemsFromRoot(index, root, remainingMaxItems, currentItem.Language.Name));
if (relatedItems.Count >= MaxItems)
{
break;
}
remainingMaxItems = MaxItems - relatedItems.Count;
}
}
return relatedItems;
}
private IEnumerable<ISitecoreItem> GetItemsFromRoot(ISearchIndex index, ISitecoreItem root, int maxItems, string language)
{
var relatedItems = new List<ISitecoreItem>();
using (var context = index.CreateSearchContext())
{
var filterPredicate = PredicateBuilder.True<SearchResultItem>();
// filter to only items based on the current page's language
filterPredicate = filterPredicate.And(x => x.Language == language);
// ensure root node
filterPredicate = filterPredicate.And(x => x.Path.StartsWith(root.FullPath));
// apply filters
var query = context.GetQueryable<SearchResultItem>().Filter(filterPredicate);
// apply paging (get number of results)
query = query.Page(0, maxItems);
// get results and map
var results = query.GetResults();
var relatedItemResults = results.Hits.Select(x => MapSearchResultToGlassSitecoreItem(x.Document)).ToList();
relatedItems.AddRange(relatedItemResults);
}
return relatedItems;
}
And my index configuration:
<index id="local_azure_web_index" type="Sitecore.ContentSearch.Azure.CloudSearchProviderIndex, Sitecore.ContentSearch.Azure" patch:source="Sitecore.ContentSearch.Azure.Index.Web.ExcludeFields.config">
<param desc="name">$(id)</param>
<param desc="connectionStringName">cloud.search</param>
<param desc="totalParallelServices">5</param>
<param ref="contentSearch/indexConfigurations/databasePropertyStore" desc="propertyStore" param1="$(id)"/>
<configuration ref="contentSearch/indexConfigurations/defaultCloudIndexConfiguration">
<documentOptions ref="contentSearch/indexConfigurations/defaultCloudIndexConfiguration/documentOptions" patch:source="Sitecore.ContentSearch.Azure.Index.Web.ExcludeFields.config">
<exclude hint="list:AddExcludedField">
<!-- omitted for brevity -->
</exclude>
</documentOptions>
</configuration>
<schemaBuilder ref="contentSearch/searchServiceSchemaBuilder"/>
<searchService type="Sitecore.ContentSearch.Azure.Http.CompositeSearchService, Sitecore.ContentSearch.Azure"/>
<strategies hint="list:AddStrategy">
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsync"/>
</strategies>
<commitPolicyExecutor type="Sitecore.ContentSearch.CommitPolicyExecutor, Sitecore.ContentSearch">
<policies hint="list:AddCommitPolicy">
<policy type="Sitecore.ContentSearch.ModificationCountCommitPolicy, Sitecore.ContentSearch">
<Limit>1000</Limit>
</policy>
</policies>
</commitPolicyExecutor>
<locations hint="list:AddCrawler">
<crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
<Database>web</Database>
<Root>/sitecore</Root>
</crawler>
</locations>
<enableItemLanguageFallback>false</enableItemLanguageFallback>
<enableFieldLanguageFallback>false</enableFieldLanguageFallback>
</index>
What I've tried:
- Rebuilding the index after the issue happens (it just returns immediately with no items updated)
- Changing the indexing strategy
- Disabling switch on rebuild
- Waiting a really long time to see if the index ever updates (overnight; it didn't)
What could be causing this?