Index problem - Built in date filter not working

When things don't work as they should.
Post Reply
fgdutoit
Posts: 2
Joined: Sat May 23, 2020 9:23 am

Index problem - Built in date filter not working

Post by fgdutoit »

I have a metadata type set up as follow:
{
"default": null,
"id": 4,
"label": "Date of Service",
"lookup": "",
"name": "DateofService",
"parser": "mayan.apps.metadata.parsers.DateParser",
"url": "http://10.165.35.11:8034/api/metadata_types/4/",
"validation": ""
}
I'm trying to create and index on the metadata type set up as follow:
"label": "Service date",
"node_templates": [
{
"enabled": true,
"expression": "",
"id": 10,
"index": 4,
"level": 0,
"link_documents": false,
"parent": null
},
{
"enabled": true,
"expression": "{{ document.metadata_value_of.DateofService|date:\"Y\"}}",
"id": 11,
"index": 4,
"level": 1,
"link_documents": false,
"parent": 10
}

Expected result: Index level according to year part of date of service metadata value.
Actual result: 0 documents indexed.

Where is my error?

User avatar
michael
Developer
Developer
Posts: 17
Joined: Sun Apr 19, 2020 6:21 am

Re: Index problem - Built in date filter not working

Post by michael »

The metadata is stored and returned as a string and not a datetime object. Instead of the date filter you need to use the slice filter to extract the elements od the date. For more details look at the template of the default date index that is created when Mayan is first installed.

https://docs.djangoproject.com/en/3.0/r ... ins/#slice

fgdutoit
Posts: 2
Joined: Sat May 23, 2020 9:23 am

Re: Index problem - Built in date filter not working

Post by fgdutoit »

Thanks for the reply Michael.

My default installation index on a datetime object.
"label": "Creation date",
"node_templates": [
{
"enabled": true,
"expression": "",
"id": 1,
"index": 1,
"level": 0,
"link_documents": false,
"parent": null
},
{
"enabled": true,
"expression": "{{ document.date_added|date:\"Y\" }}",
"id": 2,
"index": 1,
"level": 1,
"link_documents": false,
"parent": 1
},
{
"enabled": true,
"expression": "{{ document.date_added|date:\"m\" }}",
"id": 3,
"index": 1,
"level": 2,
"link_documents": true,
"parent": 2
}
Is it by design that all document metadata will always be returned as strings irrespective of using parsing when storing?

Post Reply