Manage dictionary entries
The REST API offers a single endpoint to manage your dictorionary. In this guide, we will demonstrate how to manage entries for different scenarios.
A dictionaryName
can be either stopwords
, plurals
or compounds
.
Append new entries to your dictionary
Useful when you have new data to add to a dictionary and don't want to impact existing entries.
- JavaScript
- PHP
- Java
js
await client.batchDictionaryEntries({dictionaryName: 'YOUR_DICTIONARY_NAME', // one of `stopwords`, `plurals` or `compounds`.batchDictionaryEntriesParams: {clearExistingDictionaryEntries: false, // here we want to append data, so we don't clear existing entriesrequests: [{action: 'addEntry',body: {objectID: '1',language: 'en',word: 'fancy',words: ['believe', 'algolia'],decomposition: ['trust', 'algolia'],state: 'enabled',},},],},})
js
await client.batchDictionaryEntries({dictionaryName: 'YOUR_DICTIONARY_NAME', // one of `stopwords`, `plurals` or `compounds`.batchDictionaryEntriesParams: {clearExistingDictionaryEntries: false, // here we want to append data, so we don't clear existing entriesrequests: [{action: 'addEntry',body: {objectID: '1',language: 'en',word: 'fancy',words: ['believe', 'algolia'],decomposition: ['trust', 'algolia'],state: 'enabled',},},],},})
php
// TODO
php
// TODO
java
client.batchDictionaryEntriesAsync(DictionaryType.fromValue("YOUR_DICTIONARY_NAME"),new BatchDictionaryEntriesParams().setClearExistingDictionaryEntries(false).setRequests(Arrays.asList(new BatchDictionaryEntriesRequest().setAction(DictionaryAction.ADD_ENTRY).setBody(new DictionaryEntry().setObjectID("1").setLanguage("en").setWord("fancy").setWords(Arrays.asList("believe", "algolia")).setDecomposition(Arrays.asList("trust", "algolia")).setState(DictionaryEntryState.ENABLED)))));
java
client.batchDictionaryEntriesAsync(DictionaryType.fromValue("YOUR_DICTIONARY_NAME"),new BatchDictionaryEntriesParams().setClearExistingDictionaryEntries(false).setRequests(Arrays.asList(new BatchDictionaryEntriesRequest().setAction(DictionaryAction.ADD_ENTRY).setBody(new DictionaryEntry().setObjectID("1").setLanguage("en").setWord("fancy").setWords(Arrays.asList("believe", "algolia")).setDecomposition(Arrays.asList("trust", "algolia")).setState(DictionaryEntryState.ENABLED)))));
Replace dictionary entries
Useful when you want to clear every entries of a dictionary and add new ones at the same time.
- JavaScript
- PHP
- Java
js
await client.batchDictionaryEntries({dictionaryName: 'YOUR_DICTIONARY_NAME', // one of `stopwords`, `plurals` or `compounds`.batchDictionaryEntriesParams: {clearExistingDictionaryEntries: true, // Since we replace, we will create a new dictionary from those entriesrequests: [{action: 'addEntry',body: {objectID: '1',language: 'en',word: 'fancy',words: ['believe', 'algolia'],decomposition: ['trust', 'algolia'],state: 'enabled',},},],},})
js
await client.batchDictionaryEntries({dictionaryName: 'YOUR_DICTIONARY_NAME', // one of `stopwords`, `plurals` or `compounds`.batchDictionaryEntriesParams: {clearExistingDictionaryEntries: true, // Since we replace, we will create a new dictionary from those entriesrequests: [{action: 'addEntry',body: {objectID: '1',language: 'en',word: 'fancy',words: ['believe', 'algolia'],decomposition: ['trust', 'algolia'],state: 'enabled',},},],},})
php
// TODO
php
// TODO
java
client.batchDictionaryEntriesAsync(DictionaryType.fromValue("YOUR_DICTIONARY_NAME"), // DictionaryType.PLURALS, DictionaryType.STOPWORDS or DictionaryType.COMPOUNDSnew BatchDictionaryEntriesParams().setClearExistingDictionaryEntries(true) // Since we replace, we will create a new dictionary from those entries.setRequests(Arrays.asList(new BatchDictionaryEntriesRequest().setAction(DictionaryAction.ADD_ENTRY).setBody(new DictionaryEntry().setObjectID("1").setLanguage("en").setWord("fancy").setWords(Arrays.asList("believe", "algolia")).setDecomposition(Arrays.asList("trust", "algolia")).setState(DictionaryEntryState.ENABLED)))));
java
client.batchDictionaryEntriesAsync(DictionaryType.fromValue("YOUR_DICTIONARY_NAME"), // DictionaryType.PLURALS, DictionaryType.STOPWORDS or DictionaryType.COMPOUNDSnew BatchDictionaryEntriesParams().setClearExistingDictionaryEntries(true) // Since we replace, we will create a new dictionary from those entries.setRequests(Arrays.asList(new BatchDictionaryEntriesRequest().setAction(DictionaryAction.ADD_ENTRY).setBody(new DictionaryEntry().setObjectID("1").setLanguage("en").setWord("fancy").setWords(Arrays.asList("believe", "algolia")).setDecomposition(Arrays.asList("trust", "algolia")).setState(DictionaryEntryState.ENABLED)))));
Clear dictionary
Deletes everything that exists in a dictionary.
- JavaScript
- PHP
- Java
js
await client.batchDictionaryEntries({dictionaryName: 'YOUR_DICTIONARY_NAME', // one of `stopwords`, `plurals` or `compounds`.batchDictionaryEntriesParams: {clearExistingDictionaryEntries: true,requests: [], // We don't push any new entries to it},})
js
await client.batchDictionaryEntries({dictionaryName: 'YOUR_DICTIONARY_NAME', // one of `stopwords`, `plurals` or `compounds`.batchDictionaryEntriesParams: {clearExistingDictionaryEntries: true,requests: [], // We don't push any new entries to it},})
php
// TODO
php
// TODO
java
// TODO
java
// TODO
Delete entries in the dictionary
Useful when deleting one or many entries from a dictionary.
- JavaScript
- PHP
- Java
js
await client.batchDictionaryEntries({dictionaryName: 'YOUR_DICTIONARY_NAME', // one of `stopwords`, `plurals` or `compounds`.batchDictionaryEntriesParams: {clearExistingDictionaryEntries: false, // we don't want to impact other entries.requests: [{action: 'deleteEntry', // `deleteEntry` will remove any entries in the dictionary that have the same `objectID` as the `body.objectID` field.body: {objectID: '1',},},],},})
js
await client.batchDictionaryEntries({dictionaryName: 'YOUR_DICTIONARY_NAME', // one of `stopwords`, `plurals` or `compounds`.batchDictionaryEntriesParams: {clearExistingDictionaryEntries: false, // we don't want to impact other entries.requests: [{action: 'deleteEntry', // `deleteEntry` will remove any entries in the dictionary that have the same `objectID` as the `body.objectID` field.body: {objectID: '1',},},],},})
php
// TODO
php
// TODO
java
client.batchDictionaryEntriesAsync(DictionaryType.fromValue("YOUR_DICTIONARY_NAME"), // DictionaryType.PLURALS, DictionaryType.STOPWORDS or DictionaryType.COMPOUNDSnew BatchDictionaryEntriesParams().setClearExistingDictionaryEntries(false) // we don't want to impact other entries..setRequests(Arrays.asList(new BatchDictionaryEntriesRequest().setAction(DictionaryAction.DELETE_ENTRY).setBody(new DictionaryEntry().setObjectID("1")))));
java
client.batchDictionaryEntriesAsync(DictionaryType.fromValue("YOUR_DICTIONARY_NAME"), // DictionaryType.PLURALS, DictionaryType.STOPWORDS or DictionaryType.COMPOUNDSnew BatchDictionaryEntriesParams().setClearExistingDictionaryEntries(false) // we don't want to impact other entries..setRequests(Arrays.asList(new BatchDictionaryEntriesRequest().setAction(DictionaryAction.DELETE_ENTRY).setBody(new DictionaryEntry().setObjectID("1")))));