redis-autocomplete-hangul

0.3.1 • Public • Published

redis-autocomplete-hangul

NPM version Build Status Dependency Status Coverage percentage

Redis autocomplete with support for Hangul

Installation

$ npm install --save redis-autocomplete-hangul

Usage Example

const createAutocompleteIndexer = require('redis-autocomplete-hangul');
const AutocompleteIndexer = createAutocompleteIndexer({
  redis: {
    host: 'localhost',
    port: 6379
  }
});
 
Promise.all([
  AutocompleteIndexer.index('가내수공업'),
  AutocompleteIndexer.index('가나'),
  AutocompleteIndexer.index('가나초콜렛'),
  AutocompleteIndexer.index('가부장적')
]).then(() => {
  return AutocompleteIndexer.query('가ㄴ')
}).then(results => {
  console.log(results);
  // ['가나', '가나초콜렛', '가내수공업']
  return AutocompleteIndexer.remove('가내수공업');
}).then(() => {
  return AutocompleteIndexer.query('가ㄴ');
}).then(results => {
  console.log(results);
  // ['가나', '가나초콜렛']
});
 

API

createAutocompleteIndexer(options)

This return AutocompleteIndexer. You should provide redis connection information in options. Additional options are hashKey and maxCacheLength.

Options

  • hashKey: defaults 'ac'. This option changes redis namespace.
  • maxCacheLength: defaults 15. First maxCacheLength characters in indexed word are cached in redis for autocomplete suggestion.
const createAutocompleteIndexer = require('redis-autocomplete-hangul');
const AutocompleteIndexer = createAutocompleteIndexer({
  // redis connection information is required
  redis: {
    host: 'localhost',
    port: 6379
  },
  // others are optional
  hashKey: 'ac',
  maxCacheLength: 15
});

AutocompleteIndexer.index(word)

This indexes word. Indexed words can be queried using AutocompleteIndexer.query method.

AutoCompleteIndexer.index('파리, 프랑스');

AutocompleteIndexer.query(characters[, options])

This queries characters on indexed words. Indexed words starting with the characters will be retrieved from the redis. It returns promise object with array of strings. You can set query results count using options.count (default 5).

AutoCompleteIndexer.query('');
AutoCompleteIndexer.query('', {count: 10});

AutocompleteIndexer.remove(word)

This removes the indexed word. Removed words cannot be queried using AutocompleteIndexer.query method.

AutoCompleteIndexer.remove('파리, 프랑스');

Acknowledgement

Antirez

License

MIT © Dongwon Lim

Package Sidebar

Install

npm i redis-autocomplete-hangul

Weekly Downloads

1

Version

0.3.1

License

MIT

Last publish

Collaborators

  • idw111