2014-01-09 52 views
1

我想索引不是Sitecore項目的Sitecore用戶。如何在Sitecore 7中創建一個自定義索引來索引非Sitecore項目(例如用戶)

如果我想創建組合不同Sitecore項目的不同字段的自定義索引,那麼同樣的方法我該怎麼做。假設我有某種數據提供程序/存儲庫返回的數據,我如何創建,配置,索引這些數據。

我已經寫了一些配置這個索引:

<configuration type="Sitecore.ContentSearch.LuceneProvider.LuceneSearchConfiguration, Sitecore.ContentSearch.LuceneProvider"> 
    <indexes hint="list:AddIndex"> 
     <index id="custom_user_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)" />--> 

     <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="PT.Forum.Framework.Users.Infrastructure.UserCrawler, PT.Forum.Framework.Users"/> 
     </locations>     
     </index> 
    </indexes> 
    </configuration> 

我履帶做到這一點:

public class UserCrawler : AbstractProviderCrawler 
{ 
    public override void Initialize(ISearchIndex index) 
    { 
     Assert.ArgumentNotNull(index, "index"); 
     Database = "web"; 

     Assert.IsNotNull(Database, "Database element not set."); 
     Assert.IsNotNull(Root, "Root element not set."); 
     base.Initialize(index); 
     LuceneIndex index2 = index as LuceneIndex; 
     if (Operations == null) 
     { 
     Operations = new LuceneIndexOperations(index2); 
     CrawlingLog.Log.Info(string.Format("[Index={0}] Initializing LuceneDatabaseCrawler. DB:{1}/Root:{2}", index.Name, Database, Root)); 
     } 
     var users = new UserRepository().GetByConstraint(UserRepositoryContraints.IsNejTakPlusUser); 
     index.Configuration = new LuceneIndexConfiguration(); 
     var updateContext = index.CreateUpdateContext(); 

    Operations.Add(new ForumUser(users.First()), updateContext, index.Configuration); 
    } 
} 

但該指數配置爲空。

+0

我寫了一篇關於Sitecore 7索引機制的博客文章。也許這會幫助你:http://www.partechit.nl/en/blog/2013/04/sitecore-7-in-depth- indexing-mechanics –

+0

我的問題與您的博客帖子中的「3.3.1特殊字段」部分有關。 Aparently所有computedIndexFields爲空,因爲我得到所有字段記錄的AddComputedIndexFields()方法中的錯誤。 –

回答

0

上面的配置使用DefaultIndexConfiguration包含幾個計算字段。嘗試使用自己的配置,並只添加索引所需的字段/計算字段/其他設置。

示例演示如何使用自定義配置:

<customSearch> 
    <myCustomConfiguration type="Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration, Sitecore.ContentSearch.LuceneProvider"> 

    <indexAllFields>false</indexAllFields> 

    <!-- include parts of default configuration --> 
    <Analyzer ref="contentSearch/configuration/defaultIndexConfiguration/analyzer" /> 

    <!-- more settings here --> 

    </myCustomConfiguration> 
</customSearch> 
<contentSearch> 
    <configuration type="Sitecore.ContentSearch.LuceneProvider.LuceneSearchConfiguration, Sitecore.ContentSearch.LuceneProvider"> 
    <indexes hint="list:AddIndex"> 
     <index id="custom_user_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" aram1="$(id)" />--> 

     <Configuration ref="customSearch/MyCustomConfiguration" /> 

     <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="PT.Forum.Framework.Users.Infrastructure.UserCrawler, PT.Forum.Framework.Users"/> 
     </locations>     
    </index> 
    </indexes> 
    </configuration> 
</contentSearch> 

如果你要使用增量更新,您還需要確保,Sitecore的可匹配Lucene的現有文檔。默認情況下,這是使用Sitecore字段完成的。