Help with Find query

Vote:
 

Hello,

I have a page type that stores users birthday in mm/dd format as a string. There is no year.

I have a requirement to show the pages of the users who have their birthday today. I was wondering how would I go query for this since the stored birthday is not in Datetime format how can I split the value and match month and day with todays month and day.

I tried this but I cant get any match.

var query = _client.Search<IContent>();
var toSearch = DateTime.Today.Month.ToString("00") + "/" + DateTime.Today.Day.ToString("00");
var bdayFilter = _client.BuildFilter<PersonProfilePage>();
bdayFilter = bdayFilter.And(x => x.BirthDay.Match(toSearch));


var result = query
.Filter(x => x.MatchType(typeof(PersonProfilePage)))
.Filter(bdayFilter)
.Take(1000)
.GetContentResult();

#228015
Edited, Sep 17, 2020 16:39
Vote:
 

Have you checked that the birthday is indexed? Use the Find UI, or InspectInIndex.

SearchClient.Instance.Search<PersonProfilePage>()
.Filter(x=> x.BirthDay.Match("09/17"))
.Take(1000)
.GetContentResult();

If the birtday is indexed, try simplifiing your query as above.

#228019
Sep 17, 2020 20:37
Vote:
 

Thanks Tomas. The field was marked to exclude from indexing. After including it I can see the results.

Also is it the right way to get the info or any other preferred way in my scenario.

#228111
Edited, Sep 18, 2020 13:49
Tomas Hensrud Gulla - Sep 18, 2020 14:16
Excellent! :-)
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.