Umbraco search is wired. Dynamic searchQuery dosen't work but static does?
Hello. I'm adjusting / exploring my searchfunction on a page, and I stumbled upon a strange problem.
When I make my SearchQuery dynamic and shearchs for results, it says for some keywords that there are no results, but I know that there should be some.
var searchFields = new[] { "nodeName", "name", "title", "bodyText", "seo" };
var criteria = _searchService.CreateSearchCriteria();
var query2 = new StringBuilder();
query2.AppendFormat("-{0}:1 ", "umbracoNaviHide");
// Set search path
var contentPathFilter = string.Format("__IndexType:{0} -template:0", UmbracoExamine.IndexTypes.Content);
query2.AppendFormat("+({0}) ", contentPathFilter);
// Ensure page contains all search terms in some way
var searchTems = Tokenize(model);
foreach (var term in searchTems)
{
var groupedOr = new StringBuilder();
foreach (var searchField in searchFields)
{
groupedOr.AppendFormat("{0}:{1}* ", searchField, term);
}
query2.Append("+(" + groupedOr + ") ");
}
// Rank content based on positon of search terms in fields
for (var i = 0; i < searchFields.Count(); i++)
{
foreach (var term in searchTems)
{
query2.AppendFormat("{0}:{1}*^{2} ", searchFields[i], term, searchFields.Count() - i);
}
}
var criteria2 = criteria.RawQuery(query2.ToString());
var results = _searchService.Search(criteria2).TakeWhile(x => x.Score > 0.05f).OrderByDescending(x => x.Score).ToList();
Umbraco search is wired. Dynamic searchQuery dosen't work but static does?
Hello. I'm adjusting / exploring my searchfunction on a page, and I stumbled upon a strange problem.
When I make my SearchQuery dynamic and shearchs for results, it says for some keywords that there are no results, but I know that there should be some.
But when I insert the same SearchQuery static there are now two results?
Does anyone know how this can be?
Hi André ,
Try this code snippet :
is working on a reply...