|
| 1 | +# Analyzer API |
| 2 | + |
| 3 | +These functions implement the |
| 4 | +[HTTP API for manipulating analyzers](https://docs.arangodb.com/latest/HTTP/Analyzers.html). |
| 5 | + |
| 6 | +{% hint 'info' %} |
| 7 | +Analyzers were introduced in ArangoDB 3.5 and are not supported by earlier |
| 8 | +versions of ArangoDB. |
| 9 | +{% endhint %} |
| 10 | + |
| 11 | +## analyzer.exists |
| 12 | + |
| 13 | +`async analyzer.exists(): boolean` |
| 14 | + |
| 15 | +Checks whether the analyzer exists. |
| 16 | + |
| 17 | +**Examples** |
| 18 | + |
| 19 | +```js |
| 20 | +const db = new Database(); |
| 21 | +const analyzer = db.analyzer("some-analyzer"); |
| 22 | +const result = await analyzer.exists(); |
| 23 | +// result indicates whether the analyzer exists |
| 24 | +``` |
| 25 | + |
| 26 | +### analyzer.get |
| 27 | + |
| 28 | +`async analyzer.get(): Object` |
| 29 | + |
| 30 | +Retrieves the analyzer definition for the analyzer. |
| 31 | + |
| 32 | +**Examples** |
| 33 | + |
| 34 | +```js |
| 35 | +const db = new Database(); |
| 36 | +const analyzer = db.analyzer("some-analyzer"); |
| 37 | +const definition = await analyzer.get(); |
| 38 | +// definition contains the analyzer definition |
| 39 | +``` |
| 40 | + |
| 41 | +## analyzer.create |
| 42 | + |
| 43 | +`async analyzer.create([options]): Object` |
| 44 | + |
| 45 | +Creates an analyzer with the given _options_, then returns the new analyzer |
| 46 | +definition. |
| 47 | + |
| 48 | +**Arguments** |
| 49 | + |
| 50 | +- **options**: `Object` (optional) |
| 51 | + |
| 52 | + An object with the following properties: |
| 53 | + |
| 54 | + - **features**: `string` (optional) |
| 55 | + |
| 56 | + The features to enable for this analyzer. |
| 57 | + |
| 58 | + - **type**: `string` |
| 59 | + |
| 60 | + The type of analyzer to create. |
| 61 | + Can be `"identity"`, `"delimiter"`, `"stem"`, `"norm"`, `"ngram"` or |
| 62 | + `"text"`. |
| 63 | + |
| 64 | + - **properties**: `any` |
| 65 | + |
| 66 | + Additional properties for the given analyzer type. |
| 67 | + |
| 68 | + If the type is `"identity"`, the _properties_ are optional or can be |
| 69 | + `undefined` or `null`. |
| 70 | + |
| 71 | + If the type is `"delimiter"`, the _properties_ must be an object with the |
| 72 | + following property: |
| 73 | + |
| 74 | + - **delimiter**: `string` |
| 75 | + |
| 76 | + Delimiter to use to split text into tokens as specified in RFC 4180, |
| 77 | + without starting new records on newlines. |
| 78 | + |
| 79 | + If the type is `"stem"`, the _properties_ must be an object with the |
| 80 | + following property: |
| 81 | + |
| 82 | + - **locale**: `string` |
| 83 | + |
| 84 | + Text locale. Format: `language[_COUNTRY][.encoding][@variant]`. |
| 85 | + |
| 86 | + If the type is `"norm"`, the _properties_ must be an object with the |
| 87 | + following properties: |
| 88 | + |
| 89 | + - **locale**: `string` |
| 90 | + |
| 91 | + Text locale. Format: `language[_COUNTRY][.encoding][@variant]`. |
| 92 | + |
| 93 | + - **case**: `string` (Default: `"lower"`) |
| 94 | + |
| 95 | + Case conversion. Can be `"lower"`, `"none"` or `"upper"`. |
| 96 | + |
| 97 | + - **accent**: `boolean` (Default: `false`) |
| 98 | + |
| 99 | + Preserve accent in returned words. |
| 100 | + |
| 101 | + If the type is `"ngram"`, the _properties_ must be an object with the |
| 102 | + following properties: |
| 103 | + |
| 104 | + - **max**: `number` |
| 105 | + |
| 106 | + Maximum n-gram length. |
| 107 | + |
| 108 | + - **min**: `number` |
| 109 | + |
| 110 | + Minimum n-gram length. |
| 111 | + |
| 112 | + - **preserveOriginal**: `boolean` |
| 113 | + |
| 114 | + Output the original value as well. |
| 115 | + |
| 116 | + If the type is `"text"`, the _properties_ must be an object with the |
| 117 | + following properties: |
| 118 | + |
| 119 | + - **locale**: `string` |
| 120 | + |
| 121 | + Text locale. Format: `language[_COUNTRY][.encoding][@variant]`. |
| 122 | + |
| 123 | + - **case**: `string` (Default: `"lower"`) |
| 124 | + |
| 125 | + Case conversion. Can be `"lower"`, `"none"` or `"upper"`. |
| 126 | + |
| 127 | + - **stopwords**: `Array<string>` (optional) |
| 128 | + |
| 129 | + Words to omit from result. Defaults to the words loaded from the file at |
| 130 | + _stopwordsPath_. |
| 131 | + |
| 132 | + - **stopwordsPath**: `string` (optional) |
| 133 | + |
| 134 | + Path with a `language` sub-directory containing files with words to omit. |
| 135 | + |
| 136 | + Defaults to the path specified in the server-side environment variable |
| 137 | + `IRESEARCH_TEXT_STOPWORD_PATH` or the current working directory of the |
| 138 | + ArangoDB process. |
| 139 | + |
| 140 | + - **accent**: `boolean` (Default: `false`) |
| 141 | + |
| 142 | + Preserve accent in returned words. |
| 143 | + |
| 144 | + - **stemming**: `boolean` (Default: `true`) |
| 145 | + |
| 146 | + Apply stemming on returned words. |
| 147 | + |
| 148 | +**Examples** |
| 149 | + |
| 150 | +```js |
| 151 | +const db = new Database(); |
| 152 | +const analyzer = db.analyzer("potatoes"); |
| 153 | +await analyzer.create({ type: "identity" }); |
| 154 | +// the identity analyzer "potatoes" now exists |
| 155 | +``` |
| 156 | + |
| 157 | +## analyzer.drop |
| 158 | + |
| 159 | +`async analyzer.drop(): Object` |
| 160 | + |
| 161 | +Deletes the analyzer from the database, then returns an object with the _name_ |
| 162 | +of the analyzer that was dropped. |
| 163 | + |
| 164 | +**Examples** |
| 165 | + |
| 166 | +```js |
| 167 | +const db = new Database(); |
| 168 | +const analyzer = db.analyzer("some-analyzer"); |
| 169 | +await analyzer.drop(); |
| 170 | +// the analyzer "some-analyzer" no longer exists |
| 171 | +``` |
0 commit comments