trilbymedia / grav-plugin-tntsearch

Powerful indexed-based full text search engine powered by the TNTSearch library
https://trilby.media
MIT License
61 stars 23 forks source link

Indexing Modular and Custom Field Content with Flex Pages #102

Open thekenshow opened 4 years ago

thekenshow commented 4 years ago

I'm not able to get modular and custom field content indexed with Flex Pages enabled, despite creating a template as explained in the docs.

I have a modular page with a few modules that use a custom blueprint:

modular.en.md
    infolist.en.md
    infolist.en.md
    infolist.en.md

The following YAML appears in modular.en.md:

content:
    items: '@self.modular'

The module page content in infolist.en.md looks like this:

<p>We are the XYZ experts, from a very-unique-word and more.</p>

The modular page custom field content in infolist.en.md looks like this:

listitems:
    -
        itemtitle: Something
        itemimage: someimage.jpg
        itemimageloc: center
        itemicon: null
        itemiconloc: null
        itemdesc: '<p>A bit of text with another-very-unique-word in it.</p>'

I've created a templates/tntsearch/modular.html.twig file to capture modular and custom field content:

{% for module in page.collection() %}
<p>
    {{ module.content }}
    {% for info in module.listitems %}
      {{ info.itemtitle }}
      {{ info.itemdesc }}
    {% endfor %}
</p>
{% endfor %}

{{ page.content }}

When I index the site, I get only the parent modular.en.md page content, and nothing from the infolist.en.md module page content or custom field.

Could this be related to the lack of Flex Page support for @self in blueprints as noted at Page Blueprint with filepicker field does not recognize folder value of @self?

mahagr commented 4 years ago

The @self issue in filepicker should be separate to this one (upload handling was missing support for it); modular pages should work just like they do with the regular pages.

I need to take a look what's going on here...

thekenshow commented 4 years ago

OK, let me know if you need more information.

mahagr commented 4 years ago

You are missing:

tntsearch:
  template: 'tntsearch/modular.html.twig'
content:
    items: '@self.modular'
thekenshow commented 4 years ago

Er, thanks ( :embarrassed: )

I've added that to all modular pages, rebuilt the TNT Index, and cleared the cache. There is still no sign of page.content, itemlist.itemtitle, or itemlist.itemdesc text from infolist.en.md in the search results. Worse, the parent modular.en.md page content (the "very-unique-word" example above) is no longer being found either. When I remove the tntsearch: from the header, the parent page content is restored in the search results.

thekenshow commented 4 years ago

Another data point: if I drop the templates/tntsearch/modular.html.twig into a parent page, the content of the child modules is rendered:

{% for module in page.collection() %}
<p>
    {{ module.content }}
    {% for info in module.listitems %}
      {{ info.itemtitle }}
      {{ info.itemdesc }}
    {% endfor %}
</p>
{% endfor %}

{{ page.content }}
mahagr commented 4 years ago

You mean if you put the modules into the main template of the page it works?

Does this new code work in the regular pages, btw?

thekenshow commented 4 years ago

Hi - meant to update this issue. I reach out to Trilby for paid support and @rhukster was able to get my site working for launch. The changes he came up with were:

  1. Turned off front-end Flex pages.
  2. Replaced
    tntsearch:
    template: 'tntsearch/modular.html.twig'

    with

    tntsearch:
    template: 'tntsearch/modular'
  3. Changed user/data/gantry5/themes/rt_photon/templates/tntsearch/modular.html.twig to:
    {% for module in page.collection() %}
    {{ module.content|raw|striptags }}
    {% for info in module.header.listitems %}
    {{ info.itemtitle|raw|striptags }}
    {{ info.itemdesc|raw|striptags }}
    {% endfor %}
    {% endfor %}
    {{ page.content|raw|striptags }}

    The |raw|striptags was to remove unwanted characters that were getting in somehow.