We are using Unified search with connectors and we have two external sources to index. Both have SearchMetaData dates.
So I have tried to filter search results with the WebContent metadata date like show below.
"$type": "EPiServer.Find.IndexValue, EPiServer.Find",
},}Example query: query = query.Filter(x => DateTime.Parse((x as WebContent).SearchMetaData["date"].StringValue).After(date))I know that I can get dates out like this in views but it seems like the query won't return any hits if you try to filter this way.Is there any way to filter search results with metadata fields and how to do it if it's possible?Any help would be appreciated.Joni
Create an extension to WebContent where you fetch the value as a DateTime. Include the field when indexing. I think that should work. Check out the including fields documentation
Just got external content reindexed. Does the included field show up on the index? It's not there if it should be.
It doesn't seem to work yet. Maybe something wrong how I added the extension method and the field.
I have extension method:
public static DateTime? PublishedDate<T>(this T content)
var webContent = content as WebContent;
var metaData = webContent.SearchMetaData;
if (metaData.TryGetValue("date", out dateValue))
if (DateTime.TryParse(dateValue.StringValue, out date))
.IncludeField(x => x.PublishedDate());
And on search controller:
query = query.Filter(x => (x as WebContent).PublishedDate().After(date));
I have not tried including extra field with web content to be honest, but I don't see why it shouldn't work. Have you tried debugging while indexing to see if the extension actually returns the correct value?Optionally, try with a simpler extension method to see if it gets indexed.
And yes, you should indeed see the included field in the index.
Thank you for your replys.
I'll try your suggestions tomorrow. Good to know that it should work like that and added value should be visible in the index.
No problem. But as I said, I haven't tested it myself. Let us know how it worked out!
No luck extending WebContent with simple string field.
I tried to extend our base PageData class with the same string field with same code and it show up in the index just fine after reindex. So this is something to do with the WebContent class...
Tried to debug initializable module and it seemed to get the field and return type as it should.
I meant that you should debug the extension method while the content is indexed. I gues this is being indexed via the Find crawler connector? If so, debug while re-crawling.
I tried debugging indexing jobs also but the break points didn't get hit(Attach to Process -> w3wp.exe). Tested with "EPiServer Find Content Indexing Job" and through the EPiServer Find's Connectors menu. Is there some specific method to do this?
You cannot extend WebContent with extra fields. The connector crawling job is executed on the find server and not from your local webserver and the find server is not aware of any configuration to webcontent made in your InitializationModule.