سؤال

I've created a custom content search index in Sitecore v7.1.

The indexing and crawling works fine, and I am able to search the index and return items correctly. The issue I am having is that the index sometimes gets populated with items that are outside of the "crawling root" value (see configuration below.

The work around so far has been to add template excludes to the Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.config but this is annoying as I have lots of non-content templates that I don't want to have to continue to add to this file.

My index configuration is as follows (This is in a config include file):

    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <contentSearch>
            <configuration type="Sitecore.ContentSearch.LuceneProvider.LuceneSearchConfiguration, Sitecore.ContentSearch.LuceneProvider">
                <indexes hint="list:AddIndex">
                    <index id="artscentre_web_index" type="Sitecore.ContentSearch.LuceneProvider.SwitchOnRebuildLuceneIndex, Sitecore.ContentSearch.LuceneProvider">
                        <param desc="name">$(id)</param>
                        <param desc="folder">$(id)</param>
                        <!-- This initializes index property store. Id has to be set to the index id -->
                        <param desc="propertyStore" ref="contentSearch/databasePropertyStore" param1="$(id)" />
                        <strategies hint="list:AddStrategy">
                            <!-- NOTE: order of these is controls the execution order -->
                            <strategy ref="contentSearch/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/Sites/ArtsCentre/Home</Root>
                            </crawler>
                        </locations>
                    </index>
                </indexes>
            </configuration>
        </contentSearch>
    </sitecore>
</configuration>

As you can see, my crawler root tag should mean the index only indexes my content items, yet it's indexing items from places such as /sitecore/content/Sites/SiteA/Configuration

Any help on this would be great :)

Cheers, Justin

هل كانت مفيدة؟

المحلول

This is a bug in sitecore! It is reported, but no estimation on when it will be fixed.

The bug is in the Sitecore.ContentSearch.SitecoreItemCrawler.IsAncestorOf method, where it doesn't do the right check.

This is the advice i got from sitecore support:

For the meantime, we suggest you implement the following workaround to resolve the issue:

  1. Create a class derived from the Sitecore.ContentSearch.SitecoreItemCrawler class.

  2. Override its IsAncestorOf method. The new method should look as follows:

     protected override bool IsAncestorOf(Item item)
     {
       bool result;
       using (new SecurityDisabler())
       {
         using (new CachesDisabler())
         {
           //result = item.Axes.IsAncestorOf(item);
           result = this.RootItem.Axes.IsAncestorOf(item);
         }
       }
       return result;
     }
    
  3. Build the class into an assembly. Place the assembly to the site's bin folder.

  4. Comment out all occurrences of the SitecoreItemCrawler class in your configuration. Insert new crawler definitions to use new crawler. By default you need to modify the following config files:

     Sitecore.ContentSearch.Lucene.Index.Core.config
     Sitecore.ContentSearch.Lucene.Index.Master.config
     Sitecore.ContentSearch.Lucene.Index.Web.config
    
     <!--<crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">-->
     <crawler type="[fully qualified class name], [your assembly name]">
    
  5. Rebuild the indexes.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top