title: Run AlgoliaSearch Autocomplete if query text is greater than 3-4 characters
body: <p>I am trying to limit AlgoliaSearch to show results for Autocomplete only if the uer types more than 3-4 charchters in the input box, I have tried using keypress event in jquery to do this but unfortunately that does not work, I tried searching Algolia blogs but to no avail. Below is my code,</p>
  <pre><code>var initvalues = initvariables;
      var url = userdetails['webroot'];
      console.log(initvalues);
      console.log(url);
      var fileName = '';
      if (url.includes('qa')|| url.includes('dev') || url.includes('localhost')) {
          fileName = &quot;constants-dev.json&quot;;
      } else if(url.includes('pp')|| url.includes('pre-prod')) {
          fileName = &quot;constants-preprod.json&quot;;
      } else {
          fileName = &quot;constants-prod.json&quot;;
      }
  
      var directory = window.location.pathname.split('/')[1];
  
      var json = $.getJSON({'url': location.protocol + '//' + location.host +'/'+  directory +  '/blocks/algoliasearch/'+ fileName, 'async': false});
      json = JSON.parse(json.responseText);
      console.log(json);
  
      var client = algoliasearch(json.appId, json.apiKey);
      
      var clientIndex = json.current_index;
      var index = client.initIndex(clientIndex);
      console.log(&quot;Index&quot; + JSON.stringify(index));
      console.log(autocomplete.sources.hits(index, this.userFilters(userdetails)))
      if (document.getElementsByTagName('html')[0].getAttribute('lang') == 'en' || document.getElementsByTagName('html')[0].getAttribute('xml:lang') == 'en') {
          var myAutoComplete = autocomplete('#searchform_search', { hint: false }, [
              {
                  source: autocomplete.sources.hits(index, this.userFilters(userdetails)),
                  displayKey: 'title.en',
                  templates: {
                      suggestion: function (suggestion) {
                          var sugTemplate = '';
                          if (suggestion.modalite.en == 'Online') {
                              sugTemplate += '&lt;span class=&quot;ena-aamodalonline&quot;&gt;&lt;/span&gt;';
                          } else if (suggestion.modalite.en == 'In Person') {
                              sugTemplate += '&lt;span class=&quot;ena-aamodalinperson&quot;&gt;&lt;/span&gt;';
                          } else {
                              sugTemplate += '&lt;span class=&quot;ena-aamodalhybrid&quot;&gt;&lt;/span&gt;';
                          }
  
                          //sugTemplate += '&lt;img src=&quot;&quot;&gt;'; // Where course's images would be displayed
                          sugTemplate += '&lt;a class=&quot;ena-aaresult&quot; href=&quot;'+url+'/course/view.php?id='+suggestion.courseid+'&quot;&gt;'+suggestion.title.en+'&lt;/a&gt;';
                          /*if (suggestion.partageable == 'Locale') {
                              sugTemplate += '&lt;span class=&quot;ena-aalocal&quot;&gt;Local&lt;/span&gt;';
                          } else {
                              sugTemplate += '&lt;span class=&quot;ena-aapart&quot;&gt;Shareable&lt;/span&gt;';
                          }
                          sugTemplate += '&lt;span class=&quot;ena-aaest&quot;&gt;'+suggestion.establishmentfullname+'&lt;/span&gt;';*/
                          //sugTemplate += '&lt;hr/&gt;';
                          return sugTemplate;
                      }
                  }
              }
          ]).on('autocomplete:selected', function (event, suggestion, dataset) {
              console.log(suggestion);
              console.log(dataset)
              window.location.href = url+'/course/view.php?id='+suggestion.courseid;
          });
  
  
  
      } else {
          var myAutoComplete = autocomplete('#searchform_search', { hint: false }, [
              {
                  source: autocomplete.sources.hits(index, this.userFilters(userdetails)),
                  displayKey: 'title.fr',
                  templates: {
                      suggestion: function (suggestion) {
                          var sugTemplate = '';
                          if (suggestion.modalite.en == 'Online') {
                              sugTemplate += '&lt;span class=&quot;ena-aamodalonline&quot;&gt;&lt;/span&gt;';
                          } else if (suggestion.modalite.en == 'In Person') {
                              sugTemplate += '&lt;span class=&quot;ena-aamodalinperson&quot;&gt;&lt;/span&gt;';
                          } else {
                              sugTemplate += '&lt;span class=&quot;ena-aamodalhybrid&quot;&gt;&lt;/span&gt;';
                          }
  
                          //sugTemplate += '&lt;img src=&quot;&quot;&gt;'; // Where course's images would be displayed
                          sugTemplate += '&lt;a class=&quot;ena-aaresult&quot; href=&quot;'+url+'/course/view.php?id='+suggestion.courseid+'&quot;&gt;'+suggestion.title.fr+'&lt;/a&gt;';
                          /*if (suggestion.partageable == 'Locale') {
                              sugTemplate += '&lt;span class=&quot;ena-aalocal&quot;&gt;'+suggestion.partageable+'&lt;/span&gt;';
                          } else {
                              sugTemplate += '&lt;span class=&quot;ena-aapart&quot;&gt;'+suggestion.partageable+'&lt;/span&gt;';
                          }
                          sugTemplate += '&lt;span class=&quot;ena-aaest&quot;&gt;'+suggestion.establishmentfullname+'&lt;/span&gt;';*/
  
                          //sugTemplate += '&lt;hr/&gt;';
                          return sugTemplate;
                      }
                  }
              }
          ]).on('autocomplete:selected', function (event, suggestion, dataset) {
              //alert($('#algoliasearchinput.value') + &quot;  &quot; + JSON.stringify($('#algoliasearchinput.value')));
              window.location.href = url+'/course/view.php?id='+suggestion.courseid;
          });
      }
   
  }
  </code></pre>
  <p>I am unable to parse the query as the function expects the selector as parameter, how can I modify it so as the autocomplete only run when input <code>searchform_search</code> only has more 3 characters in it.</p>
  <p>Below is the Codepen for a working prototype: <a href="https://codepen.io/karankia/pen/eYyGQbE" rel="nofollow noreferrer">https://codepen.io/karankia/pen/eYyGQbE</a></p>