<p>I have a search results page that doesn't show all matching results. The result entries that do show appear to older entries that have smaller ID numbers, although I'm not sure if that has anything to do with the issue.</p>
<p>In my case, I have a <code>people</code> channel. Each person (entry) in the channel has a related entry called <code>relatedOffices</code> (associated with a <code>locations</code> structure section). Although the entries for &quot;John&quot;, &quot;Jim&quot;, and &quot;Jerry&quot; all have &quot;Dallas&quot; selected in the <code>relatedOffices</code> field, only &quot;John&quot; and &quot;Jim&quot; show in the results.</p>
<p>I've been able to deduce the issue down to the queryParam search string. If the search query string is just <code>relatedOffices:Dallas</code>, all three entries show. But if the search query string is <code>AND relatedOffices:Dallas</code>, only two of the entries show.</p>
<p>The addition of <code>AND</code> seems to change the results, but I'm not sure why. I'm hoping to keep the <code>AND</code> in the string as well because I'm using multiple parameters in my search.</p>
<p>I tried rebuilding the index (<code>php craft resave/entries --update-search-index </code>), but that doesn't seem to resolve the issue.</p>
<p>Craft CMS 3.5.8 is what I'm running.</p>
<p>Here's my query string and query param set up:</p>
<pre><code>{# 1. Getting parameters from URL  #}
{% set keywordParam = craft.app.request.getParam('q')%}
{% set nameParam = craft.app.request.getParam('name')%}
{% set industryParam = craft.app.request.getParam('industry')%}
{% set locParam = craft.app.request.getParam('loc')%}

{# 2.Building query string #}
{%- set queryString -%}
    {% spaceless %}
        {{- keywordParam ? &quot;#{keywordParam} AND &quot; -}}
        {{- nameParam ? &quot;#{macros.paramString(nameParam, 'title')}&quot; -}}
        {{- industryParam ? &quot; AND #{macros.paramString(industryParam, 'industriesRelated')}&quot; -}}
        {{- locParam ? &quot; AND #{macros.paramString(locParam, 'relatedOffices')}&quot; -}}
    {% endspaceless %}
{%- endset -%}


{# 2B. Escape queryString output and set default to be ' ' so that if there's no params, ' ' outputs which leads to no results #}
    {% set queryString = queryString|escape|default(' ') %}

{# 3. Set queryParams #}    
{% set queryParams = {
    section:    'people',
    limit:      15,
    search:     (queryString)
} %}
</code></pre>

CC BY-SA 4.0
2020-09-09T17:00:11.467Z
What is the final queryString you're sending? How are you executing your query? ``.al()``?  If you're searching on fields, I would set the parameters of your custom field itself.
RitterKnight
CC BY-SA 4.0
2020-09-09T17:17:27.023Z
@RitterKnight The final queryString is `AND relatedOffices:Dallas`. The query is executed by the paginate tag. The parameters is set to search within the custom field itself, too. To test this all, I directly passed `AND relatedOffices:Dallas` and `relatedOffices:Dallas` as the queryString value. The `AND relatedOffices:Dallas` version doesn't show all results, but `relatedOffices:Dallas` displays all the results, so I'm not sure why the inclusion of `AND` is throwing off the results.
user3092
<craft3><search><params><querystring>
Search results not showing all entries
# Search results not showing all entries

(Asked by: username_0 on 2020-09-08)

I have a search results page that doesn't show all matching results. The result entries that do show appear to older entries that have smaller ID numbers, although I'm not sure if that has anything to do with the issue.
In my case, I have a people channel. Each person (entry) in the channel has a related entry called relatedOffices (associated with a locations structure section). Although the entries for "John", "Jim", and "Jerry" all have "Dallas" selected in the relatedOffices field, only "John" and "Jim" show in the results.
I've been able to deduce the issue down to the queryParam search string. If the search query string is just relatedOffices:Dallas, all three entries show. But if the search query string is AND relatedOffices:Dallas, only two of the entries show.
The addition of AND seems to change the results, but I'm not sure why. I'm hoping to keep the AND in the string as well because I'm using multiple parameters in my search.
I tried rebuilding the index (php craft resave/entries --update-search-index ), but that doesn't seem to resolve the issue.
Craft CMS 3.5.8 is what I'm running.
Here's my query string and query param set up:
{# 1. Getting parameters from URL  #}
{% set keywordParam = craft.app.request.getParam('q')%}
{% set nameParam = craft.app.request.getParam('name')%}
{% set industryParam = craft.app.request.getParam('industry')%}
{% set locParam = craft.app.request.getParam('loc')%}

{# 2.Building query string #}
{%- set queryString -%}
    {% spaceless %}
        {{- keywordParam ? "#{keywordParam} AND " -}}
        {{- nameParam ? "#{macros.paramString(nameParam, 'title')}" -}}
        {{- industryParam ? " AND #{macros.paramString(industryParam, 'industriesRelated')}" -}}
        {{- locParam ? " AND #{macros.paramString(locParam, 'relatedOffices')}" -}}
    {% endspaceless %}
{%- endset -%}


{# 2B. Escape queryString output and set default to be ' ' so that if there's no params, ' ' outputs which leads to no results #}
    {% set queryString = queryString|escape|default(' ') %}

{# 3. Set queryParams #}    
{% set queryParams = {
    section:    'people',
    limit:      15,
    search:     (queryString)
} %}

**Tags:** craft3, search, params, querystring
> **Comments:**
> **username_1**: What is the final queryString you're sending? How are you executing your query? ``.al()``?  If you're searching on fields, I would set the parameters of your custom field itself.  
> **username_0**: @RitterKnight The final queryString is `AND relatedOffices:Dallas`. The query is executed by the paginate tag. The parameters is set to search within the custom field itself, too. To test this all, I directly passed `AND relatedOffices:Dallas` and `relatedOffices:Dallas` as the queryString value. The `AND relatedOffices:Dallas` version doesn't show all results, but `relatedOffices:Dallas` displays all the results, so I'm not sure why the inclusion of `AND` is throwing off the results.  

---

## 0 answers

