<p>I have an endpoint for searching entries via the element api.</p>
<pre><code>'api/searchtherest.json' =&gt; function () {

            $section_handle = 'openFunding';

            $criteria = [
                'section' =&gt; $section_handle,
                'openForFunding' =&gt; true,
                'search' =&gt; ($q = Craft::$app-&gt;request-&gt;getParam('query'))
                    ? &quot;-title:*\&quot;{$q}\&quot;*&quot;
                    : null
            ];

            return [
                'elementType' =&gt; Entry::class,
                'criteria' =&gt; $criteria,
                'paginate' =&gt; false,
                'pretty' =&gt; false,
                'transformer' =&gt; function (craft\elements\Entry $entry) {

                    return [
                        'id' =&gt; $entry-&gt;id,
                        'title' =&gt; $entry-&gt;title,
                        'localauthority' =&gt; $entry-&gt;ladnm,
                        'mapitAreaId' =&gt; $entry-&gt;mapitAreaId,
                        'fundableRegion' =&gt; $entry-&gt;fundableRegion,
                        'openForFunding' =&gt; $entry-&gt;openForFunding,
                        'geojson' =&gt; json_decode($entry-&gt;geojson),
                        'lsoacode' =&gt; $entry-&gt;lsoacode
                    ];
                },

            ];
        },

</code></pre>
<p>Because the titles have spaces i am following Brandon's advice here
<a href="https://github.com/craftcms/cms/issues/2702" rel="nofollow noreferrer">https://github.com/craftcms/cms/issues/2702</a></p>
<p>But wrapping the query in quotes still produces zero data.
What am I missing?</p>

CC BY-SA 4.0
2021-12-16T04:11:14.127Z
In your query "-title:*\"{$q}\"*" try to remove the - in the start of the query, is there result still same?
aodihis
CC BY-SA 4.0
2021-12-16T09:27:24.073Z
That's the exclude flag - the result with or without is still no data. Weird and a real blocker
joomkit
CC BY-SA 4.0
2021-12-16T15:28:57.243Z
Do you get the right results searching in your control panel? As in, are things correctly indexed?
Oli
CC BY-SA 4.0
2021-12-16T15:31:26.210Z
Interesting - I took the "-" not exclude flag out and cleared the element-api cache and get results with the space. So i think the question becomes how do i exclude results in an element-api search query that includes a space.....maybe a bug ?
joomkit
<search><plugin-elementapi>
Element-api search with space in query returns zero data
# Element-api search with space in query returns zero data

(Asked by: username_0 on 2021-12-15)

I have an endpoint for searching entries via the element api.
'api/searchtherest.json' => function () {

            $section_handle = 'openFunding';

            $criteria = [
                'section' => $section_handle,
                'openForFunding' => true,
                'search' => ($q = Craft::$app->request->getParam('query'))
                    ? "-title:*\"{$q}\"*"
                    : null
            ];

            return [
                'elementType' => Entry::class,
                'criteria' => $criteria,
                'paginate' => false,
                'pretty' => false,
                'transformer' => function (craft\elements\Entry $entry) {

                    return [
                        'id' => $entry->id,
                        'title' => $entry->title,
                        'localauthority' => $entry->ladnm,
                        'mapitAreaId' => $entry->mapitAreaId,
                        'fundableRegion' => $entry->fundableRegion,
                        'openForFunding' => $entry->openForFunding,
                        'geojson' => json_decode($entry->geojson),
                        'lsoacode' => $entry->lsoacode
                    ];
                },

            ];
        },


Because the titles have spaces i am following Brandon's advice here
https://github.com/craftcms/cms/issues/2702
But wrapping the query in quotes still produces zero data.
What am I missing?

**Tags:** search, plugin-elementapi
> **Comments:**
> **username_1**: In your query "-title:*\"{$q}\"*" try to remove the - in the start of the query, is there result still same?  
> **username_0**: That's the exclude flag - the result with or without is still no data. Weird and a real blocker  
> **username_2**: Do you get the right results searching in your control panel? As in, are things correctly indexed?  
> **username_0**: Interesting - I took the "-" not exclude flag out and cleared the element-api cache and get results with the space. So i think the question becomes how do i exclude results in an element-api search query that includes a space.....maybe a bug ?  

---

## 0 answers

