Answers.Body: <p>Following is an example of using the search feature in a GET request with parameter 'search'.  </p>
  
  <pre><code>return [
      'elementType' =&gt; 'Entry',
      'criteria' =&gt; ['search' =&gt; (craft()-&gt;request-&gt;getParam('search')) ? 'title:'.craft()-&gt;request-&gt;getParam('search') : '' ],
      'paginate' =&gt; true,
      'elementsPerPage' =&gt; 10,
      'pageParam' =&gt; 'pg',
      'transformer' =&gt; new ListTransformer(),
  ];`
  </code></pre>
  
  <p>I assume you can use this instead of the custom transformer class that is being used in the above example:</p>
  
  <pre><code>'transformer' =&gt; function(EntryModel $entry) {
      return [
          'title' =&gt; $entry-&gt;title,
          'url' =&gt; $entry-&gt;url,
          'summary' =&gt; $entry-&gt;summary,
          'body' =&gt; $entry-&gt;body,
      ];
  },
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-01T14:06:15.453Z
Answers.Text: How would I use this in the URL? Like this: `search.json?search=title:test` ?
Answers.UserDisplayName: Erik
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-01T14:16:44.820Z
Answers.Text: URL format is correct I haven't delved too deeply into search syntax for parameters like title:test
  mine is search.json?search=test that is global search
Answers.UserDisplayName: Mark Watson
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-01T14:18:37.523Z
Answers.Text: The syntax for search=title:test is correct
Answers.UserDisplayName: Mark Watson
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-01T14:18:39.190Z
Answers.Text: Hmm, ok. Doesn't seem to fetch anything. I will tinker with it. Thanks.
Answers.UserDisplayName: Erik
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-01T14:23:52.993Z
Answers.Text: Try this
  `title:"*test*"`
Answers.UserDisplayName: Mark Watson
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-01T14:30:15.860Z
Answers.Text: Negative, I updated with two different approaches I tried.
Answers.UserDisplayName: Erik
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-01T14:31:42.790Z
Answers.Text: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/40609/discussion-between-green-plastic-and-mark-watson).
Answers.UserDisplayName: Erik
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-01T13:57:59.780Z
Answers.LastActivityDate: 2016-06-02T05:21:25.257Z
Answers.LastEditDate: 2016-06-02T05:21:25.257Z
Answers.UserDisplayName: Mark Watson
Body: <p>I can't seem to find this anywhere. Thanks.</p>
  
  <p><strong>Update:</strong></p>
  
  <pre><code>'api/entry/search.json' =&gt; function() {
      return [
          'elementType' =&gt; 'Entry',
          'criteria' =&gt; [
              'search' =&gt; (craft()-&gt;request-&gt;getParam('search')) ? craft()-&gt;request-&gt;getParam('search') : '' 
          ],
          'first' =&gt; true,
          'transformer' =&gt; function(EntryModel $entry) {
              return [
                  'title' =&gt; $entry-&gt;title,
                  'url' =&gt; $entry-&gt;url,
              ];
          },
      ];
  },
  </code></pre>
  
  <p>Using the url: <code>api/entry/search.json?search=title:test</code> did not work.</p>
  
  <hr>
  
  <p>This code works, but the title needs to be exact:</p>
  
  <pre><code>'api/entry/search.json' =&gt; function() {
      return [
          'elementType' =&gt; 'Entry',
          'criteria' =&gt; [
              'title' =&gt; craft()-&gt;request-&gt;getParam('title')
          ],
          'first' =&gt; true,
          'transformer' =&gt; function(EntryModel $entry) {
              return [
                  'title' =&gt; $entry-&gt;title,
                  'url' =&gt; $entry-&gt;url,
              ];
          },
      ];
  },
  </code></pre>
  
  <p>Using this url: <code>api/entry/search.json?title=Test%20Article</code>, works, but not <code>api/entry/search.json?title=Test</code></p>
  
Tags: <plugin-elementapi>
Title: How do I use the Element API to search via entry title?
ThreadText: # How do I use the Element API to search via entry title?
  
  (Asked by: username_0 on 2016-06-01)
  
  I can't seem to find this anywhere. Thanks.
  
  **Update:**
  
  ```
  'api/entry/search.json' => function() {
      return [
          'elementType' => 'Entry',
          'criteria' => [
              'search' => (craft()->request->getParam('search')) ? craft()->request->getParam('search') : '' 
          ],
          'first' => true,
          'transformer' => function(EntryModel $entry) {
              return [
                  'title' => $entry->title,
                  'url' => $entry->url,
              ];
          },
      ];
  },
  
  ```
  
  Using the url: `api/entry/search.json?search=title:test` did not work.
  
  ---
  
  This code works, but the title needs to be exact:
  
  ```
  'api/entry/search.json' => function() {
      return [
          'elementType' => 'Entry',
          'criteria' => [
              'title' => craft()->request->getParam('title')
          ],
          'first' => true,
          'transformer' => function(EntryModel $entry) {
              return [
                  'title' => $entry->title,
                  'url' => $entry->url,
              ];
          },
      ];
  },
  
  ```
  
  Using this url: `api/entry/search.json?title=Test%20Article`, works, but not `api/entry/search.json?title=Test`
  
  **Tags:** plugin-elementapi
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-06-01. Score: 5 | Accepted answer
  
  Following is an example of using the search feature in a GET request with parameter 'search'.
  
  ```
  return [
      'elementType' => 'Entry',
      'criteria' => ['search' => (craft()->request->getParam('search')) ? 'title:'.craft()->request->getParam('search') : '' ],
      'paginate' => true,
      'elementsPerPage' => 10,
      'pageParam' => 'pg',
      'transformer' => new ListTransformer(),
  ];`
  
  ```
  
  I assume you can use this instead of the custom transformer class that is being used in the above example:
  
  ```
  'transformer' => function(EntryModel $entry) {
      return [
          'title' => $entry->title,
          'url' => $entry->url,
          'summary' => $entry->summary,
          'body' => $entry->body,
      ];
  },
  
  ```
  
  > **Comments:**
  > **username_0**: How would I use this in the URL? Like this: `search.json?search=title:test` ?  
  > **username_1**: URL format is correct I haven't delved too deeply into search syntax for parameters like title:test mine is search.json?search=test that is global search  
  > **username_1**: The syntax for search=title:test is correct  
  > **username_0**: Hmm, ok. Doesn't seem to fetch anything. I will tinker with it. Thanks.  
  > **username_1**: Try this `title:"*test*"`  
  > **username_0**: Negative, I updated with two different approaches I tried.  
  > **username_0**: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/40609/discussion-between-green-plastic-and-mark-username_1).  
  
  ---
  
  