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;
}