4

I'm working on a Sitecore upgrade from 8.2 to 10.1, which includes replacing Lucene with Solr. I have a content listing page that allows filtering by content type as well as many other fields - these are OOTB Sitecore fields, not computed. I have this SearchResultItem defined:

public class ContentTypeSearchResultItem : Sitecore.ContentSearch.SearchTypes.SearchResultItem
{
    [Sitecore.ContentSearch.IndexField("region_sm")]
    [TypeConverter(typeof(IndexFieldEnumerableConverter))]
    public Guid Region { get; set; }

    [Sitecore.ContentSearch.IndexField("content_type_sm")]
    [TypeConverter(typeof(IndexFieldEnumerableConverter))]
    public IEnumerable<Guid> ContentType { get; set; }

 
}

One thing I changed initially was that the names had no suffixes, so I changed "content_type" to "content_type_sm" (this was after I got the Undefined error the first time)

My fields exist in Solr:

enter image description here

and in fact in another place in the site where I pull all items with a particular template ID, when I inspect the items while debugging, I can drill into the fields and see that they have the "content_type_sm" field and it is properly populated.

But on the listing page, my query which uses this code:

var contentTypePredicate = PredicateBuilder.True<ContentTypeSearchResultItem>();
foreach (var taxonomy in taxonomies)
{
     contentTypePredicate = contentTypePredicate.Or(x => x.ContentType.Contains(taxonomy));
}
predicate = predicate.And(contentTypePredicate);

...returns no results and I see the error in my logs, ERROR Solr Error : [undefined field content_type]

EDIT:

Manually updating the fieldMap fixed the issue:

<field fieldName="content_type" returnType="stringCollection"></field>
1
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Richard Seal
    Nov 1, 2022 at 18:52

1 Answer 1

3

As discussed in the comments, there is no need to add the "_sm" in ContentTypeSearchResultItem.

In your latest update, it looks like you are trying to map a stringcollection to an IEnumerable < Guid >

Please can you try changing index config to:

<field fieldName="content_type" returnType="guidCollection"></field>

And then update your SearchResult to:

[Sitecore.ContentSearch.IndexField("content_type")]
[TypeConverter(typeof(IndexFieldEnumerableConverter))]
public IEnumerable<Guid> ContentType { get; set; }

You will need to repopulate and rebuild the index.

Your Answer

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

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