3

I have the following setup:

  • I'm indexing Sitecore items (Employee) in Solr
  • I have the computed field "checkins" of type stringArray set in the index

Checkins is list of datetime values I get from external service and I'm filling the computed field with them.

I extended the SearchResultItem with the property:

[IndexField("checkins")]
public IEnumerable<DateTime> Checkins { get; set; }

And when I query the index, property is filled with dates.

The question is now, how do I search on this property? I want to pick a date (dateFrom) and get all the Employees that have a checkin date after this date.

I tried this:

builder = builder.And(i => i.Checkins.Any(d => d >= request.DateFrom));

but I'm getting "Unsupported lambda in Any call." error.

Is there any way I can search in date array?

1 Answer 1

3

I found the answer on StackOverflow: https://stackoverflow.com/questions/33301106/query-lucene-index-against-ienumerable-field

In short, instead of using

IEnumerable<DateTime> Checkins

you can use

[IgnoreIndexFieldAttribute]
DateTime Checkins

And then you can search using

i.Checkins >= request.DateFrom

Checkins property will not show anything and is good only for searching. If you need to retrieve the list of dates, use another property as IEnumerable<DateTime> and use it only for retrieval.

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.