//nodename being passed is AriticlePage Document Type Alias Name - "ArticlePage"
var Searcher = ExamineManager.Instance.SearchProviderCollection["ArticlePageSearcher"];
var searchCriteria = Searcher.CreateSearchCriteria();
searchCriteria.Field("nodeTypeAlias", nodeName)
.And()
.Field("articleTitle", searchString.Escape())
.Or()
.Field("articleSummary", searchString.Escape())
.Or()
.Field("articleBody", searchString.Escape())
.Or()
.Field("activityTags", searchString.Escape())
.Or()
.Field("locationTags", searchString.Escape())
.Or()
.Field("contentTags", searchString.Escape())
.Or()
.Field("articleTitle", searchString.Fuzzy())
.Or()
.Field("articleSummary", searchString.Fuzzy())
.Or()
.Field("articleBody", searchString.Fuzzy())
.Or()
.Field("activityTags", searchString.Fuzzy())
.Or()
.Field("locationTags", searchString.Fuzzy())
.Or()
.Field("contentTags", searchString.Fuzzy());
var searchResults = Searcher.Search(searchCriteria).OrderByDescending(x => x.Score);
When I wire up the pages, call the search with the key word skiing, one result is shown in the search results which is as expected. The keyword skiing is present in artileTitle, articleSummary, articleBody of an article.
When I search for another keyword avalanche which is present in the same article but only present in the articleBody. No results is found. I thought that's very strange.
I open the Examine Dashboard in Umbraco, went to the ArticlePageSearcher clicked and open the search text box, searched for keywords skiing, yes correct result found, then searched for avalanche yes the correct result was found (same article as skiing)
So why is the code searching for skiing keyword correctly and bring up the correct results and not doing the same for avalanche?
Can someone please explain / help what I am doing wrong with the search using Examine in C# code given above??
The evidence points to an error with the searchcriteria generated via code(but you knew that!)
You don't appear to be calling .Compile() anywhere?
eg
var searchCriteria = Searcher.CreateSearchCriteria();
var query = searchCriteria.Field("nodeName","hello").Or().Field("metaTitle","hello").Compile();
var searchResults = Searcher.Search(query);
so I would try compiling the search criteria first, then seeing what the raw lucene syntax is being generated by the criteria, then use the lucene syntax in the back office search, enabling you to either immediately see what the issue is from the syntax / allow you to tweak the syntax to see what does work, then work back to update your c# fluent examine criteria to generate that syntax (or just use the raw lucene query to generate the searchcriteria)
Adding ".compile()" at the end of searchCrieria as suggested by you.
It made no difference.
It can search the keyword "skiing" and bring up the results correctly.
When I search for "avalanche", it brings up no results.
I did check the processed query in Luke.Net (Lucene Index checking tool). The query runs properly. It brings up results for keyword skiing but not for avalanche. I don't know how to fine tune / tweak to get results for avalanche.
In the Umbraco backoffice (Examine Dashboard). The "ArticleSearcher" brings up the results correctly for "avalanche" keyword.
So I am perplexed as to why the query (as mentioned above) can work in one situation (when keyword is skiing) and not for the other (when keyword is avalanche).
Do you suggest any fine tuning tips that I should try for tweaking the processed query in Luke.Net or even for the code changes?
and from your explanation of the scenario, the avalanche word does not appear in the title of the page, only in the articleBody, hence it is not being returned for this search.
I believe It is the And() in your searchcriteria that is adding the +
but confirm this by searching in backoffice using lucene syntax option for:
I think the search is now bringing the results that doesn't contain the keyword searched for. In other words, that its not correctly searching through the articles at all.
I am not sure that changing And() to Or() worked really well.
I even tried removing .Fuzzy() logic, it doesn't matter, just brings too many irrelevant search results.
So hopefully you are now getting to grip with the lucene syntax and how the search works, if you have + next to a field it means it much contain the term, you are now getting matches on nodeTypeAlias, being an articlePage and therefore returning all results!
I think you want to explore the GroupedOr and GroupedAnd helpers in examine
basically you want to search multiple fields for a single term.
eg
var searchTerm = "avalaunche";
var query = searchCriteria.Field("nodeTypeAlias", nodeName).And().GroupedOr(new string[] { "articleTitle", "articleSummary","articleBody","activityTags","locationTags","contentTags"}, searchTerm ).Compile();
and check the Lucene syntax this generates...
... but if you want to boost the result if the term appears in articleTitle or locationTags you might have to split this out... eg
var searchTerm = "avalaunche";
var query = searchCriteria.Field("nodeTypeAlias", nodeName).And().GroupedOr(new string[] { "articleTitle", "locationTags"}, searchTerm.Boost(10)).Or().GroupedOr(new string[] {"articleSummary","articleBody","activityTags","locationTags","contentTags"}, searchTerm.Boost(2)).Compile();
generally with this kind of search to refine it, I would be constantly checking the results of 20 to 30 key search terms, playing with the Lucene syntax that the examine query generates, and adjusting accordingly, but hard to advise without the data in front of me!
hope that gets closer to you finding your avalanche!
Perhaps someone can assist me with examine. I have the following node structure: a HomePage node and under that node I have various pages, including the articulate node.
When I search the site for search terms located on the various pages, the search works great, and returns the results. However, when I try searching for items in the articulate blog nothing shows up.
I am using the ezSearch plugin, which uses examine.
Examine Search issues Umbraco v 7.5.12
I am facing issue with Examine search using Lucene engine.
I have an "ArticlePage" document type defined with following user index fields:
Here is the config details: ExamineIndex.config
ExamineSettings.Config (other settings are present, but pasting the relevant setting configure for search):
The code for searching:
When I wire up the pages, call the search with the key word skiing, one result is shown in the search results which is as expected. The keyword skiing is present in artileTitle, articleSummary, articleBody of an article.
When I search for another keyword avalanche which is present in the same article but only present in the articleBody. No results is found. I thought that's very strange.
I open the Examine Dashboard in Umbraco, went to the ArticlePageSearcher clicked and open the search text box, searched for keywords skiing, yes correct result found, then searched for avalanche yes the correct result was found (same article as skiing)
So why is the code searching for skiing keyword correctly and bring up the correct results and not doing the same for avalanche?
Can someone please explain / help what I am doing wrong with the search using Examine in C# code given above??
Please ask if you need further clarification
Can I get some answers from fellow Umbraco developers about this topic? Is the issue mentioned clear enough to investigate?
Hi Deepak
Hmm, it's hard for me to spot the problem here.
The evidence points to an error with the searchcriteria generated via code(but you knew that!)
You don't appear to be calling .Compile() anywhere?
eg
so I would try compiling the search criteria first, then seeing what the raw lucene syntax is being generated by the criteria, then use the lucene syntax in the back office search, enabling you to either immediately see what the issue is from the syntax / allow you to tweak the syntax to see what does work, then work back to update your c# fluent examine criteria to generate that syntax (or just use the raw lucene query to generate the searchcriteria)
if that helps
regards
Marc
Hi Marc,
Thanks for replying to my query.
I have tried your suggestions.
Adding ".compile()" at the end of searchCrieria as suggested by you. It made no difference.
It can search the keyword "skiing" and bring up the results correctly.
When I search for "avalanche", it brings up no results.
I did check the processed query in Luke.Net (Lucene Index checking tool). The query runs properly. It brings up results for keyword skiing but not for avalanche. I don't know how to fine tune / tweak to get results for avalanche.
Here is the processed query for keyword "skiing":
Here is the processed query for keyword "avalanche":
In the Umbraco backoffice (Examine Dashboard). The "ArticleSearcher" brings up the results correctly for "avalanche" keyword.
So I am perplexed as to why the query (as mentioned above) can work in one situation (when keyword is skiing) and not for the other (when keyword is avalanche).
Do you suggest any fine tuning tips that I should try for tweaking the processed query in Luke.Net or even for the code changes?
Hi Deepak
In the raw lucene syntax you have posted your search criteria produces
The + in lucene syntax means the term MUST appear in that field:
https://lucene.apache.org/core/294/queryparsersyntax.html#+
and from your explanation of the scenario, the avalanche word does not appear in the title of the page, only in the articleBody, hence it is not being returned for this search.
I believe It is the And() in your searchcriteria that is adding the +
but confirm this by searching in backoffice using lucene syntax option for:
+nodeTypeAlias:articlepage articleTitle:avalanche articleSummary:avalanche articleBody:avalanche activityTags:avalanche locationTags:avalanche contentTags:avalanche articleTitle:avalanche~0.5 articleSummary:avalanche~0.5 articleBody:avalanche~0.5 activityTags:avalanche~0.5 locationTags:avalanche~0.5 contentTags:avalanche~0.5
without the + and check you get the article...
regrds
Marc
Marc,
Yes And() was the issue. Resolving And() into Or() worked and brought up three references to the article in the results.
Can you please repost the link to https://lucene.apache.org/core/294/queryparsersyntax.html#+ ? It would help to check the syntax before I post it as an issue.
Thanks for your help.
regards,
Deepak
Great!
Here is the link:
https://lucene.apache.org/core/294/queryparsersyntax.html
regards
Marc
Marc,
I think the search is now bringing the results that doesn't contain the keyword searched for. In other words, that its not correctly searching through the articles at all.
I am not sure that changing And() to Or() worked really well.
I even tried removing .Fuzzy() logic, it doesn't matter, just brings too many irrelevant search results.
Can you please help? Thanks,
Deepak
Hi Deepak
So hopefully you are now getting to grip with the lucene syntax and how the search works, if you have + next to a field it means it much contain the term, you are now getting matches on nodeTypeAlias, being an articlePage and therefore returning all results!
I think you want to explore the GroupedOr and GroupedAnd helpers in examine
https://umbraco.com/blog/examining-examine/
basically you want to search multiple fields for a single term.
eg
and check the Lucene syntax this generates...
... but if you want to boost the result if the term appears in articleTitle or locationTags you might have to split this out... eg
generally with this kind of search to refine it, I would be constantly checking the results of 20 to 30 key search terms, playing with the Lucene syntax that the examine query generates, and adjusting accordingly, but hard to advise without the data in front of me!
hope that gets closer to you finding your avalanche!
Hi Marc,
Thanks so much for coming back and providing some further pointers on how to change the search for better results.
I will try out your suggestions and come back to you if I am still stuck.
Thanks.
Deepak
Perhaps someone can assist me with examine. I have the following node structure: a HomePage node and under that node I have various pages, including the articulate node.
When I search the site for search terms located on the various pages, the search works great, and returns the results. However, when I try searching for items in the articulate blog nothing shows up.
I am using the ezSearch plugin, which uses examine.
is working on a reply...