One index, one document, multiple nodes

Questions, comments, discussions. Over time certain topics might be moved to their own category.
Post Reply
jere
Posts: 5
Joined: Thu Jun 13, 2019 2:02 pm

One index, one document, multiple nodes

Post by jere » Sun Aug 11, 2019 7:36 pm

I want to have the same document show up in multiple nodes of an index.

As a concrete example, imagine that I use tags as date markers. A document may have multiple dates and thus multiple tags. A contract has a start and an end date, for example. If I tag that contract with 2019-01-01 and with 2019-06-01 and I use the following index template:

Code: Select all

{% for tag in document.tags.all %}{{tag.label}}{% endfor %}
Then instead of two index nodes, one of 2019-01-01 and one of 2019-06-01, I end up with one node of 2019-01-012019-06-01.

How can I create an index that will do what I want? I'm open to using metadata or whatever fields are more appropriate if this is an abuse of tags. :D But I would still like the index.

For this, I don't care which date is which. The dates may not correspond to anything that I wish to label. It would just be tagged with a date that is relevant to that particular document.

User avatar
rosarior
Posts: 317
Joined: Tue Aug 21, 2018 3:28 am

Re: One index, one document, multiple nodes

Post by rosarior » Tue Aug 13, 2019 12:47 am

The template work by substitution therefore any loop in the template will execute for all items but only once per document. To be able to have a document appear in multiple times, multiple indexes would need to be created. If the number of dates is static, for example, two dates, then two indexes would need to be created. One that uses the first date tag and the second index would use the second index tag. If the number of dates is not defined and can be none, or many then that would not be possible right now.

Your use case is interesting and has sparked a conversation about the possibility of allowing multiple templating engine backends and letting users select which engine to use for each index. Another possibility is to add a field or checkbox to the index template node that will indicate to the index that it should iterate for the number of values of the template of that level.

Post Reply