* Tokenize the given document. * @param {string} filename - key for the storage in redis * @param {string} document - Collection of words to be tokenized * @returns {Promise }
(filename, document)
| 76 | * @returns {Promise<void>} |
| 77 | */ |
| 78 | async add(filename, document) { |
| 79 | const PUNCTUATION = ['.', ',', ':', '']; |
| 80 | const tokenizer = new natural.WordTokenizer(); |
| 81 | const tokens = tokenizer.tokenize(document); |
| 82 | // filter out punctuation, then add all tokens to a redis set. |
| 83 | await Promise.all( |
| 84 | tokens |
| 85 | .filter(token => PUNCTUATION.indexOf(token) === -1) |
| 86 | .map(token => this.tokenClient.sAdd(token, filename)) |
| 87 | ); |
| 88 | await this.docsClient.set(filename, document); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Lookup files that contain a given set of words in redis |
no test coverage detected