I was building query on the basis of the occurence/relevancy of the terms present in a field and got one issue , suppose i searched for a keyword "text" in the content field , and i want to sort the results on the basis of the relevancy of the term present in the field , for ex , if that keyword is present more times then that document will be listed on the top . here is my code
var queryableResultItems = context.GetQueryable<GlobalSearchResultItem>()
.Where(x => x.Language.Equals(Sitecore.Context.Language.Name, StringComparison.InvariantCultureIgnoreCase)).Where(UseSearchComponents.GetTemplatesFilterPredicate(Guid.Parse(TemplateConstants.BlogPreviewTemplate))).Where(UseSearchComponents.GetSearchFilters(keyword, searchType)).Skip((Int32.Parse(pagenumber) - 1) * 12).Take(12).GetResults();
public static Expression<Func<GlobalSearchResultItem , bool>> GetSearchFilters(string Keyword,string searchType)
{
Expression<Func<GlobalSearchResultItem, bool>> filterSearch = x => true;
if(Keyword.IsTrimmedNullOrEmpty() || searchType.IsTrimmedNullOrEmpty())
{
return filterSearch;
}
Expression<Func<GlobalSearchResultItem, bool>> filterSearchText = x => true;
if (!string.IsNullOrEmpty(Keyword) && searchType=="exactly")
{
filterSearchText = filterSearchText.Or(x => x.Content.Contains(Keyword));
filterSearch = filterSearch.And(filterSearchText);
}
if(!string.IsNullOrEmpty(Keyword) && searchType == "allwords")
{
float slop = 1000000;
filterSearchText = filterSearchText.Or(x => x.Content.Like(Keyword,slop));
filterSearch = filterSearch.And(filterSearchText);
}
return filterSearch;
}
}
and then i used the termfreq("content_t","text") desc
function in the solr console , but i don`t know how to do it programatically in solr using the contentsearch api.
Some help would be apppreciated.
Thanks in advance.