Hi, I want to be able to search an Examine index for a couple of different node type aliases. Unfortunately my searches only search on the first alias passed in.
var searcher = ExamineManager.Instance.SearchProviderCollection[Model.ExamineSearchProvider];
var criteria = searcher.CreateSearchCriteria(IndexTypes.Content);
var filter = (IBooleanOperation)null;
var nodeTypeQuery = criteria.NodeTypeAlias(Model.DocumentTypesAlias[0]).Or();
foreach (var docTypeAlias in Model.DocumentTypesAlias)
{
if (docTypeAlias == Model.DocumentTypesAlias[0]) continue;
nodeTypeQuery.NodeTypeAlias(docTypeAlias).Or();
}
filter = nodeTypeQuery.OrderByDescending("updateDate");
var results = searcher.Search(filter.Compile());
An update to this, the document types have some different fields. Can a search not return items of different DocTypes if their properties are not exactly the same?
Heya, did you find the reason or, even better, a solution for this? Just stumbeled upon the very same problem. I tried it filtering on the field "__NodeTypeAlias", still only getting hits for whichever comes first.
var criteria = ExamineManager.Instance.SearchProviderCollection["ContentSearcher"].CreateSearchCriteria(); var filter = criteria.Field("__NodeTypeAlias", "dtevent").Or().Field("__NodeTypeAlias", "artikkel");
If you don't specify that the default operator should be OR, the first one will be required and the second will be optional, rather than both being optional!
To make that happen, just change the first line of your code to the following:
var criteria = ExamineManager.Instance.SearchProviderCollection["ContentSearcher"].CreateSearchCriteria(BooleanOperation.Or);
Examine Search on NodeTypes
Hi, I want to be able to search an Examine index for a couple of different node type aliases. Unfortunately my searches only search on the first alias passed in.
An update to this, the document types have some different fields. Can a search not return items of different DocTypes if their properties are not exactly the same?
If so, is there anyway around this?
Heya, did you find the reason or, even better, a solution for this? Just stumbeled upon the very same problem. I tried it filtering on the field "__NodeTypeAlias", still only getting hits for whichever comes first.
var criteria = ExamineManager.Instance.SearchProviderCollection["ContentSearcher"].CreateSearchCriteria();
var filter = criteria.Field("__NodeTypeAlias", "dtevent").Or().Field("__NodeTypeAlias", "artikkel");
No luck.
Hi Carl,
Have a look at this blog post: http://umbraco.com/follow-us/blog-archive/2011/9/16/examining-examine.aspx
If you don't specify that the default operator should be OR, the first one will be required and the second will be optional, rather than both being optional!
To make that happen, just change the first line of your code to the following:
var criteria = ExamineManager.Instance.SearchProviderCollection["ContentSearcher"].CreateSearchCriteria(BooleanOperation.Or);
And hopefully it should work how you want it to!
Hope that helps!
:)
Thats brilliant! :)
Thank you Tim, worked like a charm. :)
No worries! Glad you got it working!
:)
is working on a reply...