<p>This sounds like a good approach and could be done using a twig filter on your search string.</p>

<p>Here are the first two lines of the example from the docs:</p>

<pre><code>{% set query = craft.request.getParam('q') %}
{% set entries = craft.entries.search(query|customFilter).order('score') %}
</code></pre>

<p>In this example <code>query</code> is now modified by <code>customFilter</code> and can be updated in your Twig filter to behave however you like.</p>

CC BY-SA 3.0
2015-08-15T16:07:42.687Z
2015-08-15T16:07:42.687Z
Ben Parizek
<p>I want to use the standard site search but much prefer that (first) part word search is in place by default. By this I mean if a user searches for dog they will also find dogs, so the term Craft uses would then be dog*.</p>

<p>My strategy would then be to take the search string (e.g. 'dog fee') and remove any commas or fullstops unless the string is in quotes ("dog fee"). I would then split the string using spaces and throw away any empty strings ('dog', 'fee'), and then append the * to each word and send 'dog* fee*' to the search system.</p>

<p>Is this the best approach to get what I want, or have I missed a glaringly obvious and easy way of doing it?</p>

<search>
Best way to effect part word searching by default
# Best way to effect part word searching by default

(Asked by: username_0 on 2015-02-11)

I want to use the standard site search but much prefer that (first) part word search is in place by default. By this I mean if a user searches for dog they will also find dogs, so the term Craft uses would then be dog\*.

My strategy would then be to take the search string (e.g. 'dog fee') and remove any commas or fullstops unless the string is in quotes ("dog fee"). I would then split the string using spaces and throw away any empty strings ('dog', 'fee'), and then append the \* to each word and send 'dog\* fee\*' to the search system.

Is this the best approach to get what I want, or have I missed a glaringly obvious and easy way of doing it?

**Tags:** search


---

## 1 answers

### Answer by username_1 on 2015-08-15. Score: 4

This sounds like a good approach and could be done using a twig filter on your search string.
Here are the first two lines of the example from the docs:
{% set query = craft.request.getParam('q') %}
{% set entries = craft.entries.search(query|customFilter).order('score') %}

In this example query is now modified by customFilter and can be updated in your Twig filter to behave however you like.


---

