Our monthly Virtual Happy Hour is happening this week, Fri Feb 23!

Try our conversational search powered by Generative AI!

WebContent classes SearchMetaData and filtering with metadata value.

Vote:
 

Hi,

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.

"SearchMetaData": {
        "date": {
            "StringValue$$string": "2016-09-29",
            "$type": "EPiServer.Find.IndexValue, EPiServer.Find",
            "___types": [
                "EPiServer.Find.IndexValue",
                "System.Object"
            ]
        },
}

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

#171989
Nov 23, 2016 7:02
Vote:
 

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

#171994
Nov 23, 2016 8:58
Vote:
 

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;
            IndexValue dateValue;
            DateTime date;

            if (metaData.TryGetValue("date", out dateValue))
            {
                if (DateTime.TryParse(dateValue.StringValue, out date))
                {
                    return date;
                }

                return null;
            }

            return null;
        }

On InitializableModule:

SearchClient.Instance.Conventions.ForInstancesOf<WebContent>()
.IncludeField(x => x.PublishedDate());

And on search controller:

query = query.Filter(x => (x as WebContent).PublishedDate().After(date));



-Joni

#172038
Edited, Nov 24, 2016 9:05
Vote:
 

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.

#172052
Nov 24, 2016 13:59
Vote:
 

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.

#172054
Nov 24, 2016 14:10
Vote:
 

No problem. But as I said, I haven't tested it myself. Let us know how it worked out!

#172055
Nov 24, 2016 14:18
Vote:
 

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.

#172168
Nov 25, 2016 8:50
Vote:
 

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.

#172193
Nov 25, 2016 14:32
Vote:
 

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?

#172350
Dec 01, 2016 6:45
Vote:
 

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.

 

#173687
Jan 05, 2017 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.