Answers.Body: <p>One way to do it is to split the search query on spaces, and then join it with <code>'OR'</code>:</p>
  
  <pre><code>{% set query = craft.request.getParam('q')|split(' ')|join(' OR ') %}
  {% set entries = craft.entries.search(query).order('score') %}
  </code></pre>
  
  <p>The above will convert the search term <code>"salty dog"</code> to <code>"salty OR dog"</code>. It'll work regardless of the number of keywords in the original search query string.</p>
  
  <p>You should probably also make sure that you remove redundant whitespace from the original query, if you don't then a search query like <code>"salty  dog"</code> (double space) will result in a query like <code>"salty OR OR dog"</code>. Here's how you could do that using some regex and the <code>replace</code> filter:</p>
  
  <pre><code>{% set query = craft.request.getParam('q')|replace('/(( )+|(\\n)+)/', ' ')|split(' ')|join(' OR ') %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-09T10:09:17.303Z
Answers.LastActivityDate: 2016-12-09T10:15:17.280Z
Answers.LastEditDate: 2016-12-09T10:15:17.280Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I have the following text search input field:</p>
  
  <pre><code>&lt;form action="{{ url('search') }}"&gt;
      &lt;input type="search" name="q" placeholder="Search"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I would like to search each keyword in the user's query with the OR logic as per <a href="https://craftcms.com/docs/searching" rel="nofollow noreferrer">Craft docs</a>.</p>
  
  <blockquote>
    <p>salty OR dog  containing either “salty” or “dog” (or both).</p>
  </blockquote>
  
  <p>How can I separate the user's text search for "salty dog" so that the search query returns results for "salty" or "dog" instead of only for results containing "salty dog"?</p>
  
  <p>Below is how I currently have the search set up in the template:</p>
  
  <pre><code>{% set query = craft.request.getParam('q') %}
  {% set entries = craft.entries.search('*' ~ query ~ '*').order('score') %}
  {% paginate craft.entries.search('*' ~ query ~ '*').limit(10).order('score') as pageInfo, pageEntries %}
  </code></pre>
  
  <p>I have fuzzy search enabled via config:</p>
  
  <pre><code>'defaultSearchTermOptions' =&gt; array(
     'subLeft' =&gt; true,
     'subRight' =&gt; true,
  ),
  </code></pre>
  
Tags: <search><query>
Title: Searching for any keyword in query
ThreadText: # Searching for any keyword in query
  
  (Asked by: username_0 on 2016-12-09)
  
  I have the following text search input field:
  
  ```
  <form action="{{ url('search') }}">
      <input type="search" name="q" placeholder="Search">
  </form>
  
  ```
  
  I would like to search each keyword in the user's query with the OR logic as per [Craft docs](https://craftcms.com/docs/searching).
  
  > salty OR dog containing either “salty” or “dog” (or both).
  
  How can I separate the user's text search for "salty dog" so that the search query returns results for "salty" or "dog" instead of only for results containing "salty dog"?
  
  Below is how I currently have the search set up in the template:
  
  ```
  {% set query = craft.request.getParam('q') %}
  {% set entries = craft.entries.search('*' ~ query ~ '*').order('score') %}
  {% paginate craft.entries.search('*' ~ query ~ '*').limit(10).order('score') as pageInfo, pageEntries %}
  
  ```
  
  I have fuzzy search enabled via config:
  
  ```
  'defaultSearchTermOptions' => array(
     'subLeft' => true,
     'subRight' => true,
  ),
  
  ```
  
  **Tags:** search, query
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-12-09. Score: 4 | Accepted answer
  
  One way to do it is to split the search query on spaces, and then join it with `'OR'`:
  
  ```
  {% set query = craft.request.getParam('q')|split(' ')|join(' OR ') %}
  {% set entries = craft.entries.search(query).order('score') %}
  
  ```
  
  The above will convert the search term `"salty dog"` to `"salty OR dog"`. It'll work regardless of the number of keywords in the original search query string.
  
  You should probably also make sure that you remove redundant whitespace from the original query, if you don't then a search query like `"salty dog"` (double space) will result in a query like `"salty OR OR dog"`. Here's how you could do that using some regex and the `replace` filter:
  
  ```
  {% set query = craft.request.getParam('q')|replace('/(( )+|(\\n)+)/', ' ')|split(' ')|join(' OR ') %}
  
  ```
  
  
  ---
  
  