My examine search seems to be having issues with whitespace. I'm creating a search form of Members. Users should be able to search on node name which could could include a space
var searcher = ExamineManager.Instance.SearchProviderCollection["InternalMemberSearcher"];
var searchCriteria = searcher.CreateSearchCriteria();
var query = searchCriteria.Field("nodeName", searchQuery.MultipleCharacterWildcard()).Compile();
var searchResults = searcher.Search(query);
The above works fine when I search without a space but with a space returns no results.
For example, I have two members, Tommy Tester and John Doe. "Tommy" and "John" brings back results but "Tommy T", or anything after a space doesn't.
Wildcard the term and on initial criteria creation you may need to set to default or sorry no PC ATM I'm on hols so doing this from phone and old man's memory ;-)
I've tweaked that, to And conditions. For my purposes this acts as a filter. So no criteria entered - all results are returned and the more the user enters, the result get restricted down.
Working solution is here :
var searcher = ExamineManager.Instance.SearchProviderCollection["InternalMemberSearcher"];
var searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.And);
var q_split = searchQuery.Split(' ');
var fieldsToSearch = new[]{"nodeName"};
IBooleanOperation filter = searchCriteria.GroupedAnd(fieldsToSearch, q_split.First().MultipleCharacterWildcard());
foreach (var term in q_split.Skip(1))
{
filter = filter.And().GroupedAnd(fieldsToSearch, term.MultipleCharacterWildcard());
}
var searchResults = searcher.Search(filter.Compile());
Examine Search with whitespace
Hi All,
My examine search seems to be having issues with whitespace. I'm creating a search form of Members. Users should be able to search on node name which could could include a space
The above works fine when I search without a space but with a space returns no results.
For example, I have two members, Tommy Tester and John Doe. "Tommy" and "John" brings back results but "Tommy T", or anything after a space doesn't.
Thanks
Check if your search term has space if it does then split and do or on each item in the query. Without split its doing phrase search.
I found a post of yours a while back stating this https://our.umbraco.org/forum/developers/api-questions/26004-Examine-Search-with-whitespace-no-good
What is the type of your queryToBuild in that example? and what should I then pass into searcher.Search?
Here is what I have so far which obviously doesn't work!
Wildcard the term and on initial criteria creation you may need to set to default or sorry no PC ATM I'm on hols so doing this from phone and old man's memory ;-)
I think I've managed to get it working how I want it to. I found a good post here http://sleslie.me/2014/search-umbraco-using-examine-and-razor/ by Scott Leslie which helped me out.
I've tweaked that, to And conditions. For my purposes this acts as a filter. So no criteria entered - all results are returned and the more the user enters, the result get restricted down.
Working solution is here :
is working on a reply...