Thanks for your suggestions.. I had a closer look at the documentation and have now updated my code to the following, which search in the specified fields on multiple keywords.. and for area search in a single field for multiple values (selected checkbox values).
var searcher = ExamineManager.Instance.SearchProviderCollection["OffersSearcher"];
var searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
IBooleanOperation query = searchCriteria.NodeTypeAlias("offer");
var fieldsToSearch = new List<string> { "nodeName", "shortDescription", "offerCategory", "offerTypes", "offerProvider", "offerArea" };
if (!string.IsNullOrWhiteSpace(q))
{
var keywords = StringHelper.SplitKeyWords(q);
IBooleanOperation filter = query.And().GroupedOr(fieldsToSearch, keywords.Select(t => t.MultipleCharacterWildcard()).ToArray());
query = filter;
}
if (!string.IsNullOrEmpty(area))
{
var areaValues = StringHelper.SplitKeyWords(area, ',');
IBooleanOperation filter = query.And().GroupedOr(new string[] { "offerArea" }, areaValues.ToArray());
query = filter;
}
var results = searcher.Search(query.Compile());
Search single field using multiple keywords in Examine
I am trying to search in a single field in Examine if it match any of the values from a comma separated list of values.
Eg. it might be some regions/areas in Denmark like "midt, syd, vest".
So for example:
string area = "midt,syd"
At the moment I have the following, but it only return result for first value in the array (when splitted with comma).
It seems the query at the end is
__NodeTypeAlias:offer +(offerArea:midt) (offerArea:syd)
If I in Luke change the query to
__NodeTypeAlias:offer +(offerArea:midt offerArea:syd)
, then I get results for both regions/areas.Is there a way to get this output from Examine?
I am using Umbraco v7.5.11
/Bjarne
I think the problem lies with the way you are using the
.GroupedOr()
.I think you need to do
filter.GroupedOr(fieldsToSearch,keywords)
according to the documentation found here https://github.com/Shazwazza/Examine/wiki/Grouped-Operations#groupedorRelevant bit:
Hi Sven
Thanks for your suggestions.. I had a closer look at the documentation and have now updated my code to the following, which search in the specified fields on multiple keywords.. and for area search in a single field for multiple values (selected checkbox values).
Do you know if it is possible to combine
MultipleCharacterWildcard
andFuzzy
?For example:
but it only seems to use fuzzy and a keyword - and not matching start of a word.
A similar thread here: https://our.umbraco.org/forum/developers/api-questions/37433-MultipleCharacterWildcard-and-Boost-at-the-same-time-Examine
I have tried this myself a while ago but I didn't get it to work either.
is working on a reply...