<p>The light switch value should be taken out of the search query and put into the entry query:</p>

<pre><code>{% set query = 'title:"' ~ "myValue" ~ '"' %}
{% set results = craft.entries({
    section: querySections,
    search: query,
    excludeFromSearch: 'not 1',
    orderBy: 'score',
    }).limit(50) %}
</code></pre>

<p>Or slightly cleaner / Craft 3:</p>

<pre><code>{% set query = 'title:"' ~ "myValue" ~ '"' %}
{% set entryQuery = craft.entries
    .section(querySections)
    .search(query)
    .excludeFromSearch('not 1')
    .orderBy('score')
    .limit(50)
%}

{% set entries = entryQuery.all() %}
</code></pre>

CC BY-SA 4.0
2019-11-11T18:18:36.410Z
Weird. It wasn't entirely clear from the documentation that you can do this. Thanks!
4midori
CC BY-SA 4.0
2019-11-11T11:37:04.400Z
2019-11-11T11:43:03.983Z
2019-11-11T11:43:03.983Z
dmatthams
<p>I want to find all entries that match the <em>title</em> field where excludeFromSearch != 1 (is false).</p>

<pre><code>{% set query = 'and excludeFromSearch not 1 and ' ~ 'title:"' ~ "myValue" ~ '"' %}

    {% set results = craft.entries({
    section: querySections,
    search: query,
    orderBy: 'score',
    }).limit(50) %}
</code></pre>

<p>It does not work. My field <em>excludeFromSearch</em> is a lightswitch.</p>

<search><query><exclude>
Excluding specific field value from search
# Excluding specific field value from search

(Asked by: username_0 on 2019-11-08)

I want to find all entries that match the title field where excludeFromSearch != 1 (is false).
{% set query = 'and excludeFromSearch not 1 and ' ~ 'title:"' ~ "myValue" ~ '"' %}

    {% set results = craft.entries({
    section: querySections,
    search: query,
    orderBy: 'score',
    }).limit(50) %}

It does not work. My field excludeFromSearch is a lightswitch.

**Tags:** search, query, exclude

---

## 1 answers

### Answer by username_1 on 2019-11-11. Score: 4 | Accepted answer

The light switch value should be taken out of the search query and put into the entry query:
{% set query = 'title:"' ~ "myValue" ~ '"' %}
{% set results = craft.entries({
    section: querySections,
    search: query,
    excludeFromSearch: 'not 1',
    orderBy: 'score',
    }).limit(50) %}

Or slightly cleaner / Craft 3:
{% set query = 'title:"' ~ "myValue" ~ '"' %}
{% set entryQuery = craft.entries
    .section(querySections)
    .search(query)
    .excludeFromSearch('not 1')
    .orderBy('score')
    .limit(50)
%}

{% set entries = entryQuery.all() %}

> **Comments:**
> **username_0**: Weird. It wasn't entirely clear from the documentation that you can do this. Thanks!  

---

