<p>This was solved in my latest release: <a href="https://github.com/mustasj/expanded-search/releases" rel="nofollow noreferrer">https://github.com/mustasj/expanded-search/releases</a></p>

<p>So if you want to use it with pagination, you can now add <code>limit</code> and <code>offset</code> to the settings param.</p>

<p>So in your case the top of your template would look something like this:</p>

<pre><code>{% set limit = 10 %}
{% set entries = craft.entries()
    .search(searchQuery)
    .orderBy('score')
    .limit(limit) %}

{# Paginate the entries #}
{% paginate entries as pageInfo, pageEntries %}
{% set expandedResults = craft.expandedSearch.search(searchQuery, {
    length: 155,
    offset: (pageInfo.currentPage - 1) * limit,
    limit: limit
}) %}
</code></pre>

CC BY-SA 4.0
2019-04-01T10:21:59.070Z
Thanks for adding that in!
Phil Gwynne
CC BY-SA 4.0
2019-04-01T09:42:09.490Z
2019-04-01T09:42:09.490Z
peirix
<p>I'm using the Expanded Search plugin to display results of the search query with an excerpt of the text matching the query for each result. I want to limit the results to 10 per page, using pagination. </p>

<p>Does anyone know how I could limit the <code>expandedResults</code> from the Expanded Search plugin?</p>

<p>The pagination works with the following code, but the Expanded Search results does not respect the limit to entries and instead shows all the results without limit, on each paginated page (e.g. If I have 14 results, the pagination will have 2 pages available, but all 14 results are displayed across both pages):</p>

<h3>Expanded Search Results</h3>

<pre><code>  {# Get the user's search query from the 'q' query-string param #}
  {% set searchQuery = craft.app.request.getParam('q') %}

  {# Fetch entries that match the search query #}
  {% set entries = craft.entries()
      .search(searchQuery)
      .orderBy('score') 
      .limit(10) %}

  {# Paginate the entries #}
  {% paginate entries as pageInfo, pageEntries %}

  {# Get the search result excerpts from the Expanded Results plugin #}
  {% set expandedResults = craft.expandedSearch.search(searchQuery, { length: 155 }) %}

  {% if entries|length %}

      {# List search result entries #}
      {% for result in expandedResults %}
          &lt;a href="{{ result.entry.url }}"&gt;
              &lt;h3&gt;{{ result.entry.title }}&lt;/h3&gt;
              &lt;cite&gt;{{ result.entry.url }}&lt;/cite&gt;
          &lt;/a&gt;
          {% if result.matchedValue %}&lt;p&gt;{{ result.matchedValue | raw }}&lt;/p&gt;{% else %}&lt;p&gt;No preview available&lt;/p&gt;{% endif %}
          &lt;p&gt;{% if result.entry.dateUpdated %}{{ result.entry.dateUpdated | date("j F Y") }}{% else %}{{ result.entry.postDate | date("j F Y") }}{% endif %}&lt;/p&gt;
      {% endfor %}

      {# Display pagination if there are more than 10 entries #}
      {% if pageInfo.prevUrl or pageInfo.nextUrl %}
            {% if pageInfo.prevUrl %}&lt;a href="{{ pageInfo.prevUrl }}?q={{ searchQuery }}"&gt;Previous Page&lt;/a&gt;{% endif %}
            {% for page, url in pageInfo.getPrevUrls(2) %}
                &lt;a href="{{ url }}?q={{ searchQuery }}"&gt;{{ page }}&lt;/a&gt;
            {% endfor %}
            {{ pageInfo.currentPage }}
            {% for page, url in pageInfo.getNextUrls(2) %}
                &lt;a href="{{ url }}?q={{ searchQuery }}"&gt;{{ page }}&lt;/a&gt;
            {% endfor %}
            {% if pageInfo.nextUrl %}&lt;a href="{{ pageInfo.nextUrl }}?q={{ searchQuery }}"&gt;Next Page&lt;/a&gt;{% endif %}
            &lt;p&gt;Page {{ pageInfo.currentPage }} of {{ pageInfo.totalPages }}&lt;/p&gt;
      {% endif %}

  {% endif %}
</code></pre>

<p>I've also tried it this way, where I'm using the <code>expandedResults</code> for the result excerpt only. As expected, the pagination and entry limit is this time respected, but this time, every result excerpt displays the excerpts from all the results (e.g. I have 14 results, split between 2 paginated pages but each result features all 14 excerpts):</p>

<h3>Entry Results with Partial Expanded Search Result</h3>

<pre><code>{# List search result entries #}
{% for entry in pageEntries %}
    &lt;a href="{{ entry.url }}"&gt;
        &lt;h3&gt;{{ entry.title }}&lt;/h3&gt;
        &lt;cite&gt;{{ entry.url }}&lt;/cite&gt;
    &lt;/a&gt;
    {# Show excerpt with matching value if available #}
    {% for result in expandedResults %}
        {% if result.matchedValue %}&lt;p&gt;{{ result.matchedValue | raw }}&lt;/p&gt;{% else %}&lt;p&gt;No preview available&lt;/p&gt;{% endif %}
    {% endfor %}
    &lt;p&gt;{% if entry.dateUpdated %}{{ entry.dateUpdated | date("j F Y") }}{% else %}{{ entry.postDate | date("j F Y") }}{% endif %}&lt;/p&gt;
{% endfor %}
</code></pre>

<craft3><entries><plugins><search>
How to limit Expanded Search (plugin) query results for pagination?
# How to limit Expanded Search (plugin) query results for pagination?

(Asked by: username_0 on 2019-03-25)

I'm using the Expanded Search plugin to display results of the search query with an excerpt of the text matching the query for each result. I want to limit the results to 10 per page, using pagination. 
Does anyone know how I could limit the expandedResults from the Expanded Search plugin?
The pagination works with the following code, but the Expanded Search results does not respect the limit to entries and instead shows all the results without limit, on each paginated page (e.g. If I have 14 results, the pagination will have 2 pages available, but all 14 results are displayed across both pages):
Expanded Search Results
  {# Get the user's search query from the 'q' query-string param #}
  {% set searchQuery = craft.app.request.getParam('q') %}

  {# Fetch entries that match the search query #}
  {% set entries = craft.entries()
      .search(searchQuery)
      .orderBy('score') 
      .limit(10) %}

  {# Paginate the entries #}
  {% paginate entries as pageInfo, pageEntries %}

  {# Get the search result excerpts from the Expanded Results plugin #}
  {% set expandedResults = craft.expandedSearch.search(searchQuery, { length: 155 }) %}

  {% if entries|length %}

      {# List search result entries #}
      {% for result in expandedResults %}
          
              {{ result.entry.title }}
              {{ result.entry.url }}
          
          {% if result.matchedValue %}{{ result.matchedValue | raw }}{% else %}No preview available{% endif %}
          {% if result.entry.dateUpdated %}{{ result.entry.dateUpdated | date("j F Y") }}{% else %}{{ result.entry.postDate | date("j F Y") }}{% endif %}
      {% endfor %}

      {# Display pagination if there are more than 10 entries #}
      {% if pageInfo.prevUrl or pageInfo.nextUrl %}
            {% if pageInfo.prevUrl %}Previous Page{% endif %}
            {% for page, url in pageInfo.getPrevUrls(2) %}
                {{ page }}
            {% endfor %}
            {{ pageInfo.currentPage }}
            {% for page, url in pageInfo.getNextUrls(2) %}
                {{ page }}
            {% endfor %}
            {% if pageInfo.nextUrl %}Next Page{% endif %}
            Page {{ pageInfo.currentPage }} of {{ pageInfo.totalPages }}
      {% endif %}

  {% endif %}

I've also tried it this way, where I'm using the expandedResults for the result excerpt only. As expected, the pagination and entry limit is this time respected, but this time, every result excerpt displays the excerpts from all the results (e.g. I have 14 results, split between 2 paginated pages but each result features all 14 excerpts):
Entry Results with Partial Expanded Search Result
{# List search result entries #}
{% for entry in pageEntries %}
    
        {{ entry.title }}
        {{ entry.url }}
    
    {# Show excerpt with matching value if available #}
    {% for result in expandedResults %}
        {% if result.matchedValue %}{{ result.matchedValue | raw }}{% else %}No preview available{% endif %}
    {% endfor %}
    {% if entry.dateUpdated %}{{ entry.dateUpdated | date("j F Y") }}{% else %}{{ entry.postDate | date("j F Y") }}{% endif %}
{% endfor %}

**Tags:** craft3, entries, plugins, search


---

## 1 answers

### Answer by username_1 on 2019-04-01. Score: 3 | Accepted answer

This was solved in my latest release: https://github.com/mustasj/expanded-search/releases
So if you want to use it with pagination, you can now add limit and offset to the settings param.
So in your case the top of your template would look something like this:
{% set limit = 10 %}
{% set entries = craft.entries()
    .search(searchQuery)
    .orderBy('score')
    .limit(limit) %}

{# Paginate the entries #}
{% paginate entries as pageInfo, pageEntries %}
{% set expandedResults = craft.expandedSearch.search(searchQuery, {
    length: 155,
    offset: (pageInfo.currentPage - 1) * limit,
    limit: limit
}) %}

> **Comments:**
> **username_0**: Thanks for adding that in!  

---

