November Happy Hour will be moved to Thursday December 5th.

Getting SearchMetaData

Vote:
 

I currently have objects with the following SearchMetaData

 "SearchMetaData": {
        "published_date": {
            "StringValue$$string": "2009-02-26T23:00:00Z",
            "___types": [
                "EPiServer.Find.IndexValue",
                "System.Object"
            ],
            "$type": "EPiServer.Find.IndexValue, EPiServer.Find"
        },
        "updated_date": {
            "StringValue$$string": "2012-01-10T13:26:01Z",
            "___types": [
                "EPiServer.Find.IndexValue",
                "System.Object"
            ],
            "$type": "EPiServer.Find.IndexValue, EPiServer.Find"
        },
		.......

Trubble is when trying to get this updated_date. It seems to be saved in a string fromat looking at the index but When I try and get it in the projection I get a "Argument type do not match" error.

query.Select(x => new SearchHit
			{
				Title = x.SearchTitle,
				Url = x.SearchHitUrl,
				Text = x.SearchSummary.AsCropped(200),
				PublishedDate = x.SearchMetaData["updated_date"].DateTimeValue ?? DateTime.MaxValue,
				Test = x.SearchMetaData["updated_date"]
				Test2 = x.SearchMetaData["updated_date"].StringValue
			}).GetResult();

I did some testing and the PublishedDate line works, but will always be null.

The Test line will work and give me EPiServer.Find.IndexValue and checking this property on the object will have the date in it's StringValue. 

The Test2 line will give me the "Argument type do not match" error.

So my question is. How am I suppose to get the date? I could ofcourse get the hole IndexValue and then get it. But then the question becomes how do I get the value when ordering by date?

#111979
Oct 21, 2014 16:12
Vote:
 

Try parsing the string to a DateTime in the projection:

query.Select(x => new SearchHit
            {
                Title = x.SearchTitle,
                Url = x.SearchHitUrl,
                Text = x.SearchSummary.AsCropped(200),
                PublishedDate = x.SearchMetaData["updated_date"].DateTimeValue ?? DateTime.Parse(x.SearchMetaData["updated_date"].StringValue)
            }).GetResult();
#113942
Dec 02, 2014 8:55
* 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.