Problem with Sitecore 7 Search Index

I want to restrict the search index in Sitecore 7 to only scan a single node of the content tree.

Currently, the structure is as follows:

  • Sitecore
    • Content
      • Basenode
      • $ Node Company

An index indexes both BaseNode, and so $Company Node, but I want it to index $Company Node.

I've updated the default path /sitecore/contentin the Sitecore.ContentSearch.config, SitecoreContentSearch.Lucene.DefaultIndexConfiguration.config, Sitecore.ContentSearch.Lucene.Index.Master, and Sitecore.ContentSearch.LuceneIndex.Web.config. When I updated an item <root>to point to /sitecore/content/$CompanyNode, I get the following exception when I try to rebuild indexes.

Any ideas what I need to do to limit Lucene to just indexing some elements, and not all?

Exception: System.Reflection.TargetInvocationException 
Message: Exception has been thrown by the target of an invocation. 
Source: mscorlib 
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature         sig, Boolean constructor) 
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[]     parameters, Object[] arguments) 
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr,     Binder binder, Object[] parameters, CultureInfo culture) 
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) 
at Sitecore.Configuration.Factory.AssignProperties(Object obj, Object[] properties) 
at Sitecore.Configuration.Factory.AssignProperties(XmlNode configNode, String[]     parameters, Object obj, Boolean assert, Boolean deferred, IFactoryHelper helper) 
at Sitecore.Configuration.Factory.CreateObject(XmlNode configNode, String[] parameters,     Boolean assert, IFactoryHelper helper) 
at Sitecore.Configuration.Factory.GetInnerObject(XmlNode paramNode, String[] parameters,     Boolean assert) 
at Sitecore.Configuration.Factory.AssignProperties(XmlNode configNode, String[] parameters, Object obj, Boolean assert, Boolean deferred, IFactoryHelper helper) 
at Sitecore.Configuration.Factory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper) 
at Sitecore.Configuration.Factory.CreateObject(String configPath, String[] parameters, Boolean assert) 
at Sitecore.Search.SearchManager.get_SearchConfiguration() 
at Sitecore.Shell.Applications.Search.RebuildSearchIndex.RebuildSearchIndexForm.GetIndexes() 
at Sitecore.Shell.Applications.Search.RebuildSearchIndex.RebuildSearchIndexForm.BuildIndexes() 

Nested Exception 

Exception: System.InvalidOperationException 
Message: Root item is not defined 
Source: Sitecore.Kernel 
at Sitecore.Diagnostics.Assert.IsNotNull(Object value, String message) 
at Sitecore.Search.Crawlers.DatabaseCrawler.Initialize(Index index) 
at Sitecore.Search.Index.AddCrawler(ICrawler crawler) 
+4
1

, Index Master Lucene. , , Lucene.

: App_Config/Include

Sitecore.ContentSearch.Lucene.Index.Alexander.config

node.

<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="alexander_search_index" type="Sitecore.ContentSearch.LuceneProvider.LuceneIndex, 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>
        <commitPolicy hint="raw:SetCommitPolicy">
          <policy type="Sitecore.ContentSearch.TimeIntervalCommitPolicy, Sitecore.ContentSearch" />
        </commitPolicy>
        <commitPolicyExecutor hint="raw:SetCommitPolicyExecutor">
          <policyExecutor type="Sitecore.ContentSearch.CommitPolicyExecutor, Sitecore.ContentSearch" />
        </commitPolicyExecutor>
        <locations hint="list:AddCrawler">
          <crawler type="Sitecore.ContentSearch.LuceneProvider.Crawlers.DefaultCrawler, Sitecore.ContentSearch.LuceneProvider">
            <Database>web</Database>
            <Root>/sitecore/content/$Company Node</Root>
          </crawler>
        </locations>
       </index>
     </indexes>
   </configuration>
  </contentSearch>
 </sitecore>
</configuration>

node. # .

ContentSearchManager.GetIndex("alexander_search_index").Rebuild();

using (var searchContext = ContentSearchManager.GetIndex("alexander_search_index").CreateSearchContext())
   {
       var result = searchContext.GetQueryable<SearchResultItem>()
           .Where(//Put Query Here);

       //do ForEach if you return multiple and so on.

       if (result != null)
              Context.Item = result.GetItem();
   }

, , Sitecore → → → . .

: # - .

 Item bucketItem = //Code to get $Company Node as a Sitecore Item
  //Probably Sitecore.Context.Database.GetItem("Guid for $Company Node")

 using (var searchContext = ContentSearchManager.GetIndex(bucketItem as      IIndexable).CreateSearchContext())
  {
     try
     {
          var result = searchContext.GetQueryable<SearchResultItem>().Where(x => x.Name == itemName).FirstOrDefault();
             if (result != null)
                 Context.Item = result.GetItem();
     }
     catch (Exception)
     {
         //Do something
     }
  }
+7

Source: https://habr.com/ru/post/1527788/


All Articles