2014-02-19 60 views
4

我想限制Sitecore 7中的搜索索引只掃描內容樹的一個節點。Sitecore 7搜索索引問題

目前的結構是這樣的:

  • Sitecore的
    • 內容
      • BaseNode
      • $公司節點

該索引是索引BaseNode & $Company Node,但我只希望它索引$Company Node

我在Sitecore.ContentSearch.configSitecoreContentSearch.Lucene.DefaultIndexConfiguration.configSitecore.ContentSearch.Lucene.Index.MasterSitecore.ContentSearch.LuceneIndex.Web.config更新默認/sitecore/content路徑。當我將<root>元素更新爲/sitecore/content/$CompanyNode時,我嘗試重建索引時出現以下異常。

任何想法,我需要做的,以限制Lucene索引一些項目,而不是一切?

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) 
+0

請標記正確答案或提供更多信息。 :) –

+0

嗨安德魯,我正在與另一個資源來收集更多的信息。我認爲我們會實施你的解決方案,但現在這個任務被困在'等待'任務列表中。 –

回答

7

我相信你正在嘗試修改Master Lucene索引文件。我相信最終會破壞很多事情,我會建議你創建一個新的Lucene索引文件。

如果你要創建一個新的指標:在你的APP_CONFIG /地方該指數包含的文件夾

Sitecore.ContentSearch.Lucene.Index.Alexander.config

在這種配置設置爬蟲搜索爲您的節點。

<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> 

上述索引將索引該節點下的所有內容。在C#中,您可以輕鬆地使用此方法調用該方法。

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的工作 - >控制面板 - >索引 - >索引管理器。這樣做後,你應該看到索引。

另一個編輯: 您也可以在內容樹中的該項下執行您的C#搜索,並僅使用Web數據庫。

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 
    } 
    }