从umbraco搜索中排除节点

时间:2013-02-16 09:21:57

标签: asp.net umbraco

我已经创建了umbraco搜索,其中我想要一些不应该被搜索的节点,所以我能做的是我应该在搜索条件中定义或sholud我在检查设置或索引设置代码中执行某些配置文件

 <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();

2 个答案:

答案 0 :(得分:4)

如果要排除节点类型,只需将其放在IndexSet标记

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

codeplex examine

的更多信息

答案 1 :(得分: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