Index examples

Index of document types

Permissions required

  • The “Create new document indexes” permission is required for this action.
  • The “Edit document indexes” permission is required for this action, globally of via an ACL for a document index.
  • The “Edit document types” permission is required for this action, globally of via an ACL for a document type.

This index will create one level for each document type in the system and place links to the document of each respective type.

  1. Go to the System ‣ Setup ‣ Indexes menu.

  2. Create a new index using Actions > Create new.

  3. Give it a label to describe it, and an internal name. The internal name is used when referencing this index in other parts of the system.

  4. Press the Template link of the newly created index.

  5. Select New child node to create a new level in which the following template code will be entered.

    {{ document.document_type }}
    
  6. Save the template.

  7. Click on Document types and associate this index with existing document types in the system.

  8. Finally go to Tools ‣ Rebuild indexes to execute the index template. The rebuild process is only necessary when changes are made to the index templates. Otherwise they update automatically whenever a new document is uploaded or existing documents properties are modified.

  9. A new index should appear under Indexes menu.

You can also program different behavior based on the different document types, by use a comparison and a conditional statement. As the document_type itself is not a string you cannot directly use that for that comparison. You will have to use the label of the document type.

For example:

{% if document.document_type.label == "Invoice" or document.document_type.label == "Letter" %}
Correspondence
{% else %}
{{ document.document_type }}
{% endif %}

This will create and index level for each document type. Except for documents of types “Invoice” and “Letter”, these will now go into the level “Correspondence”.

Index document by department, taken from the first character of the invoice number metadata

Requires one index node with the template:

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

Nested date index from a date contained in a metadata

Assuming the metadata type is named date_issued with a date format of YYYY-MM-DD. The target is to have two levels: one for years and another sub level for months.

First level: Year

{{ document.metadata_value_of.date_issued|slice:"0:4" }}

Second level: Months

{{ document.metadata_value_of.date_issued|slice:"5:7" }}

Optional: Third level: Day

{{ document.metadata_value_of.date_issued|slice:"8:10" }}

Index by OCR content

This example indexes documents in a “quarterly report” level if they have the fragment “quarterly report” in the OCR text:

{% if "quarterly report" in document.latest_version.ocr_content|join:" "|lower %}Quarterly reports{% endif %}

The same applies to text content extracted for the document:

{% if "quarterly report" in document.latest_version.content|join:" "|lower %}Quarterly reports{% endif %}

Index documents not found in any cabinet

{% if document.cabinets.count == 0 %}No Cabinets{% endif %}

Index documents not tagged

{% if document.tags.count == 0 %}No Tags{% endif %}

Index documents specifically, by the year of a metadata field otherwise by their uploaded year

{% for tag in document.tags.all %}{% if tag.label == "Taxes" %}{% if document.metadata_value_of.tax_year|length_is:"4" %}{{ document.metadata_value_of.tax_year }}{% else %}{{ document.date_added|date:"Y" }}{% endif %}{% endif %}{% endfor %}