iProgrammer
iProgrammer

Reputation: 3107

exclude node from umbraco search

I have created umbraco search in which i want some node which should not be searched so what i can do is there something i should define in search criteria or sholud i do something in examine settings or index settings code for config files

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

and examine setting file

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

and user control code is

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

Upvotes: 3

Views: 3912

Answers (2)

Martijn van der Put
Martijn van der Put

Reputation: 4082

In your DocumentType add a field "includeInSearchIndex" of type true/false. Then add this field in your Examine index configuration

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

Then use a create a custom query to search for everything where this field is not checked.

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

Check out this page for more info about the Examine index and the search queries

Upvotes: 3

Nathalie De Hertogh
Nathalie De Hertogh

Reputation: 75

If you want to exclude a node type just put this between the IndexSet tag

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

more info on codeplex examine

Upvotes: 4

Related Questions