I have implemented Search using Examine and was wondering if I passed in a collection of NodeId how I can filter these out from the results ?
I have been trying to replicate the logic used for "umbracoNodeHide" although not had any success
public Examine.ISearchResults SearchUsingExamine(string[] documentTypes, List<SearchGroup> searchGroups, List<string> PagesToExclude = null)
{
ISearchCriteria searchCriteria = ExamineManager.Instance.CreateSearchCriteria(BooleanOperation.And);
IBooleanOperation queryNodes = null;
//only shows results for visible documents.
queryNodes = searchCriteria.GroupedNot(new string[] {"umbracoNaviHide"}, "1");
//ToDo:Filter out pages in the PagesToExclude list.
if (documentTypes != null && documentTypes.Length > 0)
{
//only get results for documents of a certain type
queryNodes = queryNodes.And().GroupedOr(new string[] { _docTypeAliasFieldName }, documentTypes);
}
if (searchGroups != null && searchGroups.Any())
{
//in each search group it looks for a match where the specified fields contain any of the specified search terms
//usually would only have 1 search group, unless you want to filter out further, i.e. using categories as well as search terms
foreach (SearchGroup searchGroup in searchGroups)
{
queryNodes = queryNodes.And().GroupedOr(searchGroup.FieldsToSearchIn, searchGroup.SearchTerms);
}
}
//return the results of the search
You can declare queryNodes and searchCriteria implictly with "var".
Do you need the GroupedNot on the umbracoNaviHide check?
Since you are only comparing one field to "1".
var searchCriteria = ExamineManager.Instance.CreateSearchCriteria(BooleanOperation.Not);
var queryNodes = searchCriteria.Field("umbracoNaviHide", "1");
But yes, that works for filtering by nodeId, am sure that is efficient.
Other things I would consider doing is putting your Search Fields as an Enum, so they become strongly typed.
Examine Search, Filter collection of Pages
I have implemented Search using Examine and was wondering if I passed in a collection of NodeId how I can filter these out from the results ?
I have been trying to replicate the logic used for "umbracoNodeHide" although not had any success
Right, I have managed to achieve this by adding the following
I'm fairly sure their are more efficient ways of doing this, if any one could advise,
You can declare queryNodes and searchCriteria implictly with "var".
Do you need the GroupedNot on the umbracoNaviHide check? Since you are only comparing one field to "1".
But yes, that works for filtering by nodeId, am sure that is efficient.
Other things I would consider doing is putting your Search Fields as an Enum, so they become strongly typed.
is working on a reply...