<p>It's not finding anything because there isn't a single row that has both <code>*hampshire*</code> <em>and</em> <code>*10k*</code> in it.</p>

<p>If you want to search across rows, then you'll want to use <code>{ search: '*hampshire* OR *10k*' }</code>.</p>

CC BY-SA 3.0
2015-10-15T17:09:19.133Z
Ah, so would the keywords have to both feature in a specific field or the title to match together  without the use of OR?
Sam Hibberd
CC BY-SA 3.0
2015-10-15T17:21:02.767Z
That sound about right.
Brad Bell
CC BY-SA 3.0
2015-10-15T17:25:43.373Z
Ok, but how do you search for entries that must have both terms, no matter in what field?
carlcs
CC BY-SA 3.0
2015-10-15T19:39:15.443Z
I think some content strategy can also help you here. (See my answer below).
RitterKnight
CC BY-SA 3.0
2015-10-16T13:56:07.433Z
Thanks @RitterKnight, completely agree, aware of this but with 9k entries that is a long term goal. @Brad Bell what happens with ```hampshire OR 10k``` vs ```hampshire AND 10k``` surely the later is the preferred behaviour in this case as the more relevant results should contain both hampshire and 10k and these could be store in different fields (a location field) and a distance category??
Sam Hibberd
CC BY-SA 3.0
2015-10-16T15:15:23.450Z
Updated my answer a bit with a couple potential options.
RitterKnight
CC BY-SA 3.0
2015-10-15T16:23:50.843Z
2015-10-15T16:23:50.843Z
Brad Bell
<p>Assuming you have a field for distance, since you have a ton of entries, Craft allows dynamic titles (and slugs) so you could <a href="http://buildwithcraft.com/docs/sections-and-entries#dynamic-entry-titles" rel="nofollow">generate your titles</a> based on fields already present on your entry.</p>

<p>Something like: <code>{raceLocation} {raceDistance} {whateverOtherField}</code> </p>

<p>Another solution would be to do a little "sanitizing" on the user's search terms to grab the distance before you send the search to Craft. Seems like searching on distance is a pretty common query, so a little AI might be in order.  Something like:</p>

<pre><code>{# get the query #}
{% set query = craft.request.getParam('q') %}

{# add the distance field to the search #}
{{ query|replace('10k','raceDistance:10k') }}

{% set entries = craft.entries.search(query).order('score') %}

{# rest of the search logic here #}
...
</code></pre>

<p>That should match the terms the user put in. It'll also match the race distance separately.  You're probably going to want to use a regex on the distance <code>(\\d+\\s+km?)</code> to make it more flexible...</p>

CC BY-SA 3.0
2015-10-15T19:38:25.127Z
2015-10-16T15:22:55.127Z
2015-10-16T15:22:55.127Z
RitterKnight
<p>As Brad mentioned, you’re not getting any results because your search query requires both keywords to be present, but you don’t have any fields that have both keywords.</p>

<p>You can solve this with a hidden <a href="https://github.com/aelvan/Preparse-Field-Craft" rel="noreferrer">Preparse</a> field that stores the content of all fields you want to be cross-searchable. Call it something like “Keywords”, and set its Twig template to:</p>

<pre><code>{{ entry.myCustomFieldHandle }}
{{ entry.myOtherCustomFieldHandle }}
</code></pre>

<p>If you want to include any Matrix or relational fields in the keywords, remember the same templating rules apply here as on your front end templates:</p>

<pre><code>{% for block in entry.myMatrixFieldHandle %}
    {{ block.myBlockFieldHandle }}
{% endfor %}

{% for relatedEntry in entry.myEntriesFieldHandel %}
    {{ relatedEntry.title }}
    {{ relatedEntry.myRelatedEntryFieldHandle }}
{% endfor %}
</code></pre>

<p>Once you’ve got that field set up and added to your section(s), you’ll need to re-save all of your existing entries before it takes effect. An easy way to do that is to go into the sections’ settings and just click the Save button, which will trigger a “Resaving Elements” background task for all entries in the section.</p>

CC BY-SA 3.0
2015-10-16T15:26:59.283Z
Nice! Going to have to try this out myself...
RitterKnight
CC BY-SA 3.0
2015-11-10T14:39:12.737Z
Great solution, search has been greatly improved!
Sam Hibberd
CC BY-SA 3.0
2015-10-16T15:14:24.177Z
2015-10-16T15:14:24.177Z
Brandon Kelly
<p>Can anyone help identify why one on my entries is not being picked up in my search query?</p>

<p>The search terms are <strong>'hampshire 10k'</strong> and the <code>craft_searchindex</code> table for this entry looks like this:</p>

<p><a href="https://i.sstatic.net/FAQPa.png" rel="noreferrer"><img src="https://i.sstatic.net/FAQPa.png" alt="Search Index"></a></p>

<p>The search string param is added as follows (along with a handful of other params) for any search</p>

<pre><code>{ search: '*hampshire* *10k*' }
</code></pre>

<p>Unsure if it's down to bug or a templating issue? The keyword search forms part of quite complex entry search.</p>

<templating><search>
Entry not showing up in search results?
# Entry not showing up in search results?

(Asked by: username_0 on 2015-10-15)

Can anyone help identify why one on my entries is not being picked up in my search query?
The search terms are 'hampshire 10k' and the craft_searchindex table for this entry looks like this:

The search string param is added as follows (along with a handful of other params) for any search
{ search: '*hampshire* *10k*' }

Unsure if it's down to bug or a templating issue? The keyword search forms part of quite complex entry search.

**Tags:** templating, search

---

## 3 answers

### Answer by username_4 on 2015-10-16. Score: 5 | Accepted answer

As Brad mentioned, you’re not getting any results because your search query requires both keywords to be present, but you don’t have any fields that have both keywords.
You can solve this with a hidden Preparse field that stores the content of all fields you want to be cross-searchable. Call it something like “Keywords”, and set its Twig template to:
{{ entry.myCustomFieldHandle }}
{{ entry.myOtherCustomFieldHandle }}

If you want to include any Matrix or relational fields in the keywords, remember the same templating rules apply here as on your front end templates:
{% for block in entry.myMatrixFieldHandle %}
    {{ block.myBlockFieldHandle }}
{% endfor %}

{% for relatedEntry in entry.myEntriesFieldHandel %}
    {{ relatedEntry.title }}
    {{ relatedEntry.myRelatedEntryFieldHandle }}
{% endfor %}

Once you’ve got that field set up and added to your section(s), you’ll need to re-save all of your existing entries before it takes effect. An easy way to do that is to go into the sections’ settings and just click the Save button, which will trigger a “Resaving Elements” background task for all entries in the section.

> **Comments:**
> **username_3**: Nice! Going to have to try this out myself...  
> **username_0**: Great solution, search has been greatly improved!  

---

### Answer by username_1 on 2015-10-15. Score: 3

It's not finding anything because there isn't a single row that has both `*hampshire*` *and* `*10k*` in it.

If you want to search across rows, then you'll want to use `{ search: '*hampshire* OR *10k*' }`.

> **Comments:**
> **username_0**: Ah, so would the keywords have to both feature in a specific field or the title to match together  without the use of OR?  
> **username_1**: That sound about right.  
> **username_2**: Ok, but how do you search for entries that must have both terms, no matter in what field?  
> **username_3**: I think some content strategy can also help you here. (See my answer below).  
> **username_0**: Thanks @RitterKnight, completely agree, aware of this but with 9k entries that is a long term goal. @Brad Bell what happens with ```hampshire OR 10k``` vs ```hampshire AND 10k``` surely the later is the preferred behaviour in this case as the more relevant results should contain both hampshire and 10k and these could be store in different fields (a location field) and a distance category??  
> **username_3**: Updated my answer a bit with a couple potential options.  

---

### Answer by username_3 on 2015-10-15. Score: 1

Assuming you have a field for distance, since you have a ton of entries, Craft allows dynamic titles (and slugs) so you could generate your titles based on fields already present on your entry.
Something like: {raceLocation} {raceDistance} {whateverOtherField} 
Another solution would be to do a little "sanitizing" on the user's search terms to grab the distance before you send the search to Craft. Seems like searching on distance is a pretty common query, so a little AI might be in order.  Something like:
{# get the query #}
{% set query = craft.request.getParam('q') %}

{# add the distance field to the search #}
{{ query|replace('10k','raceDistance:10k') }}

{% set entries = craft.entries.search(query).order('score') %}

{# rest of the search logic here #}
...

That should match the terms the user put in. It'll also match the race distance separately.  You're probably going to want to use a regex on the distance (\\d+\\s+km?) to make it more flexible...


---

