Does anyone know why the OR is not working for me?
Here is the full code of the simple search. I'm going to add more search parameters later so this is why I'm using examine search over using the umbraco helpers to get the nodes.
Code..
public static List<Examine.SearchResult> GetSearchResults()
{
var searcher = Examine.ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
var criteria = searcher.CreateSearchCriteria();
criteria.NodeTypeAlias("car").Or().NodeTypeAlias("boat");
List<Examine.SearchResult> searchResults = searcher.Search(criteria).ToList();
return searchResults;
}
To help everyone out there experiencing this issue I found an answer on another thread. Thanks Tim for solving this for me.
Click here for the other thread
Basically I had to change
var criteria = searcher.CreateSearchCriteria();
To
var criteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
For some reason the Or statements get ignored unless you set the default operator.
Here is the full search code now working...
public static List<Examine.SearchResult> GetSearchResults()
{
var searcher = Examine.ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
var criteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
criteria.NodeTypeAlias("car").Or().NodeTypeAlias("boat");
List<Examine.SearchResult> searchResults = searcher.Search(criteria).ToList();
return searchResults;
}
Hope this saves someone a bit of time solving the same problem.
I have a similar search scenario and for that I use a IBooleanOperation with a GroupedOr as shown below.
var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
var criteria = searcher.CreateSearchCriteria(IndexTypes.Content, BooleanOperation.And);
@* only look for documents of type CommitteeMember or DelegationMember *@
IBooleanOperation query = criteria.GroupedOr(new string[] { "nodeTypeAlias" }, new string[] { "committeeMember", "delegationMember" });
@* add filter to only find those linked to current MP*@
query = query
.And().Field("linkSearch", Model.Content.Id.ToString());
List<Examine.SearchResult> searchResults = searcher.Search(query.Compile()).ToList();
Rule of thumb - any examine queries, look for posts by Ismail Mayat and Shannon Deminick (author of Examine). I've learned a lot from their posts on this forum and the series of blogs Ismail wrote on the Cogworks blog (start with Examiness hints and tips from the trenches part 1 - Umbraco Examine)
var searcher = index.GetSearcher();
var criteria = searcher.CreateQuery(IndexTypes.Content, BooleanOperation.Or);
var examineQuery = criteria.NodeTypeAlias("contentPage").Or().NodeTypeAlias("blogDetailsPage").Or().NodeTypeAlias("eventDetailsPage").Or().NodeTypeAlias("officeDetailsPage").Or().NodeTypeAlias("sectorDetailsPage").Or().NodeTypeAlias("serviceDetailsPage").Or().NodeTypeAlias("staffDetailsPage");
Umbraco Examine Search - Searching with Multiple NodeTypeAlias
Hi,
I am having a few troubles getting Examine to search by multiple NodeTypeAlias.
I am basically wanting to search based on all vehicle types boat, car, plane etc.
My query works with a single NodeTypeAlias Eg.
When I try an or statement it just searches the first item in the or Eg.
if I reverse I just returns the boats Eg.
The total of boats and cars should be 10 Results but for some reason the search is ignoring the second half of the query.
I have also tried the following code and got the exact same issues. Eg
Does anyone know why the OR is not working for me?
Here is the full code of the simple search. I'm going to add more search parameters later so this is why I'm using examine search over using the umbraco helpers to get the nodes.
Code..
Thanks for your help in advance
Kind Regards
David
Hi,
To help everyone out there experiencing this issue I found an answer on another thread. Thanks Tim for solving this for me. Click here for the other thread
Basically I had to change
To
For some reason the Or statements get ignored unless you set the default operator.
Here is the full search code now working...
Hope this saves someone a bit of time solving the same problem.
Thanks
David
I have a similar search scenario and for that I use a IBooleanOperation with a GroupedOr as shown below.
HTH
Ver
Thanks veronica I will give this code a go.
I've been relying on guesswork when it comes to examine and learning as I go. This is pretty helpful.
I wish we could rate peoples responses.
Kind Regards
David
Rule of thumb - any examine queries, look for posts by Ismail Mayat and Shannon Deminick (author of Examine). I've learned a lot from their posts on this forum and the series of blogs Ismail wrote on the Cogworks blog (start with Examiness hints and tips from the trenches part 1 - Umbraco Examine)
Ver
I also posted a blog article about this here. https://www.umbrajobs.com/blog/posts/2020/july/umbraco-8-examine-how-to-search-multiple-doctypes/
This is the code you need.
Hi David. Found your blog post first and then this.
If I copy your code it complains that NodeTypeAlias does not exist.
Has it been removed in Umbraco 8 or do I need an extension?
Cheers, Josef
Came here with a similar question, for Umbraco 11 which has subtly different syntax.
This code works for me - based on the U11 examine quick start - but extended to exclude some node types from results:
is working on a reply...