I have some troubles getting correct searchresults when using Examine.
It seems some words are just not returned, even though they are included in the index (which I checked with Luke toolbox). My search criteria look something like this
The searchTerm variable is the searchterm entered in the searchbox on the site, with "*" added at the beginning and end of the variable. I have enabled the leadingwildcard in the examineindex.config. Without this option barely any result is returned.
The main problem now is that when I enter a searchterm, sometimes it returns results, but other times it doesn't. If I search for a string "I like strawberries" it returns the pages where the phrase "I like strawberries" is used. But when I search for a similar string, like "you like apples" it can very well return nothing at all even though that sentence is used on multiplepages and can be found using the Luke toolbox (so it is in the Index).
I've tried lowering the treshold in the Fuzzyoption, but this seems to return only results that don't seem to have any relation to the searchterms, but still doesn't return the pages where the string can be found.
Searching on part of the string (for example "you" or "apples" will return the page in the search results. At first I thought spaces could be the problem, but it doesn't explain why other strings with spaces are returned normally.
I'm pretty new to Umbraco, and now I am running a bit out of clues. Currently I am using version 4.11.9
var searchCriteria = ExamineManager.Instance.CreateSearchCriteria(IndexTypes.Content, Examine.SearchCriteria.BooleanOperation.Or); var query = searchCriteria
I've ommitted a number of fields, the search should include some more fields, but for testing I only use contentText and content.
Does anyone have a clue that could nudge me in the right direction. I've already improved the results by including wildcardsearches, but I'm still nog quite there yet.
And is there a way I can push a raw query to Lucene. If I try the raw query I compile in Luke Tool it seems to give decent results. Now I only have to find a way to use this query to execute. Somewhere along the way it seems to mess up the results, but I cannot find out where.
I've found out the actual querystring that is parsed to the lucenesearch.
+((contentText:you like apples) contentText:you like apples* content:you like apples* contentText:you like apples~0.3 content:you like apples~0.3) +__IndexType:content
When this is executed, it returns zero results on the website. In the Luke toolbox however it returns 5 results.
var count = HttpContext.Request.Params["count"] ?? "0";
var searcher = ExamineManager.Instance.SearchProviderCollection["WebsiteSearcher"];
var searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
ISearchCriteria query = null;
var term = model.SearchText;
var luceneString = "nodeName:";
query = searchCriteria.RawQuery(term);
var searchResults = searcher.Search(query);
ViewBag.countItem = searchResults.TotalItemCount;
var resultCollection = searchResults.Skip(Int32.Parse(count)).Take(10);
How to get correct searchresults with examine
I have some troubles getting correct searchresults when using Examine.
It seems some words are just not returned, even though they are included in the index (which I checked with Luke toolbox).
My search criteria look something like this
.Field("contentText", searchTerm.Fuzzy(0.5f)).Or()
.Field("contentText", searchTerm.MultipleCharacterWildcardFuzzy(0.3f)
The searchTerm variable is the searchterm entered in the searchbox on the site, with "*" added at the beginning and end of the variable. I have enabled the leadingwildcard in the examineindex.config. Without this option barely any result is returned.
The main problem now is that when I enter a searchterm, sometimes it returns results, but other times it doesn't.
If I search for a string "I like strawberries" it returns the pages where the phrase "I like strawberries" is used. But when I search for a similar string, like "you like apples" it can very well return nothing at all even though that sentence is used on multiplepages and can be found using the Luke toolbox (so it is in the Index).
I've tried lowering the treshold in the Fuzzyoption, but this seems to return only results that don't seem to have any relation to the searchterms, but still doesn't return the pages where the string can be found.
Searching on part of the string (for example "you" or "apples" will return the page in the search results. At first I thought spaces could be the problem, but it doesn't explain why other strings with spaces are returned normally.
I'm pretty new to Umbraco, and now I am running a bit out of clues. Currently I am using version 4.11.9
The function I use looks something like this
Examine.Providers.BaseSearchProvider baseSearchProvider = ExamineManager.Instance.DefaultSearchProvider;
IEnumerable<SearchResult> nodesPre = null;
List<SearchResult> nodes = new List<SearchResult>();
Lucene.Net.Search.Searcher luceneSearcher = null;
var searchCriteria = ExamineManager.Instance.CreateSearchCriteria(IndexTypes.Content, Examine.SearchCriteria.BooleanOperation.Or);
var query = searchCriteria
.Field("contentText",searchTerm.MultipleCharacterWildcard()).Or()
.Field("content", searchTerm.MultipleCharacterWildcard()).Or()
.Field("contentText", searchTerm.Fuzzy(0.3f)).Or()
.Field("content", searchTerm.Fuzzy(0.3f))
.Compile();
var results = baseSearchProvider.Search(query); //.OrderByDescending(x => x.Score)
luceneSearcher = ((Examine.LuceneEngine.SearchResults)results).LuceneSearcher;
nodesPre = results.OrderByDescending(x => x.Score);
I've ommitted a number of fields, the search should include some more fields, but for testing I only use contentText and content.
Does anyone have a clue that could nudge me in the right direction. I've already improved the results by including wildcardsearches, but I'm still nog quite there yet.
Hi Danny,
1) You can try to install Examine Manager package and test your search results without your code just from the admin part.
2) As said Aaron Powell on this post : http://our.umbraco.org/forum/developers/extending-umbraco/16893-Examine-MultipleCharacterWildcard()-on-a-word-with-an-apostrophe
You probably need to call Escape before you use the Wildcard. I've never tested with apostrophized queries though
Thanks, Alex
And how can I call Escape?
And is there a way I can push a raw query to Lucene. If I try the raw query I compile in Luke Tool it seems to give decent results. Now I only have to find a way to use this query to execute. Somewhere along the way it seems to mess up the results, but I cannot find out where.
var results = baseSearchProvider.Search(query); //.OrderByDescending(x => x.Score) luceneSearcher = ((Examine.LuceneEngine.SearchResults)results).LuceneSearcher; nodesPre = results.OrderByDescending(x => x.Score);
This is what I am currently doing to return results.
I've found out the actual querystring that is parsed to the lucenesearch.
+((contentText:you like apples) contentText:you like apples* content:you like apples* contentText:you like apples~0.3 content:you like apples~0.3) +__IndexType:content
When this is executed, it returns zero results on the website. In the Luke toolbox however it returns 5 results.
var results = baseSearchProvider.Search(query); //.OrderByDescending(x => x.Score) luceneSearcher = ((Examine.LuceneEngine.SearchResults)results).LuceneSearcher; nodesPre = results.OrderByDescending(x => x.Score);
this is the part that executes the query, and something goes wrong here. But I cannot find out what.
It has been a while since I have been trying to get this fixed. But unfortunately it still doesn't work properly.
does anyone have an example of a properly working searchfunction? I have used the sample posted above, but it doesn't return proper results.
currenlty I use the following query
This should return the correct data, but it doesn't, randomly searchwords seem to be omitted, even though they are in the index.
Does anyone have an idea how to fix this?
Anyone?
Hi Danny,
It's working example:
Thanks, Danny
is working on a reply...