Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pivot resources using templates. (#1342)
* core: change pivoter to use templates instead of hard coded text extraction. Issue #1076 * Remove test value for repivot. * docs: add documentation for the pivot templates. * docs: add references to pivot templates.
- Loading branch information
Showing
18 changed files
with
476 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
.. _cookbook-pivot-templates: | ||
|
||
Pivot Templates | ||
=============== | ||
|
||
:ref:`guide-datamodel-query-model` uses database indices on special pivot | ||
columns and full text fields. | ||
|
||
These columns and text fields are extracted in a process called *pivoting*. | ||
This is done a short period after a resource has been updated. | ||
|
||
The content of the pivot columns is determined by a template. This template is | ||
called ``pivot/pivot.tpl`` (in ``mod_base``) and is rendered using a *catinclude*. | ||
This makes it possible to have your own unique indexing per category. | ||
|
||
The ``pivot/pivot.tpl`` template consists of multiple blocks. Each block corresponds | ||
to a pivot column. The block is rendered for determining the pivot’s content. | ||
|
||
The following blocks are defined: | ||
|
||
**a, b, c and d** | ||
|
||
These blocks are used for the full text index. Block *a* contains more | ||
important texts than block *b*, *c* or *d*. Per default the title and other | ||
essential texts are shown in block *a*, and block *d* is used for related | ||
texts (think titles of connected resources). | ||
|
||
The default pivot template uses the following catincluded templates for the | ||
different blocks: | ||
|
||
* ``pivot/_title_text.tpl`` for block *a* | ||
* ``pivot/_main_text.tpl`` for block *b* | ||
* ``pivot/_block_text.tpl`` for block *c* | ||
* ``pivot/_related_text.tpl`` for block *c* | ||
|
||
**title** | ||
|
||
The title used for database sorting etc. Per default the lowercased title in the selected | ||
pivot language or the default site language. | ||
|
||
**related_ids** | ||
|
||
The ids of all related resources and categories. This is a full text index used for | ||
finding resources that are similar to some other resource. | ||
All matching resource ids should be prefixed with ``zpo`` and category ids with ``zpc`` | ||
(for example ``zpo1234``). | ||
|
||
The catincluded template ``pivot/_related_ids.tpl`` is used for extracting these ids. | ||
This template also adds the id of the content group as a related resource. | ||
|
||
**address_street, address_city, address_postcode, address_state, address_country** | ||
|
||
The address to be used for searches. Defaults to the related ``address_…`` properties | ||
with a fallback to the ``mail_address_…`` properties. | ||
|
||
The country should be the two letter ISO code, not the country’s descriptive text. | ||
|
||
**name_first, name_surname** | ||
|
||
If the resource is a person then this should contain the first name and surname. | ||
|
||
**gender** | ||
|
||
The gender of the person, currently a single letter. For example: ``f``, ``m`` or ``?``. | ||
|
||
**date_start, date_end** | ||
|
||
The start or end date associated with the resource. This should be in a parseable format, which | ||
will be done automatically when echoing a date directly. Make sure UTC is used as the timezone (note that the timezone will be set to UTC when pivoting). | ||
|
||
**date_start_month_day, date_end_month_day** | ||
|
||
A four digit number representing the month and day for the date start and date end. Think of | ||
an index for birthdays, without exposing the birth year. | ||
|
||
Defaults to ``{{ id.date_start|date:"md" }}`` and ``{{ id.date_end|date:"md" }}``. | ||
|
||
**location_lat, location_lng** | ||
|
||
The latitude and longitude of the resource location. This should be empty or a floating point number. | ||
|
||
Defaults to ``{{ id.computed_location_lat|default:id.location_lat }}`` and ``{{ id.computed_location_lng|default:id.location_lng }}`` | ||
|
||
**date_repivot** | ||
|
||
The date and time this resource should be repivoted. This is useful if some resources (like events) should be indexed with lower priorities after a certain date. A pivot task will be scheduled at the specified date. | ||
Per default no repivot will be scheduled. | ||
|
||
|
||
See :ref:`cookbook-custom-pivots` for adding your own custom pivot columns. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
.. include:: meta-pivot-pivot.rst | ||
|
||
.. todo:: Not yet documented. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% for b in id.blocks %} | ||
{% for z_language in id.language|default:[z_language] %} | ||
{{ b.header }} {{ b.body }} | ||
{% endfor %} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{% for cat,_true in id.is_a %} | ||
{{ cat }} | ||
{% for z_language in id.language|default:[z_language] %} | ||
{{ m.rsc[cat].title }} | ||
{% endfor %} | ||
{% endfor %} | ||
|
||
{% for oid in id.o.author %} | ||
{% catinclude "pivot/_title.tpl" oid %} | ||
{% endfor %} | ||
|
||
{% for z_language in id.language|default:[z_language] %} | ||
{{ id.chapeau }} {{ id.summary }} {{ id.body }} {{ id.body_extra }} | ||
{{ id.date_remarks }} | ||
{% endfor %} | ||
|
||
{{ id.address_street_1 }} | ||
{{ id.address_street_2 }} | ||
{{ id.address_city }} | ||
{{ id.address_state }} | ||
{{ id.address_postcode }} | ||
{{ id.address_country }} | ||
{% if id.address_country and m.modules.active.mod_l10n %} | ||
{% for z_language in id.language|default:[z_language] %} | ||
{{ m.l10n.country_name[id.address_country] }} | ||
{% endfor %} | ||
{% endif %} | ||
|
||
{{ id.mail_street_1 }} | ||
{{ id.mail_street_2 }} | ||
{{ id.mail_city }} | ||
{{ id.mail_state }} | ||
{{ id.mail_postcode }} | ||
{{ id.mail_country }} | ||
{% if id.mail_country and m.modules.active.mod_l10n %} | ||
{% for z_language in id.language|default:[z_language] %} | ||
{{ m.l10n.country_name[id.mail_country] }} | ||
{% endfor %} | ||
{% endif %} | ||
|
||
{{ id.website }} | ||
|
||
{{ id.seo_title }} | ||
{{ id.seo_keywords }} | ||
{{ id.seo_desc }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{# All related resource ids, used for finding similar resources #} | ||
{# Prefix object ids with 'zpo' and categories with 'zpc' #} | ||
{% for name,os in m.edge[id] %} | ||
{% for o in os %} | ||
zpo{{ o.object_id }} | ||
{% endfor %} | ||
{% endfor %} | ||
{% if id.content_group_id %} | ||
zpo{{ id.content_group_id }} | ||
{% endif %} | ||
{% for cat,_true in id.is_a %} | ||
zpc{{ m.rsc[cat].id }} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% for name,os in m.edge[id] %} | ||
{% if name /= 'author' and not m.rsc[name].is_object_noindex %} | ||
{% for o in os %} | ||
{% catinclude "pivot/_title.tpl" o.object_id %} | ||
{% endfor %} | ||
{% endif %} | ||
{% endfor %} | ||
{% if id.content_group_id %} | ||
{% catinclude "pivot/_title.tpl" id.content_group_id %} | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% if id.name_first or id.name_surname %}{{ id.name_first }} {{ id.name_surname_prefix }} {{ id.name_surname }}{% else %}{{ id.title }}{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% id.title %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{% for z_language in id.language|default:[z_language] %} | ||
{{ id.title }} {{ id.short_title }} {{ id.subtitle }} | ||
{% endfor %} | ||
|
||
{{ id.name_prefix }} {{ id.name_first }} {{ id.name_surname_prefix }} {{ id.name_surname }} | ||
|
||
{{ id.slug|replace:"-":" " }} | ||
{{ id.page_path|replace:"/":" " }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{# Template used by z_pivot_rsc to fill the index tables for resources #} | ||
{# Extend this template if a category needs special pivoting (pivot uses a catinclude) #} | ||
|
||
{# Arguments: | ||
# - id (integer) the resource id to be pivoted | ||
# - props (property list) the prepivoted properties of the resource | ||
# - z_language (atom) the preferred stemmer language | ||
#} | ||
|
||
{# Blocks a..d contain the texts to be indexed, you need to render all languages #} | ||
{% block a %} | ||
{% catinclude "pivot/_title_text.tpl" id %} | ||
{% endblock %} | ||
|
||
{% block b %} | ||
{% catinclude "pivot/_main_text.tpl" id %} | ||
{% endblock %} | ||
|
||
{% block c %} | ||
{% catinclude "pivot/_block_text.tpl" id %} | ||
{% endblock %} | ||
|
||
{% block d %} | ||
{% catinclude "pivot/_related_text.tpl" id %} | ||
{% endblock %} | ||
|
||
{# This title is used for sorting #} | ||
{% block title %} | ||
{{ id.title|lower }} | ||
{% endblock %} | ||
|
||
{# All related resource ids, used for finding similar resources #} | ||
{# Prefix object ids with 'zpo' and categories with 'zpc' #} | ||
{% block related_ids %} | ||
{% catinclude "pivot/_related_ids.tpl" id %} | ||
{% endblock %} | ||
|
||
{# Pivot fields #} | ||
{% block address_street %}{{ id.address_street_1|default:mail_address_street_1 }}{% endblock %} | ||
{% block address_city %}{{ id.address_city|default:mail_city }}{% endblock %} | ||
{% block address_postcode %}{{ id.address_postcode|default:mail_postcode }}{% endblock %} | ||
{% block address_state %}{{ id.address_state|default:mail_state }}{% endblock %} | ||
{% block address_country %}{{ id.address_country|default:mail_country }}{% endblock %} | ||
|
||
{% block name_first %}{{ id.name_first }}{% endblock %} | ||
{% block name_surname %}{{ id.surname }}{% endblock %} | ||
{% block gender %}{{ id.gender }}{% endblock %} | ||
|
||
{% block date_start %}{{ id.date_start }}{% endblock %} | ||
{% block date_end %}{{ id.date_end }}{% endblock %} | ||
{% block date_start_month_day %}{{ id.date_start|date:"md" }}{% endblock %} | ||
{% block date_end_month_day %}{{ id.date_end|date:"md" }}{% endblock %} | ||
|
||
{% block location_lat %}{{ id.computed_location_lat|default:id.location_lat }}{% endblock %} | ||
{% block location_lng %}{{ id.computed_location_lng|default:id.location_lng }}{% endblock %} | ||
|
||
{# Optional date when to repivot #} | ||
{# Useful to repivot events when they are past their date_end, example: {{ id.date_end }} #} | ||
{% block date_repivot %}{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.