2015-05-19 111 views
2

我正在學習如何爲Sitecore 6.6設置和配置Lucene搜索索引。我將一個基本配置文件拼湊在一起,該文件將所有類型爲「文章」模板的項目索引到樹中所需的位置,並能夠將所有項目從該索引中提取出來並顯示結果中的名稱。Sitecore 6.6 - 設置Lucene索引

現在我準備好定製該索引。我需要專門索引兩個字段,並且遇到配置語法問題。這是兩個領域的細分。我希望有人能夠幫助我調整配置來解釋這些字段。

Meta關鍵詞 - 該字段(單行文本)不是文章模板的一部分,而是從另一個名爲Meta Base的模板中提取,該文章從該文章繼承。我不需要存儲這個,只需要索引它就可以搜索。恩。值「ortho,pain,joint」

類別 - 此字段是指向樹中類別項目的可用列表的下拉鍊接。我確實需要存儲以及索引它,以便可以在搜索/顯示這些Lucene文檔的結果頁面上使用它。

我似乎無法找到6.6的正確文檔。 7+以上的文檔存在,但它們在6.6中不起作用,因爲事情似乎發生了顯着變化。 Sitecore支持指導我一些舊文檔,其中包含不推薦使用的代碼以及沒有編譯的代碼,而我讀過的所有內容似乎都指向使用Contrib Search(我已經通過NuGet提取)。我想讓它在沒有Contrib的情況下工作,但是如果我需要的話,我會的。

這裏是我的配置我沒有了contrib東西創建:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> 
<sitecore> 
<search> 
    <configuration> 
    <indexes> 
     <index id="my-custom-index" type="Sitecore.Search.Index, Sitecore.Kernel"> 
     <!-- name - not sure if necessary but use id and forget about it --> 
     <param desc="name">$(id)</param> 

     <!-- folder - name of directory on the hard drive --> 
     <param desc="folder">__my-custom-index</param> 

     <!-- analyzer - reference to analyzer defined in Sitecore.config --> 
     <Analyzer ref="search/analyzer" /> 

     <!-- list of locations to index - each of the with unique xml tag --> 
     <locations hint="list:AddCrawler"> 

      <!-- first location (and the only one in this case) - specific folder from you question --> 
      <!-- type attribute is the crawler type - use default one in this scenario --> 
      <specificfolder type="Sitecore.Search.Crawlers.DatabaseCrawler,Sitecore.Kernel"> 

      <!-- indexing items from web database --> 
      <Database>web</Database> 

      <!-- your folder path --> 
      <Root>/sitecore/content/Northwestern/in-care</Root> 

      <!-- Article Template --> 
      <include hint="list:IncludeTemplate"> 
       <ContentHubArticle>{1E79E463-631A-4FBB-BEEA-3304D25F29CD}</ContentHubArticle> 
      </include> 

      <indexAllFields>true</indexAllFields> 
      </specificfolder> 
     </locations> 



     </index> 
    </indexes> 
    </configuration> 
</search> 

+0

暫且,其實我已經禁用了SearchContrib指數,下定決心要擺脫的最現成的指標工作。我已經安裝了indexviewer模塊,並且由於 true設置,我能夠看到所有字段都獲得了索引,儘管它們沒有被存儲,只有索引。我想禁用該設置,並只索引上面提到的兩個字段,存儲所提到的droplink值。我懷疑droplink會更困難,而且需要自定義代碼,所以我先從單行文本框開始。 – tjans

+0

查看下面的3篇博文。他們應該回答你的所有問題:https://www.cognifide.com/blogs/sitecore/sitecore-6-lucene-search-the-most-basic-setup/ https://www.cognifide.com/blogs/sitecore /故障排除-Sitecore的-的Lucene搜索和索引/ https://www.cognifide.com/blogs/sitecore/troubleshooting-sitecore-lucene-search-and-indexing/ –

+0

馬立克,在那裏你打算髮布另一個鏈接?最後兩個是對方的愚蠢。此外,我已經完成了這兩個,他們都讓我到現在的位置,但不提供如何指定特定字段進行索引以及如何配置是存儲它們還是僅索引它們的解決方案,也不提供他們是否提供有關如何處理droplink字段的解決方案。 – tjans

回答

0

與Sitecore支持人員交談時,他們絕對稱這不能用開箱即用的功能完成。我能夠利用這一系列的博客文章得到它的索引我的領域:

http://sitecoregadgets.blogspot.com/2009/10/working-with-lucene-search-index-part-i.html http://sitecoregadgets.blogspot.com/2009/11/working-with-lucene-search-index-in.html http://sitecoregadgets.blogspot.com/2009/11/working-with-lucene-search-index-in_25.html http://sitecoregadgets.blogspot.com/2010/08/adding-custom-fields-to-index.html http://sitecoregadgets.blogspot.com/2010/07/sitecore-lucene-index-does-not-remove.html

的唯一剩下的就是讓droplink場店不同的場比指向該項目的guid,但我認爲這裏有足夠的可以稱之爲答案,因爲最大的問題是如何爲自定義字段建立索引。當我完成後,我可能會回過頭來發布整個代碼,所以您不必像我一樣將博客文章中的所有內容拼湊在一起,但要弄清楚發生了什麼很容易。

我也upvode馬立克氏後上方,因爲他一直樂於助人,他的意見是非常有用的。

4

Sitecore的6 Lucene索引的最基本的設置是:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> 
<sitecore> 
    <search> 
    <configuration> 
    <indexes> 
    <index id="custom-index" type="Sitecore.Search.Index, Sitecore.Kernel"> 
     <!-- name of the index displayed in the Sitecore Control Panel --> 
     <param desc="name">Custom Index</param> 
     <!-- folder in which index file will be stored --> 
     <param desc="folder">__$(id)</param> 
     <!-- reference to the analyzer defined in Sitecore config --> 
     <Analyzer ref="search/analyzer" /> 
     <!-- list of locations which will be index by our index --> 
     <locations hint="list:AddCrawler"> 
     <!-- our first and only location crawled by standard Sitecore crawler --> 
     <custom-loc-1 type="Sitecore.Search.Crawlers.DatabaseCrawler,Sitecore.Kernel"> 
     <!-- location root is Home item in master database --> 
     <Database>master</Database> 
     <Root>/sitecore/content/Home</Root> 
     </custom-loc-1> 
     </locations> 
    </index> 
    </indexes> 
    </configuration> 
    </search> 
</sitecore> 
</configuration> 

對於您需要創建自定義抓取工具類的自定義字段,例如:

public class MyCrawler : Sitecore.Search.Crawlers.DatabaseCrawler 
{ 
    protected override void 
    AddAllFields(Document document, Item item, bool versionSpecific) 
    { 
    base.AddAllFields(document, item, versionSpecific); 

    document.Add(CreateField("my_title", item["title"], false, 1)); 

    WorkflowState state = item.State.GetWorkflowState(); 
    document.Add(CreateField("my_final_state", 
     state != null && state.FinalState ? "1" : "", false, 1)); 

    document.Add(CreateDataField("data_title", item["title"])); 
    } 
} 

和註冊這個爬蟲類這樣的:

<locations hint="list:AddCrawler"> 
    <custom-location-1 type="My.Assembly.Namespace.MyCrawler,My.Assembly"> 
    <Database>master</Database> 
    <Root>/sitecore/content/Home</Root> 
    </custom-location-1> 
</locations> 

這裏的博客文章,你可以用它來了解更多關於Sitecore的6個搜索:

  1. https://www.cognifide.com/blogs/sitecore/troubleshooting-sitecore-lucene-search-and-indexing/
  2. https://www.cognifide.com/blogs/sitecore/sitecore-6-lucene-search-the-most-basic-setup/
  3. https://www.cognifide.com/blogs/sitecore/pagination-sorting-crawling-and-storing-data-with-sitecore-and-lucene/
+0

看起來我仍然需要一些配置,以便索引中的項目在發佈時得到重新索引。當我重建索引時,它做得很好,但是當我發佈時,更新不會更新。我嘗試添加一些我曾閱讀過的HistoryEngine的東西,但是這只是導致任何變化的項目從索引中刪除(使用Luke確認)。 – tjans