0

I'm having issues with returning results from Solr that have a forward slash (/), if I search for something like - "Valid Publication Name 2019/20", it shows 0 results, while running "Valid Publication Name 2019" it brings back the result. The code is similar to the following:

            var predicate = PredicateBuilder.True<SearchResultModel>();

           //// Search the whole phrase with fuzzy logic to include special characters - LIKE
            predicate = predicate.Or(x => x.Title.Like(searchText)).Boost(6.0f); //title get the highest priority
            predicate = predicate.Or(x => x.Name.Like(searchText)).Boost(5.5f);
            predicate = predicate.Or(x => x.Content.Like(searchText)).Boost(4.0f);
            predicate = predicate.Or(x => x.Renderpagecontent.Like(searchText)).Boost(3.0f);
            
            BooleanQuery.MaxClauseCount = int.MaxValue;
            var allResults = context.GetQueryable<SearchResultModel>).Where(predicate).Take(maxNumResults).ToList()

As per Solr documentation a forward slash doesn't need escaping, so not sure why this is happening? Please could someone help!!

Thanks in advance.

1 Answer 1

2

Can you make below changes on search predicate while creating Solr query.

var predicate = PredicateBuilder.False<SearchResultModel>();
predicate = predicate.Or(x => x.Title.Contains(searchText));

BooleanQuery.MaxClauseCount = int.MaxValue;
var allResults = context.GetQueryable<SearchResultModel>).Where(predicate).Take(maxNumResults).ToList()

This will sent query to Solr in below format.

?q==title_t:(*Valid* *Publication* *Name* *2019* *20*)

Let me know in case you face any issues. Hope this helps!!!

12
  • Thanks CKhanna, but this did not seem to work, actually I also tried to remove all the other fields from predicate, with the changes you suggested, so predicate is as below: predicate = predicate.Or(x => x.Title.Like(searchText)).Boost(10000.0f); //title get the highest priority Commented Jun 11 at 16:52
  • I've done the reindexing also, but it doesn't even return anything with a query like "Valid Publication Name". Not sure what I'm missing, do I need to do any other config changes for title field please? Commented Jun 11 at 16:54
  • I've also tried using the Solr API directly, the URL is similar to following: localhost:8983/solr/sitecore_web_content/… Publication Name 2020/21" localhost:8983/solr/sitecore_web_content/… Publication Name" Both return results similar to following: { "responseHeader":{ "status":0, "QTime":0, "params":{ "q":"title_s:\"Valid Pulication NAme 2020/21\""}}, "response":{"numFound":0,"start":0,"docs":[] }} Commented Jun 11 at 16:58
  • @MaverickHT Did you checked the field is getting indexed with suffix '_s' in the Solr and can you also check the Solr query in the Search logs.
    – ckhanna
    Commented Jun 11 at 16:58
  • Schema in solr the index doesn't have this fld, are any other config changes to get this done, following is config: <defaultSolrIndexConfiguration type="Sitecore.ContentSearch.SolrProvider.SolrIndexConfiguration, Sitecore.ContentSearch.SolrProvider"> <fieldMap ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/fieldMap" > <fieldNames hint="raw:AddFieldByFieldName"> <field fieldName="title" returnType="string"/> </fieldNames> </fieldMap> Thanks for your help! Commented Jun 11 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.