Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-01T10:21:59.070Z
Answers.Text: Thanks for adding that in!
Answers.UserDisplayName: Phil Gwynne
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-01T09:42:09.490Z
Answers.LastActivityDate: 2019-04-01T09:42:09.490Z
Answers.UserDisplayName: peirix
Body: <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>
  
Tags: <craft3><entries><plugins><search>
Title: How to limit Expanded Search (plugin) query results for pagination?
ThreadText: # 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 %}
            <a href="{{ result.entry.url }}">
                <h3>{{ result.entry.title }}</h3>
                <cite>{{ result.entry.url }}</cite>
            </a>
            {% if result.matchedValue %}<p>{{ result.matchedValue | raw }}</p>{% else %}<p>No preview available</p>{% endif %}
            <p>{% if result.entry.dateUpdated %}{{ result.entry.dateUpdated | date("j F Y") }}{% else %}{{ result.entry.postDate | date("j F Y") }}{% endif %}</p>
        {% endfor %}
  
        {# Display pagination if there are more than 10 entries #}
        {% if pageInfo.prevUrl or pageInfo.nextUrl %}
              {% if pageInfo.prevUrl %}<a href="{{ pageInfo.prevUrl }}?q={{ searchQuery }}">Previous Page</a>{% endif %}
              {% for page, url in pageInfo.getPrevUrls(2) %}
                  <a href="{{ url }}?q={{ searchQuery }}">{{ page }}</a>
              {% endfor %}
              {{ pageInfo.currentPage }}
              {% for page, url in pageInfo.getNextUrls(2) %}
                  <a href="{{ url }}?q={{ searchQuery }}">{{ page }}</a>
              {% endfor %}
              {% if pageInfo.nextUrl %}<a href="{{ pageInfo.nextUrl }}?q={{ searchQuery }}">Next Page</a>{% endif %}
              <p>Page {{ pageInfo.currentPage }} of {{ pageInfo.totalPages }}</p>
        {% 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 %}
      <a href="{{ entry.url }}">
          <h3>{{ entry.title }}</h3>
          <cite>{{ entry.url }}</cite>
      </a>
      {# Show excerpt with matching value if available #}
      {% for result in expandedResults %}
          {% if result.matchedValue %}<p>{{ result.matchedValue | raw }}</p>{% else %}<p>No preview available</p>{% endif %}
      {% endfor %}
      <p>{% if entry.dateUpdated %}{{ entry.dateUpdated | date("j F Y") }}{% else %}{{ entry.postDate | date("j F Y") }}{% endif %}</p>
  {% 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!  
  
  ---
  
  