TriplyDB / Yasgui

Yet Another Sparql GUI
https://yasgui.triply.cc
MIT License
190 stars 55 forks source link

Combining mutiple autocompleters #176

Closed semanticfire closed 3 years ago

semanticfire commented 3 years ago

Is it possible to use multiple autocompleters and combine the results, I want to use the standard LOV and then extend that with some of our internal vocabulaires.

LaurensRietveld commented 3 years ago

Hi @semanticfire , you can use the forkAutocompleter functionality here. Make sure to run this before instantiating yasqe

//Disable property completer
Yasqe.defaults.autocompleters.splice(Yasqe.defaults.autocompleters.indexOf("property"), 1);
//Add a new one, based on the property completer we just disabled
Yasqe.forkAutocompleter("property", {
      name: "customPropertyCompleter",
      get: (yasqe, token) => {
        if (!token) return [];
        return Promise.all([
          Yasqe.Autocompleters.property.get(yasqe, token),//fetch using regular lov autocompleter
          Promise.resolve([token.autocompletionString + 'someOtherSuggestion'])
        ]).then(results => {
          return [...results[0], ...results[1]]
        })
      }
    });