0.3.1 • Published 8 years ago

redis-autocomplete-hangul v0.3.1

Weekly downloads
5
License
MIT
Repository
github
Last release
8 years ago

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

0.3.1

8 years ago

0.3.0

8 years ago

0.2.9

8 years ago

0.2.8

8 years ago

0.2.7

8 years ago

0.2.6

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago