Hyperspeed real-time search with caching
Existing addons that implement real-time typeahead search assume that your app already has all the data. ember-hypersearch
lets you query an endpoint directly, and caches results locally for better performance when the same query is repeated.
If you provide the addon with data, it will use that directly and does fuzzy search to find the item.
This addon is tested to work with Ember versions 1.13.x
and up. For versions < 2.0
, you will need to install the excellent ember-get-helper
addon as well.
Because native inputs
are used in this addon, you will need to provide your own template in order to use it on pre-Glimmer versions of Ember (basically anything below 1.13.x
). As this makes for poor testing ergonomics, we do not explicitly test for backwards compatibility please report any issues you might encounter to our issue tracker.
First, install the addon:
$ ember install ember-hypersearch
Then include the hyper-search
component in a template of your choice:
The component can also be used in block form, if you pass it a template:
Note that this addon is designed to work with native inputs, so you will not need to use the {{input}}
helper.
Default: 3
The minimum length for a query before it fetches and returns results.
Default: 0
If > 0
, requests to your endpoint will be debounced by this number of milliseconds to reduce the load on your API.
Default: null
The URL for your endpoint. By default, hyper-search
will do a simple GET
request with q
as a query parameter.
If your endpoint requires a different setup, you should reopen/extend the component and override the request
method. For example:
import HyperSearch from 'ember-hypersearch';
export default HyperSearch.reopen({
request(query) {
// Your AJAX request here
// Must return a `Promise`
}
});
Default: null
Results of the current query are displayed in a ul
element below the input
. If your result is an array of objects, you can optionally specify a key to display in the list of results.
Default: null
An optional placeholder for the hypersearch input.
Default: null
If a closure action / action name is passed to the component, the action will receive the selected result.
Default: null
If a closure action / action name is passed to the component, the action will receive the results of the query.
Default: null
A closure action / action name that will receive a boolean which states if results are being loaded/fetched.
Future versions will allow you to persist results locally via localStorage
or some other storage method. For APIs with data that doesn't change often (e.g. addresses), this will allow for improved UX (search queries will appear to be instantaneous) and reduced load on the endpoint.
git clone
this repositorynpm install
bower install
ember server
- Visit your app at http://localhost:4200.
ember test
ember test --server
ember build
For more information on using ember-cli, visit http://www.ember-cli.com/.