2012-01-06 112 views
0

我希望能夠在某個目錄內進行搜索。例如。可以說用戶點擊了網站頂部的「不同類型的火車」鏈接。然後,該頁面將列出不同類型的列車,並帶有搜索框。我希望用戶在搜索框中鍵入的任何內容僅用於搜索「火車類型」部分中的頁面 - 任何在/sitecore/content/LOTW/Home/trains之內的內容以及網站上的其他任何頁面。我目前使用:使用sitecore搜索搜索特定文件夾

protected void searchIcon_Click(object sender, EventArgs e) 
{ 
    PerformSearch(); 
} 

private void PerformSearch() 
{ 
    /* Changed from Shared Source, to use different path finding, and context database */ 

    Item pointerItem = Sitecore.Context.Database.SelectSingleItem("/sitecore/content/LOTW/Global/Settings/Config/Pointers/Search Results"); 

    if (pointerItem != null) 
    { 
     Item results = Sitecore.Context.Database.GetItem(new ID(pointerItem["Item"])); 

     if (results != null) 
     { 

      string results_url = LinkManager.GetItemUrl(results) + "?search=" + Server.UrlEncode(search.Text); 
      Response.Redirect(results_url); 
     } 
     else 
     { 
      search.ForeColor = Color.Red; 
      search.Text = "Unable to find results item"; 
     } 

    } 
} 

這反而搜索整個網站。我對Sitecore中的搜索一無所知,所以我有點失落!

+0

我有點困惑。您發佈的代碼似乎只處理查找搜索頁面並重定向到它。它不是實際的搜索代碼。不過,我建議你爲每個部分創建獨特的索引來搜索和使用[高級數據庫爬行器](http://trac.sitecore.net/AdvancedDatabaseCrawler/) – 2012-01-06 13:45:33

回答

1

Sitecore在項目上具有Axis名稱空間,允許您從特定項目訪問後代,但如果您的孩子超過25個,則搜索變得非常緩慢。

要快速搜索,請使用Lucene索引。 Sitecore是Lucene索引的標準。

爲了簡化對索引的訪問,您應該下載免費軟件/開源模塊Advanced Database Crawler

你可以閱讀更多關於如何設置它以及如何訪問這裏的指數:

Using the Sitecore open source AdvancedDatabaseCrawler Lucene indexer