addsearch-js-client
Advanced tools
Comparing version 0.8.14 to 0.8.15
@@ -1,3 +0,3 @@ | ||
"use strict" | ||
'use strict'; | ||
module.exports = require("./src/index.js") | ||
module.exports = require('./src/index.js'); |
{ | ||
"name": "addsearch-js-client", | ||
"version": "0.8.14", | ||
"version": "0.8.15", | ||
"description": "AddSearch API JavaScript client", | ||
"main": "index.js", | ||
"jsdelivr": "./dist/addsearch-js-client.min.js", | ||
"scripts": { | ||
"test": "./node_modules/mocha/bin/mocha.js --recursive --require @babel/register", | ||
"build": "npm run test && ./node_modules/webpack-cli/bin/cli.js", | ||
"watch": "./node_modules/webpack-cli/bin/cli.js --watch" | ||
}, | ||
"repository": { | ||
@@ -27,2 +20,3 @@ "type": "git", | ||
"bugs": "https://github.com/AddSearch/js-client-library/issues", | ||
"license": "MIT", | ||
"author": { | ||
@@ -38,9 +32,21 @@ "name": "AddSearch", | ||
], | ||
"license": "MIT", | ||
"main": "index.js", | ||
"jsdelivr": "./dist/addsearch-js-client.min.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"dist", | ||
"index.d.ts" | ||
], | ||
"scripts": { | ||
"build": "npm run test && ./node_modules/webpack-cli/bin/cli.js", | ||
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"", | ||
"test": "./node_modules/mocha/bin/mocha.js --recursive --require @babel/register", | ||
"watch": "./node_modules/webpack-cli/bin/cli.js --watch" | ||
}, | ||
"dependencies": { | ||
"axios": "^1.7.2", | ||
"buffer": "^6.0.3", | ||
"es6-promise": "^4.2.8", | ||
"js-base64": "^3.6.0", | ||
"uuid": "^9.0.0", | ||
"buffer": "^6.0.3" | ||
"uuid": "^9.0.0" | ||
}, | ||
@@ -59,2 +65,3 @@ "devDependencies": { | ||
"mocha": "^10.0.0", | ||
"prettier": "^3.3.3", | ||
"terser-webpack-plugin": "^5.3.1", | ||
@@ -61,0 +68,0 @@ "uglify-js": "^3.12.0", |
372
README.md
# AddSearch Search API Client for JavaScript | ||
[AddSearch](https://www.addsearch.com) is a Search-as-a-Service for all your search needs. This API | ||
Client lets you easily use the [Search API](https://www.addsearch.com/docs/api/) | ||
and [Indexing API](https://www.addsearch.com/docs/api/indexing-overview/) with JavaScript. | ||
[AddSearch](https://www.addsearch.com) is a Search-as-a-Service for all your search needs. This API | ||
Client lets you easily use the [Search API](https://www.addsearch.com/docs/api/) and | ||
[Indexing API](https://www.addsearch.com/docs/api/indexing-overview/) with JavaScript. | ||
## Quick Start | ||
The library is available on the global CDN [jsDelivr:](https://www.jsdelivr.com/package/npm/addsearch-js-client) | ||
The library is available on the global CDN | ||
[jsDelivr:](https://www.jsdelivr.com/package/npm/addsearch-js-client) | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/addsearch-js-client@0.6/dist/addsearch-js-client.min.js"></script> | ||
``` | ||
Or install the library locally to use it with Node.js: | ||
```sh | ||
@@ -24,2 +29,3 @@ npm install addsearch-js-client --save | ||
Or use import in ES6 | ||
```js | ||
@@ -30,2 +36,3 @@ import AddSearchClient from 'addsearch-js-client'; | ||
#### Execute the first search query | ||
```js | ||
@@ -36,6 +43,6 @@ // Create client with your 32-character SITEKEY | ||
// Callback function | ||
var cb = function(res) { | ||
var cb = function (res) { | ||
// Print results to console | ||
console.log(res); | ||
} | ||
}; | ||
@@ -48,6 +55,7 @@ // Execute search. Callback function will be called with search results | ||
The client provides following functions to execute search queries. To use the client library for indexing, | ||
see [Indexing API](https://github.com/AddSearch/js-client-library#indexing-api). | ||
The client provides following functions to execute search queries. To use the client library for | ||
indexing, see [Indexing API](https://github.com/AddSearch/js-client-library#indexing-api). | ||
#### Fetch search results | ||
```js | ||
@@ -65,4 +73,6 @@ // Search with a specific keyword | ||
#### Fetch search suggestions | ||
Search suggestions are keywords and search phrases that real users have used in your search. Configure Search | ||
suggestions on AddSearch Dashboard before using this function. | ||
Search suggestions are keywords and search phrases that real users have used in your search. | ||
Configure Search suggestions on AddSearch Dashboard before using this function. | ||
```js | ||
@@ -74,2 +84,3 @@ // Get suggestions starting with a specific prefix | ||
#### Set the number of search suggestions to fetch | ||
```js | ||
@@ -81,6 +92,8 @@ // Number of search suggestions to fetch (default 10) | ||
#### Custom field autocompletion | ||
Custom fields autocomplete can be used for predictive search. For example, product names or categories can be | ||
suggested as the keyword is being typed in. | ||
Custom fields autocomplete can be used for predictive search. For example, product names or | ||
categories can be suggested as the keyword is being typed in. | ||
```js | ||
// Fetch custom field values starting with a specific prefix In this example, fetch records | ||
// Fetch custom field values starting with a specific prefix In this example, fetch records | ||
// starting with *a* from the *custom_fields.brand* field. Results could be "adidas, apple, azure" | ||
@@ -91,2 +104,3 @@ client.autocomplete('custom_fields.brand', 'a', callback); | ||
#### Set the number of custom field autocompletion results to fetch | ||
```js | ||
@@ -98,3 +112,5 @@ // Number of autocompletion results to fetch (default 10) | ||
#### Search with fuzzy matching | ||
Fuzzy matching is used for typo tolerance. There are four options: | ||
- **false**: No typo tolerance | ||
@@ -108,9 +124,11 @@ - **true**: Exact matches and fuzzy matches are equal | ||
// Possible values true/false/"auto"/"retry" (default: "auto") | ||
client.setFuzzyMatch(false); | ||
client.setFuzzyMatch(false); | ||
``` | ||
#### Search operator | ||
When a user searches with multiple keywords, we return only documents that contain all the terms which means | ||
applying the logical operator AND for the query. It is possible to choose which logical operator to use for | ||
fuzzy results when the fuzzy parameter is set to auto. There are two options: | ||
When a user searches with multiple keywords, we return only documents that contain all the terms | ||
which means applying the logical operator AND for the query. It is possible to choose which logical | ||
operator to use for fuzzy results when the fuzzy parameter is set to auto. There are two options: | ||
- **"or"**: makes fuzzy results broader and includes partial matches of a few search terms | ||
@@ -121,16 +139,17 @@ - **"and"**: makes fuzzy results stricter and includes only mistyped search terms | ||
// Possible values "and"/"or" (default: "or") | ||
client.setSearchOperator('and'); | ||
client.setSearchOperator('and'); | ||
``` | ||
#### Postfix wildcard | ||
Enable or disable postfix wildcard. I.e. should keyword "add" match to "addsearch" or should it just match to the | ||
term **add** | ||
Enable or disable postfix wildcard. I.e. should keyword "add" match to "addsearch" or should it just | ||
match to the term **add** | ||
```js | ||
// Possible values true/false (default: true) | ||
client.setPostfixWildcard(false); | ||
client.setPostfixWildcard(false); | ||
``` | ||
#### Set enableLogicalOperators | ||
#### Set enableLogicalOperators | ||
```js | ||
@@ -144,2 +163,3 @@ // (default: false) | ||
#### Set cacheResponseTime | ||
Caching the response, define the time-to-live of the cache. | ||
@@ -149,16 +169,20 @@ | ||
// Specify time-to-live value in seconds | ||
client.setCacheResponseTime(3600); | ||
client.setCacheResponseTime(3600); | ||
``` | ||
Please contact our [Support](https://github.com/AddSearch/js-client-library?tab=readme-ov-file#support) team to active Response Caching for your index. | ||
Please contact our | ||
[Support](https://github.com/AddSearch/js-client-library?tab=readme-ov-file#support) team to active | ||
Response Caching for your index. | ||
### Pagination | ||
### Pagination | ||
Set page number, page size and sorting parameters. It's possible to order results by: | ||
- relevance (descending) | ||
- date (ascending or descending) | ||
- custom field value (ascending or descending. E.g. *custom_fields.price*) | ||
- custom field value (ascending or descending. E.g. _custom_fields.price_) | ||
Type of sortBy and sortOrder: `string` or `array`. They must have the same type, in case type is array, sortBy and sortOrder must have the same size. | ||
For example: | ||
Type of sortBy and sortOrder: `string` or `array`. They must have the same type, in case type is | ||
array, sortBy and sortOrder must have the same size. For example: | ||
```js | ||
@@ -168,3 +192,3 @@ sortBy = 'date'; | ||
or | ||
or; | ||
@@ -175,3 +199,2 @@ sortBy = ['date', 'custom_fields.price']; | ||
```js | ||
@@ -195,2 +218,3 @@ // Defaults: page: 1, pageSize: 10, sortBy: "relevance", sortOrder: "desc" | ||
#### Define language filter | ||
```js | ||
@@ -201,3 +225,4 @@ // Fetch documents in specific language (e.g. "en" or "de" or "en-GB") | ||
#### Define publishing date filter | ||
#### Define publishing date filter | ||
```js | ||
@@ -209,2 +234,3 @@ // Documents published between specific date range | ||
#### Define price range filter | ||
```js | ||
@@ -215,6 +241,7 @@ // Products in specific price range (in cents. e.g. 100,00 - 200,00) | ||
#### Define category filters | ||
Filter by URL patterns, document types or *addsearch-category* meta tag values. | ||
See the [full documentation.](https://www.addsearch.com/support/documentation/ranking-relevance-filters/filters/#category-filters) | ||
#### Define category filters | ||
Filter by URL patterns, document types or _addsearch-category_ meta tag values. See the | ||
[full documentation.](https://www.addsearch.com/support/documentation/ranking-relevance-filters/filters/#category-filters) | ||
```js | ||
@@ -226,13 +253,15 @@ // Only PDF files or products | ||
#### Custom field filters | ||
Filter by custom fields. Custon fields can be defined in meta tags or AddSearch crawler can pick them up from your HTML or JSON data. | ||
See the [full documentation.](https://www.addsearch.com/support/documentation/ranking-relevance-filters/custom-field/) | ||
Filter by custom fields. Custon fields can be defined in meta tags or AddSearch crawler can pick | ||
them up from your HTML or JSON data. See the | ||
[full documentation.](https://www.addsearch.com/support/documentation/ranking-relevance-filters/custom-field/) | ||
```js | ||
// Search by specific city (Berlin, Paris or Boston) | ||
client.addCustomFieldFilter('city','berlin'); | ||
client.addCustomFieldFilter('city','paris'); | ||
client.addCustomFieldFilter('city','boston'); | ||
client.addCustomFieldFilter('city', 'berlin'); | ||
client.addCustomFieldFilter('city', 'paris'); | ||
client.addCustomFieldFilter('city', 'boston'); | ||
// Remove Paris (Berlin and Boston remaining) | ||
client.removeCustomFieldFilter('city','paris'); | ||
client.removeCustomFieldFilter('city', 'paris'); | ||
@@ -244,12 +273,13 @@ // Remove all cities | ||
#### Set filtering object | ||
Set complex filtering object that can contain nested *and*, *or*, *not*, and *range* filters. | ||
Set complex filtering object that can contain nested _and_, _or_, _not_, and _range_ filters. | ||
```js | ||
// Find results where brand is apple, color is not white, and price is between 200 and 500 | ||
var filter = { | ||
'and':[ | ||
{'custom_fields.brand': 'apple'}, | ||
{'not': {'custom_fields.color': 'white'}}, | ||
{'range': {'custom_fields.price': {'gt': 200, 'lt':500}}} | ||
] | ||
and: [ | ||
{ 'custom_fields.brand': 'apple' }, | ||
{ not: { 'custom_fields.color': 'white' } }, | ||
{ range: { 'custom_fields.price': { gt: 200, lt: 500 } } } | ||
] | ||
}; | ||
@@ -261,2 +291,3 @@ | ||
#### Set result type | ||
```js | ||
@@ -268,4 +299,4 @@ // By default, fetch all search results | ||
### Facets | ||
### Facets | ||
```js | ||
@@ -277,4 +308,6 @@ // Declare fields for faceting. Number of hits found from | ||
``` | ||
By default, 10 facets with most hits are returned per field. | ||
Use the following function to get more or less facets. | ||
By default, 10 facets with most hits are returned per field. Use the following function to get more | ||
or less facets. | ||
```js | ||
@@ -285,11 +318,9 @@ client.setNumberOfFacets(20); | ||
#### Numerical range facets | ||
Group numerical custom fields into range buckets. | ||
```js | ||
// Define ranges. E.g. products with price $0-$100, $100-$200, and over $200. | ||
// From value is inclusive, to value is exclusive | ||
var ranges = [ | ||
{'to': 100}, | ||
{'from': 100, 'to': 200}, | ||
{'from': 200} | ||
]; | ||
var ranges = [{ to: 100 }, { from: 100, to: 200 }, { from: 200 }]; | ||
@@ -301,6 +332,8 @@ // Parameters: field name, range array | ||
### Field statistics | ||
Get minimum, maximum, and average values of a numerical or date-based custom field. The information | ||
is handy for applications like range filtering. | ||
```js | ||
// Search response will have a fieldStats element with information like | ||
// Search response will have a fieldStats element with information like | ||
// custom_fields.price: {min: 1230, max: 1590, avg: 1382} | ||
@@ -311,9 +344,12 @@ client.addStatsField('custom_fields.price'); | ||
### Recommendations | ||
#### Frequently bought together items | ||
Get frequently bought together items, given "configurationKey" and "itemId" | ||
```js | ||
// fetch frequently bought together items | ||
client.recommendations({ | ||
configurationKey: "config1", | ||
itemId: "1065921" | ||
configurationKey: 'config1', | ||
itemId: '1065921' | ||
}); | ||
@@ -323,21 +359,29 @@ ``` | ||
### Search analytics | ||
#### Send search event to analytics | ||
When search is executed, send the event to your AddSearch Analytics Dashboard. | ||
```js | ||
// If the numberOfResults is 0, the search is shown in the list of "queries with no hits" | ||
client.sendStatsEvent('search', keyword, {numberOfResults: n}); | ||
client.sendStatsEvent('search', keyword, { numberOfResults: n }); | ||
``` | ||
#### Send click event to analytics | ||
When a search results is clicked, send the event to your AddSearch Analytics Dashboard. Click information is shown | ||
in your statistics and used by the self-learning search algorithm. | ||
When a search results is clicked, send the event to your AddSearch Analytics Dashboard. Click | ||
information is shown in your statistics and used by the self-learning search algorithm. | ||
```js | ||
// documentId is the 32-character long id that is part of each hit in search results. | ||
// position is the position of the document that was clicked, the first result being 1 | ||
client.sendStatsEvent('click', keyword, {documentId: id, position: n}); | ||
client.sendStatsEvent('click', keyword, { documentId: id, position: n }); | ||
``` | ||
#### Set or get stats session ID | ||
Control the search session ID manually. Search queries with the same ID are grouped on the Analytics Dashboard. | ||
For example, in a search-as-you-type implementation the final keyword of a given session is shown. | ||
Control the search session ID manually. Search queries with the same ID are grouped on the Analytics | ||
Dashboard. For example, in a search-as-you-type implementation the final keyword of a given session | ||
is shown. | ||
```js | ||
@@ -349,4 +393,6 @@ client.getStatsSessionId(); | ||
#### Collect search events automatically | ||
Send search events automatically to the Analytics Dashboard. Not recommended in search-as-you-type implementations, | ||
as every keystroke would fire a statistics event | ||
Send search events automatically to the Analytics Dashboard. Not recommended in search-as-you-type | ||
implementations, as every keystroke would fire a statistics event | ||
```js | ||
@@ -358,6 +404,8 @@ // Control whether search queries are sent to your AddSearch Analytics Dashboard automatically or not (default: true) | ||
#### Set a tag for analytics events | ||
Defines a tag associated with all analytics events reported by the client. | ||
These tags will be available as filters in the AddSearch Analytics Dashboard. | ||
You can use tags, for instance, in A/B testing to compare which search UIs are most effective. | ||
Splitting the analytics with tags may also provide insights to the behaviour of audiences on different websites. | ||
Defines a tag associated with all analytics events reported by the client. These tags will be | ||
available as filters in the AddSearch Analytics Dashboard. You can use tags, for instance, in A/B | ||
testing to compare which search UIs are most effective. Splitting the analytics with tags may also | ||
provide insights to the behaviour of audiences on different websites. | ||
```js | ||
@@ -371,5 +419,8 @@ // Specify a tag for analytics events (the maximum length is 50 characters) | ||
#### Enable personalization tracking | ||
Enable personalization tracking, user token will be included in every stat events as "session ID". <br/> | ||
Enable personalization tracking, user token will be included in every stat events as "session ID". | ||
<br/> | ||
Set stats session ID if user token is generated by your site. | ||
```js | ||
@@ -381,2 +432,3 @@ client.setStatsSessionId(userToken); | ||
Specify the expiration date of the cookie. Default is 180. | ||
```js | ||
@@ -387,5 +439,7 @@ // Defaults - isEnabled: false, expirationDates: 180 | ||
#### Allow storing AddSearch's user token in cookie | ||
#### Allow storing AddSearch's user token in cookie | ||
By default, the value is false. Set it to false when users reject cookie (AddSearch's cookie can be categorized as functional/analytics cookie), or set to true when user accepts cookie. | ||
By default, the value is false. Set it to false when users reject cookie (AddSearch's cookie can be | ||
categorized as functional/analytics cookie), or set to true when user accepts cookie. | ||
```js | ||
@@ -396,4 +450,4 @@ // Default: false | ||
#### Set user token to search query (for personalized search results) | ||
#### Set user token to search query (for personalized search results) | ||
```js | ||
@@ -404,5 +458,6 @@ // Add a user token to the search request (if personalization in use) | ||
#### Get user token from AddSearch cookie | ||
#### Get user token from AddSearch cookie | ||
Get the user token which is stored in AddSearch cookie (if available). | ||
```js | ||
@@ -413,8 +468,8 @@ // Get a user token | ||
#### Send personalization events with search query - deprecated | ||
In personalized search, user events are typically sent to AddSearch via API and a user token | ||
is passed with the search query (see setUserToken function). | ||
An alternative way is to send user events needed for personalization with the search query. | ||
In personalized search, user events are typically sent to AddSearch via API and a user token is | ||
passed with the search query (see setUserToken function). An alternative way is to send user events | ||
needed for personalization with the search query. | ||
```js | ||
@@ -424,5 +479,5 @@ // Events depend on the personalization strategy | ||
var events = [ | ||
{favorite_genre: 'rock'}, | ||
{favorite_band: 'Red Hot Chili Peppers'}, | ||
{least_favorite_genre: 'country'} | ||
{ favorite_genre: 'rock' }, | ||
{ favorite_band: 'Red Hot Chili Peppers' }, | ||
{ least_favorite_genre: 'country' } | ||
]; | ||
@@ -433,7 +488,6 @@ | ||
### Other | ||
#### Set JSON Web Token (for authentication) | ||
```js | ||
@@ -445,2 +499,3 @@ // Add JWT to the search request (if protected search index) | ||
#### Set API throttling | ||
```js | ||
@@ -452,5 +507,11 @@ // Set Search API throttle time in milliseconds. Default is 200. | ||
#### Set API hostname | ||
`option` is an object with the following properties, all of which are optional. If `option` is not defined, host name will be applied for all requests. | ||
- **searchApiRequestOnly**: If true, the new host name is only applied for searchApi requests (default: false) | ||
- **statsApiRequestOnly**: If true, the new host name is only applied for statsApi requests (default: false) | ||
`option` is an object with the following properties, all of which are optional. If `option` is not | ||
defined, host name will be applied for all requests. | ||
- **searchApiRequestOnly**: If true, the new host name is only applied for searchApi requests | ||
(default: false) | ||
- **statsApiRequestOnly**: If true, the new host name is only applied for statsApi requests | ||
(default: false) | ||
```js | ||
@@ -462,8 +523,14 @@ // Set API hostname (e.g. for dedicated environments) | ||
#### Set API request interceptor | ||
`configurationObject` contains 2 keys: <string>`url` and <object>`headers`. Modify the `configurationObject` before it is sent. | ||
`option` is an object with the following properties, all of which are optional. If `option` is not defined, the interceptor will be used for all requests. | ||
- **searchApiRequestOnly**: If true, the interceptor is only used for searchApi requests (default: false) | ||
- **statsApiRequestOnly**: If true, the interceptor is only used for statsApi requests (default: false) | ||
`configurationObject` contains 2 keys: <string>`url` and <object>`headers`. Modify the | ||
`configurationObject` before it is sent. | ||
`option` is an object with the following properties, all of which are optional. If `option` is not | ||
defined, the interceptor will be used for all requests. | ||
- **searchApiRequestOnly**: If true, the interceptor is only used for searchApi requests (default: | ||
false) | ||
- **statsApiRequestOnly**: If true, the interceptor is only used for statsApi requests (default: | ||
false) | ||
```js | ||
@@ -477,10 +544,10 @@ function callback(configurationObject) { | ||
## Indexing API | ||
With the Indexing API, you can fetch, create, update, and delete single documents or | ||
batches of documents. | ||
Indexing API functions are meant to be used with Node.js. Never expose secret key in your | ||
website code. | ||
With the Indexing API, you can fetch, create, update, and delete single documents or batches of | ||
documents. | ||
Indexing API functions are meant to be used with Node.js. Never expose secret key in your website | ||
code. | ||
```js | ||
@@ -497,11 +564,14 @@ // Create client with your keys | ||
### Document structure | ||
Documents can contain a set of pre-defined fields, as well as any number of custom fields | ||
defined under the **custom_fields** key. | ||
Using pre-defined fields is optional, but default [Search UI](https://github.com/AddSearch/search-ui) components | ||
display them by default, so pre-defined field give you visible results a bit faster. | ||
Documents can contain a set of pre-defined fields, as well as any number of custom fields defined | ||
under the **custom_fields** key. | ||
Using pre-defined fields is optional, but default | ||
[Search UI](https://github.com/AddSearch/search-ui) components display them by default, so | ||
pre-defined field give you visible results a bit faster. | ||
Pre-defined fields are: url, title, and main_content. | ||
Example document: | ||
```js | ||
@@ -514,9 +584,9 @@ const doc = { | ||
custom_fields: { | ||
'name': 'Example product', | ||
'description': 'Description for the example product', | ||
'price_cents': 599, | ||
'average_customer_rating': 4.5, | ||
'release_date': 1589200255 | ||
name: 'Example product', | ||
description: 'Description for the example product', | ||
price_cents: 599, | ||
average_customer_rating: 4.5, | ||
release_date: 1589200255 | ||
} | ||
} | ||
}; | ||
``` | ||
@@ -534,4 +604,4 @@ | ||
If the **id** is not defined in the document at indexing time, it is generated automatically either randomly | ||
or from the **url** field. | ||
If the **id** is not defined in the document at indexing time, it is generated automatically either | ||
randomly or from the **url** field. | ||
@@ -543,11 +613,13 @@ ```js | ||
custom_fields: {} | ||
} | ||
}; | ||
``` | ||
```js | ||
// ID created from the URL field (md5 of the url) | ||
const docWithURL= { | ||
const docWithURL = { | ||
url: 'https://..', | ||
custom_fields: {} | ||
} | ||
}; | ||
``` | ||
```js | ||
@@ -558,6 +630,7 @@ // ID generated randomly | ||
custom_fields: {} | ||
} | ||
}; | ||
``` | ||
### Save document | ||
Add a document to the index, or update a document. | ||
@@ -569,3 +642,3 @@ | ||
custom_fields: { | ||
'name': 'Example product' | ||
name: 'Example product' | ||
} | ||
@@ -575,7 +648,8 @@ }; | ||
// Save document | ||
client.saveDocument(doc) | ||
.then(response => { | ||
client | ||
.saveDocument(doc) | ||
.then((response) => { | ||
console.log(response); | ||
}) | ||
.catch(error => { | ||
.catch((error) => { | ||
console.log(error); | ||
@@ -585,11 +659,13 @@ }); | ||
### Get document by ID | ||
### Get document by ID | ||
Fetch a specific document by ID. | ||
```js | ||
client.getDocument(id) | ||
.then(response => { | ||
client | ||
.getDocument(id) | ||
.then((response) => { | ||
console.log(response); | ||
}) | ||
.catch(error => { | ||
.catch((error) => { | ||
console.log(error); | ||
@@ -599,11 +675,13 @@ }); | ||
### Delete document by ID | ||
### Delete document by ID | ||
Delete a specific document by ID. | ||
```js | ||
client.deleteDocument(id) | ||
.then(response => { | ||
client | ||
.deleteDocument(id) | ||
.then((response) => { | ||
console.log(response); | ||
}) | ||
.catch(error => { | ||
.catch((error) => { | ||
console.log(error); | ||
@@ -613,5 +691,6 @@ }); | ||
### Save batch of documents | ||
### Save batch of documents | ||
Add or update bunch of documents defined in an array. | ||
```js | ||
@@ -623,3 +702,3 @@ const batch = { | ||
custom_fields: { | ||
'name': 'Product 1' | ||
name: 'Product 1' | ||
} | ||
@@ -630,3 +709,3 @@ }, | ||
custom_fields: { | ||
'name': 'Product 2' | ||
name: 'Product 2' | ||
} | ||
@@ -638,7 +717,8 @@ } | ||
// Save batch of documents | ||
client.saveDocumentsBatch(batch) | ||
.then(response => { | ||
client | ||
.saveDocumentsBatch(batch) | ||
.then((response) => { | ||
console.log(response); | ||
}) | ||
.catch(error => { | ||
.catch((error) => { | ||
console.log(error); | ||
@@ -648,17 +728,19 @@ }); | ||
### Delete batch of documents | ||
### Delete batch of documents | ||
Delete multiple documents with an array of document IDs. | ||
```js | ||
// Array of document IDs | ||
const batch = { | ||
documents: ["1234", "5678"] | ||
documents: ['1234', '5678'] | ||
}; | ||
// Delete batch of documents | ||
client.deleteDocumentsBatch(batch) | ||
.then(response => { | ||
client | ||
.deleteDocumentsBatch(batch) | ||
.then((response) => { | ||
console.log(response); | ||
}) | ||
.catch(error => { | ||
.catch((error) => { | ||
console.log(error); | ||
@@ -668,5 +750,6 @@ }); | ||
## Supported browsers | ||
## Supported browsers | ||
The client is tested on | ||
- Chrome | ||
@@ -679,6 +762,9 @@ - Firefox | ||
## Development | ||
## Development | ||
To modify this client library, clone this repository to your computer and execute following commands. | ||
To modify this client library, clone this repository to your computer and execute following | ||
commands. | ||
#### Install dependencies | ||
```sh | ||
@@ -689,3 +775,5 @@ npm install | ||
#### Code | ||
Re-compile automatically when source files are changed | ||
```sh | ||
@@ -696,2 +784,3 @@ npm run watch | ||
#### Run tests | ||
```sh | ||
@@ -702,2 +791,3 @@ npm test | ||
#### Build | ||
```sh | ||
@@ -707,6 +797,8 @@ npm run build | ||
Built bundle is saved under the *dist/* folder | ||
Built bundle is saved under the _dist/_ folder | ||
## Support | ||
Feel free to send any questions, ideas, and suggestions at [support@addsearch.com](mailto:support@addsearch.com) or | ||
visit [addsearch.com](https://www.addsearch.com/) for more information. | ||
Feel free to send any questions, ideas, and suggestions at | ||
[support@addsearch.com](mailto:support@addsearch.com) or visit | ||
[addsearch.com](https://www.addsearch.com/) for more information. |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
743
121839
16
5
2
4