Akshay Jain
Akshay Jain

Reputation: 26

Sitecore web indexing issue for more version items in master database?

When a new version of an item is created in master database, if we edit the item and save and publish it.The item gets published and web database contains the latest updated version item. But while browsing item is not visible on the website some $name is visible for the item. Sometimes the item is not visible and sometimes it is visible with $name. Also when browsing the item directly through url item is visible with latest updated content,so the item is published.Its seems some problem related with indexing. But when an item is directly edited without the creating a new version,then the issue doesn't exist.So the issue is with the indexing as well as versions as I guess there will be more than one latest versions for the web index which is creating the problem. How to fix this issue? As a workaround I have to delete the item from web database and republish and rebuild the index again to solve the issue.

Is there a need to customize the existing indexing and crawler strategy for more than one versions of items?If so which files needs to customize or override and change?" Here is the code snippet for web indexing for the data items to be displayed?

<!-- sitecore_web_content_mag_index -->
        <indexes hint="list:AddIndex">
          <index id="sitecore_web_content_mag_index" type="Sitecore.ContentSearch.LuceneProvider.SwitchOnRebuildLuceneIndex, Sitecore.ContentSearch.LuceneProvider">
            <param desc="name">$(id)</param>
            <param desc="folder">$(id)</param>
            <param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
            <configuration ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration" />
            <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.TimeIntervalCommitPolicy, Sitecore.ContentSearch" />
              </policies>
            </commitPolicyExecutor>
            <locations hint="list:AddCrawler">
              <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
                <Database>web</Database>
                <Root>/sitecore/content/Site/Home</Root>
              </crawler>
            </locations>
          </index>
        </indexes>

Upvotes: 0

Views: 829

Answers (1)

Ben Golden
Ben Golden

Reputation: 1580

When using the ContentSearch API, you can filter the results to return only the latest version by doing something like this:

searchContext.GetQueryable<SearchResultItem>()
             .Where(result => result["_latestversion"].Equals("1");

Or, if you have created your own search result model, you can add a property to it to make the query syntax more consise.

Search Result Model:

public class CustomSearchResultItem : SearchResultItem
{
    [IndexField("_latestversion")]
    public bool IsLatestVersion { get; set; }

    // other properties
}

Query

searchContext.GetQueryable<CustomSearchResultItem>()
             .Where(result => result.IsLatestVersion);

Another approach is to use extension methods as described in this post: http://laubplusco.net/generic-extension-methods-sitecore-contentsearch/

Upvotes: 0

Related Questions