0

The content search (using Examine) on our websites is broken. The issues can be separated into three distinct categories:

Search is returning deleted pages: I am not sure how to remove the deleted contents from the search result. Is there an way to add a filter criteria to exclude deleted pages?

Search is returning content from all the sites: We are running two websites for two different countries (Australia and New Zealand) in one Umbraco instance. The issue is that search result is returning pages from both the sites. We don't need AU pages on NZ search result and vice versa. How to create a search query to restrict it to a specific root node id?

Bringing up pages without a template: Some content nodes don't have templates associated with them and meant to be displayed as a part of a parent node. Is there an way to restrict the search to specific document types? But, if the content is found on a sub node, bring up the parent node with a specific doc type?

I am probably asking too many questions in one post, but I guess other users might have faced such issues before.

The code I am using till now:

private List<SiteSearchResult> GetSiteResults(string query, out int totalResults)
{
    var criteria = ExamineManager.Instance
        .SearchProviderCollection["WebSearcher"]
        .CreateSearchCriteria(IndexTypes.Content);
    var filter =
        criteria.GroupedOr(
            new[]
            {
                "nodeName", "heading", "content", "metaKeywords", "title", "umbracoNaviHide", "umbracoUrlName",
                "umbracoUrlAlias", "metaCategory", "metaDescription", "metaTags", "heading", "subHeading",
                "quote", "author", "socialCopy", "socialTitle", "socialTitle2", "thumbTitle", "thumbTitle2",
                "thumbCopy", "thumbQuote", "url", "location"
            }, query)
            .Compile();

    var searchResults =
        ExamineManager.Instance.SearchProviderCollection["WebSearcher"].Search(filter)
            .OrderByDescending(x => x.Score);
    totalResults = searchResults.Count();
    var results = new List<SiteSearchResult>();

    foreach (var item in searchResults)
    {
        var heading = "";
        var copy = "";
        var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);

        var url = umbracoHelper.Url(item.Id, UrlProviderMode.Relative);

        if (url.Length == 0)
        {
            continue;
        }

        if (url.StartsWith("/forms/"))
        {
            continue;
        }

        // Do many things here

        results.Add(r);
    }

    return results;
}
TejSoft
  • 3,213
  • 6
  • 34
  • 58

1 Answers1

2

Search is returning deleted pages:

Not sure if that helps, but you could just exclude the unpublished/protected results from the index. You can do that in your ExamineSettings.config file. For you it should look a something like that:

<add name="WebIndexer" 
     type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine" 
     supportUnpublished="false" 
     supportProtected="false" 
     analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" />

The supportUnpublished and supportProtected flags define if unpublished/protected content should be stored in the specific index.

Bringing up pages without a template

Again, you could possibly change your ExamineIndex.config file and just specify which document types should be indexed and which shouldn't. For example:

<IndexSet SetName="WebIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/{machinename}/Features/">
  <IndexAttributeFields>
    <add Name="id" EnableSorting="true" />
  </IndexAttributeFields>
  <IndexUserFields>     
    <add Name="exampleField" />
  </IndexUserFields>
  <IncludeNodeTypes>
    <add Name="DocumentType1" />
  </IncludeNodeTypes>
</IndexSet>

The aboved index will only containt nodes of document type "DocumentType1", what's more it will only store the "id" field (and enable sorting on it) from the system ones and "exampleField" from the fields defined by the user. You could also use EncludeNodeType to specify which document types should not land in the index.

Search is returning content from all the sites:

If the document types used in those two sites are different, then creating two separate indexes for each should solve it. If not, however, I currently have no knowledge of how to tackle this at the moment in a proper way. A quick fix might be adding a field to the doc type that holds a value, which specifies if the document is from NZ or AU region. Then you could add it to the index and filter on it when searching. Quite possibly there's a better way to do it though.

Examine Documentation

If you need some info about how to deal with Examine indexes and searchers, you could always look here.

Slowacki
  • 480
  • 7
  • 20