you should just implement case when your searchQuery is null or empty, so you need else block and code for retrieving all nodes (baseSearchProvider or your implementation without any specific boosting, filtering etc.).
Your code is filling nodes collection only if searchQuery is not null or empty.
Just remind to refactor it a little bit to not duplicate the same chunks of code.
Thank you Marcin for your answer...I already tried to implement an else block, but I didn't found what write in the "searchTerm" string or how to change code to get all results.
For example I tried with "*", and with "?" but I receive always an YSOD page with this error:
Lucene.Net.QueryParsers.ParseException: '*' or '?' not allowed as first character in WildcardQuery
I'm using this results_page code because is a part of uSkinned...so...I only would to add my custom code to get all results when user don't write any search terms.
With your indications, I change my code:
try
{
if (!String.IsNullOrEmpty(searchTerm))
{
//nodes = baseSearchProvider.Search(searchTerm, true);
var searchCriteria = Examine.ExamineManager.Instance.CreateSearchCriteria(Examine.SearchCriteria.BooleanOperation.Or);
//Boost matches that contain all search terms higher
var luceneStringNodeName = "nodeName:";
luceneStringNodeName += "(+" + searchTerm.Replace(" ", " +") + ")^5 ";
luceneStringNodeName += "nodeName:" + searchTerm;
//Boost matches that contain all search terms higher
var luceneStringBodyText = "bodyText:";
luceneStringBodyText += "(+" + searchTerm.Replace(" ", " +") + ")^5 ";
luceneStringBodyText += "bodyText:" + searchTerm;
var query = searchCriteria.RawQuery(luceneStringNodeName + " OR " + luceneStringBodyText);
var results = baseSearchProvider.Search(query); //.OrderByDescending(x => x.Score)
luceneSearcher = ((Examine.LuceneEngine.SearchResults)results).LuceneSearcher;
nodes = results.OrderByDescending(x => x.Score);
}
else
{
var searchCriteria = baseSearchProvider.CreateSearchCriteria(UmbracoExamine.IndexTypes.Content);
var results = baseSearchProvider.Search(searchCriteria);
luceneSearcher = ((Examine.LuceneEngine.SearchResults)results).LuceneSearcher;
nodes = results.OrderByDescending(x => x.Score);
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
The actual result is: NO DOCUMENT FOUND.
But if you see the screenshot, you can see that there are 7 nodes in the Index.
Examin Search and empty querystring
Hi to all, my actual result partial view can show results only if the querystring isn't empty (or null).
Now I need to extend this search to show all nodes, when I have an empty querystring.
I tried to enable wildcards and used * or ? but I always receive YSOD page.
This is my actual code:
How can I change this code to show all nodes when I receive an empty querystring?
Thanks for support.
Adriano
Hey Adriano,
you should just implement case when your searchQuery is null or empty, so you need else block and code for retrieving all nodes (baseSearchProvider or your implementation without any specific boosting, filtering etc.).
Your code is filling nodes collection only if searchQuery is not null or empty.
Just remind to refactor it a little bit to not duplicate the same chunks of code.
Thank you Marcin for your answer...I already tried to implement an else block, but I didn't found what write in the "searchTerm" string or how to change code to get all results.
For example I tried with "*", and with "?" but I receive always an YSOD page with this error:
Lucene.Net.QueryParsers.ParseException: '*' or '?' not allowed as first character in WildcardQuery
Do you help me?
I have not big experience with examine.
Thanks Adriano
Adriano,
Couple of things:
Its already sorted by score you are adding extra over head by sorting again with linq. You do not need this.
Also not sure why you are using raw query and all the string manipulation when you can do it with the examine fluent api.
Anyhow to get all content when no query then in the else do:
var results = baseSearchProvider.Search(searchCriteria);
I'm using this results_page code because is a part of uSkinned...so...I only would to add my custom code to get all results when user don't write any search terms.
With your indications, I change my code:
The actual result is: NO DOCUMENT FOUND.
But if you see the screenshot, you can see that there are 7 nodes in the Index.
Adriano,
Before line
Can you do searchCriteria.ToString() then paste back here the output. I want to see the generated query.
Regards
Ismail
This is the output.
{ SearchIndexType: content, LuceneQuery: }
Adriano
Instead of using Examine to bring back all pages in the site, couldn't you just use a standard Umbraco query? eg.
Dan,
Good point.
Hi Dan...good suggestion. I was so determined to want to resolve the problem with Examine that I haven't thought at this solution :-)
Thank you very much.
I will take this solution!
Thank yout to all Bye
Adriano,
Argghh. Ok I thought that would work. The quickest thing then would be todo:
var query = criteria.GroupedOr(new List
Replace nodetype1 2 with your node types. Then do
var results = baseSearchProvider.Search(query);
is working on a reply...