| 130 | return parsed.toString() |
| 131 | } |
| 132 | async function analyzeVersion(client, texts, indexName, verbose = false) { |
| 133 | for (const text of texts) { |
| 134 | console.log(`RAW TEXT: 〝${chalk.italic(text)}〞`) |
| 135 | for (const analyzer of ['text_analyzer_explicit', 'text_analyzer', 'standard']) { |
| 136 | console.log('ANALYZER:', chalk.bold(analyzer)) |
| 137 | const response = await client.indices.analyze({ |
| 138 | index: indexName, |
| 139 | body: { analyzer, text }, |
| 140 | }) |
| 141 | if (response.statusCode !== 200) { |
| 142 | console.warn(response) |
| 143 | throw new Error(`${response.statusCode} on ${indexName}`) |
| 144 | } |
| 145 | const { |
| 146 | body: { tokens }, |
| 147 | } = response |
| 148 | const tokenWords = tokens.map((token) => token.token) |
| 149 | console.log(tokenWords) |
| 150 | } |
| 151 | } |
| 152 | } |