0

I am building a search component in solr , and want to get the results on the basis of how relevant (most occured ) that word is in the particular field , i am filtering the results on a Content field , here is the 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)).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;
    }

Suppose i search for the keyword "DHS" , and from this query i am getting the results , but that are not sorted on the basis of relevancy of the "DHS" words . The results should be in order of the most occurence of the keyword in the content field. I tried the termcomponent by adding terms.fl=content_t&terms.list=dhs&terms.sort=count into the query , but didn`t get any success.

  • You really shouldn't try and second guess the search algorithms like this – Mark Cassidy Sep 8 at 18:42
  • then what should i do ? – Rohan Bhateja Sep 8 at 19:03
  • Let the search engine do, what the search engine is designed to do – Mark Cassidy Sep 8 at 19:10
  • what .... solr can't do that ?? :( – Rohan Bhateja Sep 8 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.