从umbraco搜索中排除节点

问题描述 投票:3回答:2

我创建了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();
asp.net umbraco
2个回答
4
投票
如果要排除节点类型,只需将其放在IndexSet标记之间

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

有关codeplex examine的更多信息

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以获取有关检查索引和搜索查询的更多信息
© www.soinside.com 2019 - 2024. All rights reserved.