0

I am facing a weird(might not be weird for experienced people) issue where ContentSearch API is returning null value for few fields while I can see the correct values in Solr. The fields whose values are returning as null are of String type because of Sitecore field type as Droplist and Treelist. Wondering if there is anything obvious I am missing somewhere?

Search Result Class:

public class BlogSearchModel 
{
    //Blog Specific
    [IndexField("title_t")]
    public string Title { get; set; }
    [IndexField("excerpt_t")]
    public string Excerpt { get; set; }
    [IndexField("body_t")]
    public string Body { get; set; }

    [IndexField("author_s")]
    public string Author { get; set; }

    [IndexField("category_s")]
    public string Category { get; set; }
    [IndexField("tags_sm")]
    public IEnumerable<string> TagID { get; set; }
}

Here Author, Category, TagID whose value is returning as Null have inherited templates.

The solr log shows the query as:

Solr Query - ?q=((site_sm:("xxxxx") AND _templates:("795b38b1aca6433fb5f1e02ee350857d")) AND (body_t:(*blog1*) OR title_t:(*blog1*) OR excerpt_t:(*blog1*))) AND _val_:__boost&start=0&rows=1000000&fl=tags,_templates,author_t,_fullpath,_name,__created_by_s,title_t,_template,site_sm,category_t,excerpt_t,_language,body_t,itemurl_t,_uniqueid,_datasource&fq=_indexname:(sitecore_master_index)&wt=xml

2
  • What is the search result item class code? Aug 4 at 13:15
  • thanks, @MarekMusielak. I have updated the question with the class definition. Aug 4 at 13:21
1

You don't need the suffix in the IndexField attribute here. The Sitecore Content Search API will (most of the time) add that in when it builds the search query. So it's probably doubling those up, you would see that in your search logs.

Build your model class like this:

public class BlogSearchModel 
{
    //Blog Specific
    [IndexField("title")]
    public string Title { get; set; }
    [IndexField("excerpt")]
    public string Excerpt { get; set; }
    [IndexField("body")]
    public string Body { get; set; }

    [IndexField("author")]
    public string Author { get; set; }

    [IndexField("category")]
    public string Category { get; set; }
    [IndexField("tags")]
    public IEnumerable<string> TagID { get; set; }
}
3
  • I did the changes in my model as per your suggestion without any luck. I am wondering if I am missing anything else.. Aug 4 at 17:41
  • I have updated the question with the query showing in the Solr log. It indeed seems that fields returned in the result are not exactly the same as showing in solr result. Aug 4 at 17:51
  • If you go to solr dashborad and in query part just search with template, do you see category and tagid there in search results? Aug 5 at 15:21

Your Answer

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

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