This npm package is a command-line utility to help create autocomplete microservices from text files. It creates the microservice with your data embedded and returns you the URL of the service which you can use in your web forms.
Node.js is required to install the
acsetup utility and an IBM OpenWhisk account to create the serverless microservices.
Ensure you have Node.js and npm installed. Then run:
npm install -g serverless-autocomplete
sudo may also be required before this command in some cases).
Make sure you have downloaded the OpenWhisk command-line utility
ibmcloud fn and have authenticated it with your IBM Cloud credentials.
Creating autocomplete services
You can now create as many autocomplete microservices as you need. Take text file containing the strings you wish to be used. The files should contain one string per line e.g.
George Washington John Adams Thomas Jefferson James Madison James Monroe
To create an autocomplete index, simple run
acsetup with the path to the text file of strings:
> acsetup uspresidents.txt
It will return you:
- the URL of your autocomplete service
- an example
- an HTML snippet that shows your service embedded into a web page
If you don't have data to hand then we've got you covered.
acsetup countries.txtacsetup names.txtacsetup uktowns.txt
Working with the API
Your service URL will look something like this:
USER is your Bluemix username + space e.g.
INDEX is the name of your index e.g.
To perform an autocomplete operation, the API call requires a
term parameter containing the string to be completed:
It outputs a JSON array e.g.
"George H. W. Bush""George W. Bush""George Washington""Gerald Ford"
If no matches are found, an empty array is returned:
The API is compatible with the jQuery Autocomplete API but can be plumbed into any front-end code.