<p>I think the problem originates from the space in your search term: <code>test ticket</code>.
To verify that, could you try altering your query to either</p>

<pre><code>.search('"' ~ searchQuery ~ '"')
</code></pre>

<p>Or</p>

<pre><code>.search('fieldHandle:"' ~ searchQuery ~ '"')
</code></pre>

<p>The latter can be used if the search has to take place in only one field.</p>

CC BY-SA 4.0
2019-03-07T13:25:44.237Z
That indeed solves the problem. Thank you! Accepted this answer.
mike
CC BY-SA 4.0
2019-03-07T12:14:27.750Z
2019-03-07T12:14:27.750Z
Paul
<p>I found out that the problem can be resolved by changing the query from :</p>

<p><code>{% set ticket = craft.entries().search(searchQuery).section('ticketLog').one() %}</code></p>

<p>to</p>

<p><code>{% set ticket = craft.entries().title(searchQuery).section('ticketLog').one() %}</code></p>

CC BY-SA 4.0
2019-03-07T12:09:42.180Z
2019-03-07T12:09:42.180Z
mike
<p>In my project I have a <code>tickets</code> which are edited in multiple steps where each step has it's own front end for. Now, of course. to continue editing an ticket I am required to fetch that exact ticket. </p>

<p>To accomplish this I have a search form include which will be displayed before the form is showed. When the search form returns an entry the form is shown, when this fails the search form include will be shown again.</p>

<p>Lastly: The search does work when I search for an entry where the title does not contain a spacebar, So:</p>

<p>When the title is 'Test' I can find it, when the title is <code>test ticket</code> I can't find it using the search form, even though they do both exist!</p>

<p>My code:</p>

<p>General.php settings:</p>

<pre class="lang-php prettyprint-override"><code>'defaultSearchTermOptions' =&gt; [
    'attribute' =&gt; 'title',
    'exact' =&gt; true,
    'subRight' =&gt; false,
    'subLeft' =&gt; false,
],
</code></pre>

<p>My search form:</p>

<pre class="lang-html prettyprint-override"><code>&lt;form novalidate&gt;
    &lt;input id="search" type="search" name="ticket_number"/&gt;
    &lt;button type="submit"&gt;Search&lt;/button&gt;
&lt;/form&gt;
</code></pre>

<p>My <code>URL</code> after submitting the form:</p>

<pre><code>domain.com?ticket_number=ticket+number+test+search
</code></pre>

<p>My page:</p>

<pre class="lang-php prettyprint-override"><code>{% set searchQuery = craft.app.request.getParam('ticket_number') %}
{% set ticket = craft.entries().search(searchQuery).section('ticketLog').one() %}

{% if ticket|length %}
    &lt;div class="row"&gt;
        &lt;div class="col-12"&gt;
            &lt;div class="card"&gt;
                &lt;div class="card-body"&gt;
                    &lt;h4 class="card-title"&gt;Start Picking - {{ ticket.title }}&lt;/h4&gt;
                    &lt;h6 class="card-subtitle"&gt;Fill in this form to start picking.&lt;/h6&gt;
                    {% include '/_components/includes/form' with {
                        'redirect' : siteUrl,
                        'section_handle' : 'ticketLog',
                        'fields' : [{
                            type : 'datetime',
                            handle : 'pickingStartTime',
                        },{
                            type : 'user',
                            title : 'Picker',
                            query : 'teamleader',
                            required : 'required',
                            size : '12',
                        }, {
                            type : 'submit',
                            text : 'Save Ticket',
                        }]
                    } %}
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

{% else %}
    &lt;p&gt;Your search for “{{ searchQuery }}” didn’t return any Tickets, please try again below.&lt;/p&gt;
    {% include 'ticket_log/forms/search_form.twig' %}
{% endif %}
</code></pre>

<p>Hope someone sees what I am doing wrong there!</p>

<templating><search>
Search query for entries doesn't seem to work correctly
# Search query for entries doesn't seem to work correctly

(Asked by: username_0 on 2019-03-07)

In my project I have a tickets which are edited in multiple steps where each step has it's own front end for. Now, of course. to continue editing an ticket I am required to fetch that exact ticket. 
To accomplish this I have a search form include which will be displayed before the form is showed. When the search form returns an entry the form is shown, when this fails the search form include will be shown again.
Lastly: The search does work when I search for an entry where the title does not contain a spacebar, So:
When the title is 'Test' I can find it, when the title is test ticket I can't find it using the search form, even though they do both exist!
My code:
General.php settings:
'defaultSearchTermOptions' => [
    'attribute' => 'title',
    'exact' => true,
    'subRight' => false,
    'subLeft' => false,
],

My search form:

    
    Search


My URL after submitting the form:
domain.com?ticket_number=ticket+number+test+search

My page:
{% set searchQuery = craft.app.request.getParam('ticket_number') %}
{% set ticket = craft.entries().search(searchQuery).section('ticketLog').one() %}

{% if ticket|length %}
    
        
            
                
                    Start Picking - {{ ticket.title }}
                    Fill in this form to start picking.
                    {% include '/_components/includes/form' with {
                        'redirect' : siteUrl,
                        'section_handle' : 'ticketLog',
                        'fields' : [{
                            type : 'datetime',
                            handle : 'pickingStartTime',
                        },{
                            type : 'user',
                            title : 'Picker',
                            query : 'teamleader',
                            required : 'required',
                            size : '12',
                        }, {
                            type : 'submit',
                            text : 'Save Ticket',
                        }]
                    } %}
                
            
        
    

{% else %}
    Your search for “{{ searchQuery }}” didn’t return any Tickets, please try again below.
    {% include 'ticket_log/forms/search_form.twig' %}
{% endif %}

Hope someone sees what I am doing wrong there!

**Tags:** templating, search

---

## 2 answers

### Answer by username_1 on 2019-03-07. Score: 1 | Accepted answer

I think the problem originates from the space in your search term: test ticket.
To verify that, could you try altering your query to either
.search('"' ~ searchQuery ~ '"')

Or
.search('fieldHandle:"' ~ searchQuery ~ '"')

The latter can be used if the search has to take place in only one field.

> **Comments:**
> **username_0**: That indeed solves the problem. Thank you! Accepted this answer.  

---

### Answer by username_0 on 2019-03-07. Score: 0

I found out that the problem can be resolved by changing the query from :

`{% set ticket = craft.entries().search(searchQuery).section('ticketLog').one() %}`

to

`{% set ticket = craft.entries().title(searchQuery).section('ticketLog').one() %}`


---

