2013-02-16 79 views
3

我已經創建了umbraco搜索,其中我不應該搜索一些節點,所以我可以做的是有些東西我應該在搜索條件或sholud中定義我在檢查設置或索引設置代碼中執行某些操作對於配置文件排除從umbraco搜索

<IndexSet SetName="DemoIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/DemoIndex/"> 
<IndexAttributeFields/> 
<IndexUserFields/> 
<IncludeNodeTypes/> 
<ExcludeNodeTypes> 
<add Name="News" /> 
</ExcludeNodeTypes> 
</IndexSet> 

,並檢查設置文件

<add name="DemoIndexer" type="UmbracoExamine.LuceneExamineIndexer, UmbracoExamine" runAsync="true" 
    supportUnpublished="false" 
    supportProtected="true" 
    interval="10" 
    analyzer="Lucene.Net.Analysis.WhitespaceAnalyzer, Lucene.Net" indexSet="DemoIndexSet"/> 

和用戶控制代碼

public static class SearchResultExtensions 
    { 
     public static string FullUrl(this SearchResult sr) 
     { 
      return umbraco.library.NiceUrl(sr.Id); 
     } 

    } 

SearchTerm = Request.QueryString["s"]; 

      if (string.IsNullOrEmpty(SearchTerm)) return; 

      SearchResults = ExamineManager.Instance.SearchProviderCollection["DemoSearcher"].Search(SearchTerm,true).ToList(); 

      SearchResultListing.DataSource = SearchResults; 
      SearchResultListing.DataBind(); 

回答

3

在您的DocumentType中添加一個類型爲true/false的字段「includeInSearchIndex」。 然後在您檢查索引配置添加該字段

<IndexUserFields> 
    <add Name="includeInSearchIndex"/> 
</IndexUserFields> 

然後用創建自定義查詢來搜索在沒有檢查該字段的一切。

var Searcher = ExamineManager.Instance.SearchProviderCollection["WebsiteSearcher"];    
var query = searchCriteria.Field("includeInSearchIndex", "0"). 
    Or().Field("includeInSearchIndex", "").Compile(); 
var searchResults = Searcher.Search(query); 

有關檢查索引和搜索的詳細信息退房this page查詢

4

如果要排除節點類型只是把這個索引集標籤之間

<IndexSet ...> 
    ... 
    <ExcludeNodeTypes> 
    <add Name="NameNodeType" /> 
    </ExcludeNodeTypes> 
</IndexSet> 

更多信息上codeplex examine