Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello all,
I am using Examine to return some nodes, all is fine except when I add Or() to the query.. it returns no results.
Am I using it wrongly ?
results = searcher.CreateQuery() .Field("path", Model.Path.ToString().MultipleCharacterWildcard()).And() .Field("__IndexType", "content").And() .Field("articleCountry", (countryUDI != null ? countryUDI.ToString() : "")).And() .Field("parentID", selectedYear != 0 ? selectedYear : "").And() .Field("nodeName", selectedTerm != "" ? searchTerm.ToString() : searchTerm.ToString()).Or() .Field("title", selectedTerm != "" ? searchTerm.ToString() : searchTerm.ToString()).And() .Field("__NodeTypeAlias", "newsLetter").Execute();
Thanks
Hi Saif,
Please can you try this query instead and see if it works for you. I have tried with GroupedOr
var fields = new List<string> { "nodeName", "title" }; results = searcher.CreateQuery() .Field("path", Model.Path.ToString().MultipleCharacterWildcard()).And() .Field("__IndexType", "content").And() .Field("articleCountry", (countryUDI != null ? countryUDI.ToString() : "")).And() .Field("parentID", selectedYear != 0 ? selectedYear : "").And() .GroupedOr(fields, selectedTerm != "" ? searchTerm.ToString() : searchTerm.ToString()).And() .Field("__NodeTypeAlias", "newsLetter").Execute();
It worked! ..
but with this way, but it didn't return all nodes when the search term was null or empty string..
how could I make the query return results when the search term is empty string?
We can have if check to fix this issue.
var fields = new List<string> { "nodeName", "title" }; if (!string.IsNullOrEmpty(searchTerm)) { results = searcher.CreateQuery() .Field("path", Model.Path.ToString().MultipleCharacterWildcard()).And() .Field("__IndexType", "content").And() .Field("articleCountry", (countryUDI != null ? countryUDI.ToString() : "")).And() .Field("parentID", selectedYear != 0 ? selectedYear : "").And() .GroupedOr(fields, selectedTerm != "" ? searchTerm.ToString() : searchTerm.ToString()).And() .Field("__NodeTypeAlias", "newsLetter").Execute(); } else { results = searcher.CreateQuery() .Field("path", Model.Path.ToString().MultipleCharacterWildcard()).And() .Field("__IndexType", "content").And() .Field("articleCountry", (countryUDI != null ? countryUDI.ToString() : "")).And() .Field("parentID", selectedYear != 0 ? selectedYear : "").And() .Field("__NodeTypeAlias", "newsLetter").Execute(); }
Hi Shaishav,
We have already tried that, but we are searching for a better way, isn't there? because we duplicate some code.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Or() in Examine doesn't work with me | Umbraco 8
Hello all,
I am using Examine to return some nodes, all is fine except when I add Or() to the query.. it returns no results.
Am I using it wrongly ?
Thanks
Hi Saif,
Please can you try this query instead and see if it works for you. I have tried with GroupedOr
It worked! ..
but with this way, but it didn't return all nodes when the search term was null or empty string..
how could I make the query return results when the search term is empty string?
Hi Saif,
We can have if check to fix this issue.
Hi Shaishav,
We have already tried that, but we are searching for a better way, isn't there? because we duplicate some code.
is working on a reply...