<p>Lots going on here, but I'll take a stab at it (in the future, it's helpful if you have multiple questions/issues to make separate posts for them).</p>

<p>Your questions of "why isn't this search term matching" probably comes down to the fact that by default, Craft doesn't do fuzzy matching.  You can use wildcards (*) to change that behavior on a per-search basis.  You can see that syntax here along with all of the other search syntax that Craft supports: <a href="https://craftcms.com/docs/searching" rel="nofollow noreferrer">https://craftcms.com/docs/searching</a></p>

<p>Also of note from that page is the <a href="https://craftcms.com/docs/config-settings#defaultSearchTermOptions" rel="nofollow noreferrer">defaultSearchTerms</a> config setting, where you can <a href="https://craftcms.com/support/enabling-fuzzy-search-by-default" rel="nofollow noreferrer">change</a> that behavior.</p>

<blockquote>
  <p>Then my search component is this:</p>
</blockquote>

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

{% paginate craft.entries.section('Organizations').search('title:' ~ query).order('score').limit(10) as entries %}
    {% if entries|length &lt; 1 %}
        {% paginate craft.entries.section('Organizations').search('organizationSummary:' ~ query).order('score').limit(10) as entries %}
</code></pre>

<p>That's probably not working as expected because not only can you not nest paginate tags, you can technically only have one paginate tag per <a href="https://craftcms.com/docs/templating/paginate" rel="nofollow noreferrer">request</a>.</p>

CC BY-SA 3.0
2017-01-16T23:52:15.660Z
2017-01-16T23:52:15.660Z
Brad Bell
<p>I currently have a search box which returns results, but only seems to return results if the search term is an exact match. For example, if i search hospital I will get 5 results back with the name hospital in the title, but if i search hospitals i will get no matches found. I would like the search to return results that are close to the search term as well. This is how i have it set up.</p>

<p>This is my search box. It returns to the same page as my index page has an <code>{% include "components/search" %}</code> to display on the homepage.</p>

<pre><code>   &lt;form class="navbar-search" action="{{ url('') }}"&gt;
      &lt;div class="input-group add-on"&gt;
        &lt;input class="form-control" placeholder="Search" name="q" id="srch-term" type="search"&gt;
        &lt;div class="input-group-btn"&gt;
        &lt;button class="btn btn-default" type="submit"&gt;&lt;i class="glyphicon glyphicon-search"&gt;&lt;/i&gt;&lt;/button&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  &lt;/form&gt;
</code></pre>

<p>Then my search component is this:</p>

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

{% paginate craft.entries.section('Organizations').search('title:' ~ query).order('score').limit(10) as entries %}
    {% if entries|length &lt; 1 %}
        {% paginate craft.entries.section('Organizations').search('organizationSummary:' ~ query).order('score').limit(10) as entries %}
</code></pre>

<p>If the title returns no search results I wanted it to search through a summary section instead. Currently it works very well except for only returning exact terms. I'm a bit stuck as I'm ordering by score as shown in the Craft documentation so not sure what I am missing here. Any ideas?</p>

<p>Thanks</p>

<search>
Search results by closest match to query
# Search results by closest match to query

(Asked by: username_0 on 2017-01-16)

I currently have a search box which returns results, but only seems to return results if the search term is an exact match. For example, if i search hospital I will get 5 results back with the name hospital in the title, but if i search hospitals i will get no matches found. I would like the search to return results that are close to the search term as well. This is how i have it set up.
This is my search box. It returns to the same page as my index page has an {% include "components/search" %} to display on the homepage.
   
      
        
        
        
        
      
  

Then my search component is this:
{% set query = craft.request.getParam('q') %}

{% paginate craft.entries.section('Organizations').search('title:' ~ query).order('score').limit(10) as entries %}
    {% if entries|length < 1 %}
        {% paginate craft.entries.section('Organizations').search('organizationSummary:' ~ query).order('score').limit(10) as entries %}

If the title returns no search results I wanted it to search through a summary section instead. Currently it works very well except for only returning exact terms. I'm a bit stuck as I'm ordering by score as shown in the Craft documentation so not sure what I am missing here. Any ideas?
Thanks

**Tags:** search


---

## 1 answers

### Answer by username_1 on 2017-01-16. Score: 1

Lots going on here, but I'll take a stab at it (in the future, it's helpful if you have multiple questions/issues to make separate posts for them).
Your questions of "why isn't this search term matching" probably comes down to the fact that by default, Craft doesn't do fuzzy matching.  You can use wildcards (*) to change that behavior on a per-search basis.  You can see that syntax here along with all of the other search syntax that Craft supports: https://craftcms.com/docs/searching
Also of note from that page is the defaultSearchTerms config setting, where you can change that behavior.

Then my search component is this:

{% set query = craft.request.getParam('q') %}

{% paginate craft.entries.section('Organizations').search('title:' ~ query).order('score').limit(10) as entries %}
    {% if entries|length < 1 %}
        {% paginate craft.entries.section('Organizations').search('organizationSummary:' ~ query).order('score').limit(10) as entries %}

That's probably not working as expected because not only can you not nest paginate tags, you can technically only have one paginate tag per request.


---

