ElasticSearch: display text where searched word appears

35 views
Skip to first unread message

Diego Martinez

unread,
Sep 29, 2016, 7:31:44 AM9/29/16
to Wagtail support
Hi everybody,

I have this template for the search_page:

         {% for t in titles%}
            <h1 class="search-title">{{ t.search_title }}</h1>
            <h2 class="search-subtitle">
                {% if search_results %}
                    {% for result in search_results %}
                        {% if forloop.last %}
                            {% if forloop.counter > 1 %}
                                {{ forloop.counter }} {% trans 'results for' %}
                            {% else %}
                                {{ forloop.counter }} {% trans 'result for' %}
                            {% endif %}
                        {% endif %}
                    {% endfor %}
                {% else %}
                    {% trans '0 results for' %}
                {% endif %}
                {% if search_query %}
                    "{{ search_query }}"
                {% endif %}
            </h2>
        {% endfor %}
        {% if search_results %}
                {% for result in search_results %}
                    <div class="search-result-row">
                        <a class="search-result-link" href="{% pageurl result %}">{{ result }}</a>
                        {% if result.search_description %}
                            {{ result.search_description|safe }}
                        {% endif %}
                    </div>
                {% endfor %}
        {% endif %}

I would like to show the text where the search string appears on the web, is it possible?

Thanks in advance

Moritz Pfeiffer

unread,
Sep 29, 2016, 7:42:45 AM9/29/16
to Wagtail support
Hi Diego

Can you be more specific?
Is this an HTML question or something Elasticsearch/Wagtail specific?

Greetings
Moritz

Diego Martinez

unread,
Sep 29, 2016, 8:01:04 AM9/29/16
to Wagtail support
It's a Elasticsearch/Wagtail specific question. I want to do is to show in the template the associated text field where Elastic found the word. Sample:

If i search "Welcome", now i show in the template the page where the word is found, but i need too the text or paragraph (field value) where the word is.

"Welcome" ----> page

"Welcome to my web site"  ----> field value inserted in wagtail admin

Diego Martinez

unread,
Sep 29, 2016, 8:03:35 AM9/29/16
to Wagtail support
"Welcome" in the template is {{result}} (obtained with search_results), but i don't know what variable save the other value("Welcome to my web site."). I need to show this.

Moritz Pfeiffer

unread,
Sep 29, 2016, 8:04:41 AM9/29/16
to Wagtail support
Interesting use case, and indeed elasticsearch specific.
I don't know the elasticsearch bindings well enough for that.
Anybody?

Matthew Westcott

unread,
Sep 29, 2016, 8:13:42 AM9/29/16
to wag...@googlegroups.com
Hi Diego,
As far as I'm aware this isn't currently supported by Wagtail's search module, but work on it is in progress here:
https://github.com/torchbox/wagtail/pull/3004

Cheers,
- Matt
> --
> You received this message because you are subscribed to the Google Groups "Wagtail support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wagtail+u...@googlegroups.com.
> To post to this group, send email to wag...@googlegroups.com.
> Visit this group at https://groups.google.com/group/wagtail.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/wagtail/8d55b1be-a168-4ddd-8724-c4433e2aed16%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Diego Martinez

unread,
Sep 29, 2016, 8:32:32 AM9/29/16
to Wagtail support
Thanks for the response. I'll be waiting for this feature!
Reply all
Reply to author
Forward
0 new messages