Mayan EDMS Index Reference

Community contributed guides or tutorials for multiple topics like installations for other operating systems or platforms, monitoring, log aggregation, etc.
taro
Posts: 0
Joined: Mon May 25, 2020 7:13 am

Re: Mayan EDMS Index Reference

Post by taro »

Hi all,

I'm quite new to Mayan and I'm trying to learn how to use this wonderful index features. I have a question about adding child node. Below is what I want to do:

1. Any document comes in will have invoice number as custom metadata.

2. The first level of the child node will check the first character of the invoice number and set an index for it. For example:

{% if document.metadata_value_of.invoice_number.0 == "A" %}Accounting
{% elif document.metadata_value_of.invoice_number.0 == "H" %}Human Resources
{% endif %}

3. Then, I add another child node under number 2 above (this new node is the child of either "Accounting" or Human Resources"). I want to add the condition to this node like:

{% if document.metadata_value_of.invoice_number|slice:"1:3"== "NE" %}New Employee
{% elif document.metadata_value_of.invoice_number|slice:"1:3" == "CT" %}Contract
{% endif %}

However, it seems that the condition doesn't work at all on number 3. I tried to remove all if/else and make the template like:

document.metadata_value_of.invoice_number|slice:"1:3"

And it works. Can anyone let me know if there is no way we can get condition work on child node of another child node?
mattwebboz
Posts: 1
Joined: Sat Oct 03, 2020 10:45 am

Re: Mayan EDMS index reference post

Post by mattwebboz »

monadnock wrote:
> Is there a way to view Django template errors or get some troubleshooting
> output when index templates fail to produce the desired results? They
> aren't in the docker logs output and I cannot find them in the menus...
>
> It's very frustrating to play "guess the problem" with a
> moderately complex index template.
>
> Example:
> [code]
> {% if document.metadata_value_of.date_issued %}
>
> {% if document.metadata_value_of.date_issued|slice:"5:7" in
> '10,11,12' %}
> FY{{
> document.metadata_value_of.date_issued|slice:":4"|add:"1"
> }}
> {% elif document.metadata_value_of.date_issued|slice:"5:7"
> in '01,02,03,04,05,06,07,08,09' %}
> FY{{ document.metadata_value_of.date_issued|slice:":4" }}
>
> {% else %}
>
> Unknown
>
> {% endif %}
>
> {% elif document.file_metadata_value_of.ModifyDate %}
>
> {% if document.file_metadata_value_of.ModifyDate|slice:"5:7"
> in '10,11,12' %}
> FY{{
> document.file_metadata_value_of.exiftool_ModifyDate|slice:":4"|add:"1"
> }}
> {% elif
> document.file_metadata_value_of.exiftool_ModifyDate|slice:"5:7"
> in '01,02,03,04,05,06,07,08,09' %}
> FY{{
> document.file_metadata_value_of.exiftool_ModifyDate|slice:":4" }}
>
> {% else %}
>
> Unknown
>
> {% endif %}
>
> {% else %}
>
> Unknown
>
> {% endif %}
> [/code]
>
> Fairly straight forward fiscal year calculation (possibly from metadata
> *or* file metadata). Produces no documents, but it's not possible to tell
> why. If there's no errors in the template, then at worst all the documents
> should show up under "Unknown"...
>
> Is there a better way to test for the existance of optional metadata? Is
> there another template problem? It's very difficult to track down these
> sorts of issues.
Hey - don't have an answer regarding debugging, but using your example, I was able to create a Financial Year index. I've included it here in anyone finds it useful:

{% if document.metadata_value_of.TransactionDate|slice:"5:7" in '07,08,09,10,11,12' %}
FY{{ document.metadata_value_of.TransactionDate|slice:"0:4"|add:"1" }}
{% elif document.metadata_value_of.TransactionDate|slice:"5:7" in '01,02,03,04,05,06' %}
FY{{ document.metadata_value_of.TransactionDate|slice:"0:4"|add:"0"}}
{% else %}
No Tr Date
{% endif %}

Cheers,
Matt.
lynxy
Posts: 2
Joined: Sat Nov 07, 2020 9:49 pm

Re: Mayan EDMS Index Reference

Post by lynxy »

First of all thank you KevinPawsey for this valuable information! You opened my eyes to just how powerful indexes can be.

I've created a modified version of the "people mentioned" index supporting many variations and support for OCR errors. This took quite a while to figure out how to do so I figured I'd post it here to save others some time!

Version 3.5 introduced regular expressions (regex) template tags, but no documentation on how to use them:

> A set of regular expression tags were added. These are regex_findall, regex_match, regex_search, and regex_sub. Each regular expression tag support the flags ascii, ignorecase, locale, multiline, dotall, and verbose.

I haven't figured out how to pass flags to the functions, but in my case it doesn't matter much since I can just pipe to |lower.

Sometimes OCR may interpret some characters incorrectly, either because of font family, size, smudges, etc. Some examples of this are:
- "a" as an "o" or visa-versa
- "l" as an "i" or "1"
- "w" as "vv"
- "u" as a "v"

Here is what I'm using:

{% with ocr=document.latest_version.ocr_content|join:" "|lower %}{% regex_search "j[ao]hn( +(w|vv)(\.|[uv]rt)?)?( +sm[li1]th)?" ocr as result %}{% if result %}{{ result.0 }}{% endif %}{% endwith %}

This would match any of the following variations (and many more!):
- john
- john smith
- john w smith
- john w. smith
- john wurt smith
- jahn
- jahn smlth
- jahn vv sm1th
- jahn vv. smlth
- jahn vvurt smith
- jahn wvrt smith

The {% with %} block is just there to show how variables can be easily stored and updated in just one spot for anyone that doesn't know about it (makes a lot more sense when used in KevinPawsey's original template).

{{ result.0 }} is pretty self explanatory if you know how regex capture groups work. It can of course be replaced with regular text, i.e. John Smith.

Hope if helps someone, good luck!
Post Reply