Answers.Body: <p>If you want to enable fuzzy searching globally (across the entire Craft install - CP, front-end, ElementAPI, etc.), you can use the <a href="https://craftcms.com/docs/config-settings#defaultSearchTermOptions" rel="nofollow">defaultSearchTerms</a> config setting.</p>
  
  <p>You can also just do it programmatically from the ElementAPI plugin with something like:</p>
  
  <p>Suffix wildcard:</p>
  
  <pre><code>'criteria' =&gt; ['title' =&gt; $search ~ '*']
  </code></pre>
  
  <p>Prefix wildcard:</p>
  
  <pre><code>'criteria' =&gt; ['title' =&gt; '*' ~ $search]
  </code></pre>
  
  <p>Both sides:</p>
  
  <pre><code>'criteria' =&gt; ['title' =&gt; '*' ~ $search ~ '*']
  </code></pre>
  
  <p>Or you can use any of the other search syntaxes listed on the <a href="https://craftcms.com/docs/searching#supported-syntaxes" rel="nofollow">search docs</a> page.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-07T18:12:24.760Z
Answers.LastActivityDate: 2016-10-07T18:12:24.760Z
Answers.UserDisplayName: Brad Bell
Body: <p>What is the best way to implement a typeahead search in Craft. I looked at using ElementAPI to do something similar at this example but it doesn't seem to allow me to wildcard search</p>
  
  <p><a href="https://craftcms.com/docs/templating/search-form" rel="nofollow">https://craftcms.com/docs/templating/search-form</a></p>
  
  <p>Here's an example of the endpoints I have configured:</p>
  
  <p>I have one entry with a title of "test" when I call the API doing </p>
  
  <p>When I call <code>/entries/te</code> its returns 0 results. When I call <code>/entries/test</code> it returns 1 result.</p>
  
  <pre><code>&lt;?php
  
  namespace Craft;
  return [
      'endpoints' =&gt; [
  
          'entries/&lt;search:\w+&gt;' =&gt; function($search) {
              return [
                  'elementType' =&gt; 'Entry',
                  'criteria' =&gt; ['title' =&gt; $search]
              ];
          }
  
      ]
  ];
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-06T18:12:13.820Z
Comments.Text: Could you elaborate on what you mean by "wildcard search?" What have you tried, already, within your `criteria` block in the ElementAPI configuration?
Comments.UserDisplayName: August Miller
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-06T18:30:36.633Z
Comments.Text: Essentially,  I want to be able to search for entries using any syntaxes mention here https://craftcms.com/docs/searching. When I use the ElementAPI is only returns the results when using the exact word.
Comments.UserDisplayName: jpoiri
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-06T18:37:29.923Z
Comments.Text: Can you edit the original question and share the relevant portion of your Element API config where you're trying to perform the search?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-06T20:15:07.777Z
Comments.Text: Ahh, not so much element-api related, but basically this answer is what you're looking for I'm guessing? http://craftcms.stackexchange.com/a/5477/57
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-07T13:32:50.293Z
Comments.Text: @BradBell this is exactly what I would like to do but throught the ElementAPI so  can return JSON
Comments.UserDisplayName: jpoiri
Tags: <search>
Title: Implementing search with Ajax
ThreadText: # Implementing search with Ajax
  
  (Asked by: username_0 on 2016-10-06)
  
  What is the best way to implement a typeahead search in Craft. I looked at using ElementAPI to do something similar at this example but it doesn't seem to allow me to wildcard search
  
  <https://craftcms.com/docs/templating/search-form>
  
  Here's an example of the endpoints I have configured:
  
  I have one entry with a title of "test" when I call the API doing
  
  When I call `/entries/te` its returns 0 results. When I call `/entries/test` it returns 1 result.
  
  ```
  <?php
  
  namespace Craft;
  return [
      'endpoints' => [
  
          'entries/<search:\w+>' => function($search) {
              return [
                  'elementType' => 'Entry',
                  'criteria' => ['title' => $search]
              ];
          }
  
      ]
  ];
  
  ```
  
  **Tags:** search
  
  > **Comments:**
  > **username_1**: Could you elaborate on what you mean by "wildcard search?" What have you tried, already, within your `criteria` block in the ElementAPI configuration?  
  > **username_0**: Essentially,  I want to be able to search for entries using any syntaxes mention here https://craftcms.com/docs/searching. When I use the ElementAPI is only returns the results when using the exact word.  
  > **username_2**: Can you edit the original question and share the relevant portion of your Element API config where you're trying to perform the search?  
  > **username_2**: Ahh, not so much element-api related, but basically this answer is what you're looking for I'm guessing? http://craftcms.stackexchange.com/a/5477/57  
  > **username_0**: @username_2 this is exactly what I would like to do but throught the ElementAPI so  can return JSON  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-10-07. Score: 2
  
  If you want to enable fuzzy searching globally (across the entire Craft install - CP, front-end, ElementAPI, etc.), you can use the [defaultSearchTerms](https://craftcms.com/docs/config-settings#defaultSearchTermOptions) config setting.
  
  You can also just do it programmatically from the ElementAPI plugin with something like:
  
  Suffix wildcard:
  
  ```
  'criteria' => ['title' => $search ~ '*']
  
  ```
  
  Prefix wildcard:
  
  ```
  'criteria' => ['title' => '*' ~ $search]
  
  ```
  
  Both sides:
  
  ```
  'criteria' => ['title' => '*' ~ $search ~ '*']
  
  ```
  
  Or you can use any of the other search syntaxes listed on the [search docs](https://craftcms.com/docs/searching#supported-syntaxes) page.
  
  
  ---
  
  