0

I have a template EventPage defined several attributes, datetime, single-line text, droplist etc. I defined a EventPageSearchItem inherit from SearchResultItem as follows:

public class EventPageSearchItem : SearchResultItem
{
    [IndexField("TopicTags")]
    public IEnumerable<string> TopicTags { get; set; }

    [IndexField("EventDateTime")]
    public DateTime EventDateTime { get; set; }

    [IndexField("EventType")]
    public string EventType { get; set; }
    
    [IndexField("EventTitle")]
    public string EventTitle { get; set; }
    
    [IndexField("EventDetail")]
    public string EventDetail { get; set; }
}

I have a code to search for event pages with EventDate, Topics and EventType, just found out that all other field types works fine but the EventType (droplist) always come back as null

using (var context = selectedIndex.CreateSearchContext())
{
    var tags = new List<string>();
    if (!string.IsNullOrEmpty(topic))
        tags.Add(topic);

    var searchFolder = Sitecore.Context.Database.GetItem("/sitecore/content/fedpartnership/home/pages");

    var fromDate = fromEventDate.HasValue ? fromEventDate.Value : DateTime.MinValue;
    var toDate = toEventDate.HasValue ? toEventDate.Value : DateTime.MaxValue;

    var searchResults = context.GetQueryable<EventPageSearchItem>()
            .Where(x => x.Paths.Contains(searchFolder.ID)
                && x.TemplateId == Sitecore.Data.ID.Parse(PFPTemplateIDs.EventPage)
                && x.EventDateTime >= fromDate
                && x.EventDateTime <= toDate);

    if (!string.IsNullOrEmpty(topic))
        searchResults = searchResults.Where(x => x.TopicTags.Contains(topic));

    if (!string.IsNullOrEmpty(eventType))
        searchResults = searchResults.Where(x => x.EventType == eventType);

    if (sortedBy == "alpha")
    {
        searchResults = searchResults.OrderBy(x => x.EventTitle);
    }
    else
    {
        searchResults = searchResults.OrderByDescending(x => x.EventDateTime);
    }

but in the fields collection of the result, I do see the eventtype is populated enter image description here

Can someone help to identify what step I did wrong? how can I map that droplist in the EventPageSearchItem?

Thank you very much!

3
  • Have you tried with any other droplist field? Is it the same issue?
    – Marek Musielak
    Nov 14, 2023 at 7:34
  • I have another field PageType is also droplist and it behaves the same
    – John
    Nov 14, 2023 at 19:36
  • Double-check the field name used in the IndexField attribute for EventType. Ensure it matches the actual name of the Droplist field in Sitecore. Any case sensitivity should also be matched accurately. Dec 1, 2023 at 18:49

1 Answer 1

0

I would suggest you to try few things,

  • First of all, go and check if this content is indexed in your Solr Admin (or any search that you are using).
  • If yes, try to match index property name and all. You can also check raw query in Logs. And see what result do you get when you execute it in Solr Admin. This should give you clue.
  • If it is not in indexes, then assuming that you have created computed field for TopicTags, you can debug that code.
  • I had issues in indexed data with multilingual setup in past. Not sure what version was that. I had to explicitly pass current language in computed field logic for multi-selection field. Just sharing in case you see something similar.

Go step by step to find out where it is breaking. This will help you to narrow down suspicious area. Hope this helps !

5
  • localhost:8983/solr/#/~cores/XP0_web_index shows no issues, which folder has the LOG? The computed field TopicTags is working, only droplist field type not working
    – John
    Nov 14, 2023 at 19:51
  • you webroot logs should have files named Search.log.xxx... . You can check what query is being executed in Solr from your website. Nov 15, 2023 at 6:23
  • Can you check if it would work with IEnumerable<string> EventType property? I know that DropList is a single item selection, but maybe the mapping expect collection?
    – Marek Musielak
    Nov 15, 2023 at 7:49
  • changed to IEnumerable<string> EventType to test, value still null
    – John
    Nov 15, 2023 at 14:29
  • Check this out - sitecore.stackexchange.com/questions/29423/…. First do confirm in Solr admin that your indexes have this field value. If yes, then recheck you configuration for computed field. Try to returnType="string" and reindex to see if you are getting any value. Nov 16, 2023 at 7:12

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.