I have some trouble with the examine sitesearch in Umbraco 7.2.2. The sitesearch is working when I only use the attributes of the result like Id and Name.
When I use the folowing code the searchresults stays empty. I can't find any solution...
@{
string searchTerm = Request.QueryString["keywords"];
if (String.IsNullOrWhiteSpace(searchTerm))
{
searchTerm = "";
}
var searcher = ExamineManager.Instance;
var searchCriteria = searcher.CreateSearchCriteria();
var query = searchCriteria.GroupedOr(new[] { "nodeName", "name", "title", "bodyText", "seo" }, searchTerm).Compile();
var searchResults = searcher.Search(query).Where(r => r["__IndexType"] == "content").ToList();
}
@if (@searchResults.Any())
{ ... Do stuff with it ...}
Is this a old code snippet? Or am I doing something wrong?
I think you need to specify the index you want to search. By default there are 3 searchers configured by Umbraco (in examinesettings.config) . InternalSearcher, InternalMemberSearcher and ExternalSearcher. For searching on your site you will need to use the ExternalSearcher because this one only searches through published content.
You specify which searcher to use like this :
var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"]
I've added Daves sugestion and included all the variables in this post.
@Ismail: If I change the code to your sugestion I get a error:
Compiler Error Message: CS0103: The name 'IndexTypes' does not exist in the current context
@{
string searchTerm = Request.QueryString["keywords"];
if (String.IsNullOrWhiteSpace(searchTerm))
{
searchTerm = "";
}
var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
var searchCriteria = searcher.CreateSearchCriteria();
var query = searchCriteria.GroupedOr(new[] {"nodeName", "title", "subTitle", "contentgrid", "mainHeader", "contentgrid","metaTitle" }, searchTerm).Compile();
var searchResults = searcher.Search(query).Where(r => r["__IndexType"] == "content").ToList();
}
<p>
@searcher.ToString()<br/><br/>
@searchCriteria.ToString()<br/><br/>
@query.ToString()<br/><br/>
@searchResults.ToString()<br/><br/>
</p>
I can see the generated lucene query, can you download luke (https://code.google.com/p/luke/downloads/list need 3.5.0 you will also need to have java installed) and open the index with that and then run the generated query see if that works.
Sitesearch with examine
Hi all,
I have some trouble with the examine sitesearch in Umbraco 7.2.2. The sitesearch is working when I only use the attributes of the result like Id and Name.
When I use the folowing code the searchresults stays empty. I can't find any solution...
Is this a old code snippet? Or am I doing something wrong?
Frans
edit: oops, wrong topic....
I think you need to specify the index you want to search. By default there are 3 searchers configured by Umbraco (in examinesettings.config) . InternalSearcher, InternalMemberSearcher and ExternalSearcher. For searching on your site you will need to use the ExternalSearcher because this one only searches through published content.
You specify which searcher to use like this :
Dave
Frans,
One other thing you do not need to use linq to specifically search on content so the line
Is not needed, you can do
searcher.CreateSearchCriteria(IndexTypes.Content);
also in your searcher.Search(query)
that should be
query.Compile()
If you stll get no results then after the search line can you do
and post back here the generated lucene query that will give indication as to what is going on.
Regards
Ismail
Hi Ismail,
Is it not needed to specify a searcher to use ?
Dave
Thanks for the reply's guys,
I've added Daves sugestion and included all the variables in this post.
@Ismail: If I change the code to your sugestion I get a error: Compiler Error Message: CS0103: The name 'IndexTypes' does not exist in the current context
searcher: UmbracoExamine.UmbracoExamineSearcher
searchCriteria: { SearchIndexType: , LuceneQuery: +(nodeName:ipsum title:ipsum subTitle:ipsum contentgrid:ipsum mainHeader:ipsum contentgrid:ipsum metaTitle:ipsum) }
query: { SearchIndexType: , LuceneQuery: +(nodeName:ipsum title:ipsum subTitle:ipsum contentgrid:ipsum mainHeader:ipsum contentgrid:ipsum metaTitle:ipsum) }
searchResults: System.Collections.Generic.List`1[Examine.SearchResult]
Thanks
Francs,
You need one of these usings
using Examine;
using Examine.LuceneEngine.SearchCriteria;
using Examine.Providers;
using Examine.SearchCriteria;
using UmbracoExamine;
not sure which ;-}
I can see the generated lucene query, can you download luke (https://code.google.com/p/luke/downloads/list need 3.5.0 you will also need to have java installed) and open the index with that and then run the generated query see if that works.
is working on a reply...