TYPO3-Solr / ext-solr

A TYPO3 extension that integrates the Apache Solr search server with TYPO3 CMS. dkd Internet Service GmbH is developing the extension. Community contributions are welcome. See CONTRIBUTING.md for details.
GNU General Public License v3.0
136 stars 248 forks source link

[FEATURE] Use state of the art autocomplete Code #2832

Open georgringer opened 3 years ago

georgringer commented 3 years ago

Currently, the autocomplete does use jQuery for just doing a basic ajax call and processing the data. More and more websites don't need jQuery and use more state of the art code.

I propose changing the provided code with the next major version and use a simplier vanilla js code or what would be also possible to ship this as another solution and keep jquery - just to make it easier for everybody

In a latest project I am using https://lit-html.polymer-project.org/ (which is also used by the core in 11 (see https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/11.0/Feature-91810-IntroduceLit-htmlAndLit-elementAsClient-sideTemplatingEngine.html) but this is totally optional

I can't share the project url yet right now as it is not in production but will be happy to help if there are any questions. The code without templating is as basic as

  static autocomplete() {
    var input = document.getElementById('search');

    const debounce = (func, wait, immediate) => {
      let timeout

      return function () {
        const context = this, args = arguments
        const later = function () {
          timeout = null
          if (!immediate) func.apply(context, args)
        }

        const callNow = immediate && !timeout
        clearTimeout(timeout)
        timeout = setTimeout(later, wait)
        if (callNow) func.apply(context, args)
      }
    }

    document.querySelector('#search').addEventListener('input', debounce(() => {
      const uri = input.getAttribute('data-suggest-url') + '?tx_solr[queryString]=' + input.value;
      fetch(uri)
        .then((response) => {
          return response.json()
        })
        .then((data) => {
          // do stuff
          // 
        })
        .catch((err) => {
          console.log(err);

        })
    }, 300))
  }

Important to know: due to using promises latest technologies like promises and fetch, the code won't work in IE 11

dkd-kaehm commented 3 years ago

@georgringer Would you like to implement the suggest controller client part with lit-html? We'll release the EXT:solr v 11.5 for TYPO3 11 this year. Would be nice to begin to deprecate and throw a jquery stuff in EXT:solr.

georgringer commented 3 years ago

@dkd-kaehm let's maybe discuss on slack?