@@ -70,11 +70,12 @@ client.suggestions('a', callback);
70
70
client .setSuggestionsSize (20 );
71
71
```
72
72
73
- #### Fetch custom field autocompletion
73
+ #### Custom field autocompletion
74
74
Custom fields autocomplete can be used for predictive search. For example, product names or categories can be
75
75
suggested as the keyword is being typed in.
76
76
``` js
77
- // Fetch custom field values starting with a specific prefix. In this example, results could be "adidas, apple, azure"
77
+ // Fetch custom field values starting with a specific prefix In this example, fetch records
78
+ // starting with *a* from the *custom_fields.brand* field. Results could be "adidas, apple, azure"
78
79
client .autocomplete (' custom_fields.brand' , ' a' , callback);
79
80
```
80
81
@@ -86,57 +87,36 @@ client.setAutocompleteSize(20);
86
87
87
88
#### Search with fuzzy matching
88
89
``` js
89
- // Enable/disable fuzzy matching. Possible values true/false/"auto" (default: "auto")
90
- client .setFuzzyMatch (false );
90
+ // Control fuzzy matching used for typo-tolerance
91
+ // Possible values true/false/"auto" (default: "auto")
92
+ client .setFuzzyMatch (false );
91
93
```
92
94
93
- #### Collect analytics
95
+ ### Pagination
96
+ Set page number, page size and sorting parameters. It's possible to order results by:
97
+ - relevance (descending)
98
+ - date (ascending or descending)
99
+ - custom field value (ascending or descending. E.g. * custom_fields.price* )
94
100
``` js
95
- // Control whether search queries are sent to your AddSearch Analytics Dashboard or not (default: true)
96
- client .setCollectAnalytics ( false );
101
+ // Defaults: page "1", pageSize "10", sortBy "relevance", sortOrder "desc"
102
+ client .setPaging (page, pageSize, sortBy, sortOrder );
97
103
```
98
104
99
- #### Send click event to analytics
100
- When a search results is clicked, send the event to your AddSearch Analytics Dashboard. Information on clicks is used
101
- in your statistics and in the self-learning search algorithm.
102
- ``` js
103
- // Docid is the 32-character long id that is part of each hit in search results
104
- // Position is the position of the document that was clicked, the first result being 1
105
- client .searchResultClicked (docid, position);
106
- ```
105
+ Other functions.
107
106
108
- #### Set JSON Web Token (for authentication)
109
107
``` js
110
- // Add JWT to the search request (if protected search index)
111
- client .setJWT (token);
112
- ```
108
+ // Next page (call search function to fetch results)
109
+ client .nextPage ();
113
110
114
- #### Set user token (for personalized search results)
115
- ``` js
116
- // Add a user token to the search request (if personalization in use)
117
- client .setUserToken (' uuid' );
111
+ // Previous page
112
+ client .previousPage ();
118
113
```
119
114
120
- #### Send personalization events with search query
121
- In personalized search, user events are typically sent to AddSearch via API and a user token
122
- is passed with the search query (see setUserToken function).
123
- An alternative way is to send user events needed for personalization with the search query.
124
-
125
- ``` js
126
- // Events depend on the personalization strategy
127
- // Contact AddSearch for more information
128
- var events = [
129
- {favorite_genre: ' rock' },
130
- {favorite_band: ' Red Hot Chili Peppers' },
131
- {least_favorite_genre: ' country' }
132
- ];
133
-
134
- client .setPersonalizationEvents (events);
135
- ```
115
+ ### Filters
136
116
137
117
#### Define language filter
138
118
``` js
139
- // Documents in specific language (e.g. "en" or "de")
119
+ // Fetch documents in specific language (e.g. "en" or "de")
140
120
client .setLanguage (' en' );
141
121
```
142
122
@@ -194,34 +174,14 @@ var filter = {
194
174
client .setFilterObject (filter);
195
175
```
196
176
197
- #### Manage paging
198
- Set page number, page size and sorting parameters. It's possible to order results by:
199
- - relevance (descending)
200
- - date (ascending or descending)
201
- - custom field value (ascending or descending. E.g. * custom_fields.price* )
202
- ``` js
203
- // Defaults: page "1", pageSize "10", sortBy "relevance", sortOrder "desc"
204
- client .setPaging (page, pageSize, sortBy, sortOrder);
205
- ```
206
-
207
- Other functions.
208
-
209
- ``` js
210
- // Next page (call search function to fetch results)
211
- client .nextPage ();
212
-
213
- // Previous page
214
- client .previousPage ();
215
- ```
216
-
217
177
#### Set result type
218
178
``` js
219
179
// By default, fetch all search results
220
180
// If "organic", Pinned results and Promotions are left out
221
181
client .setResultType (' organic' );
222
182
```
223
183
224
- #### Facets
184
+ ### Facets
225
185
``` js
226
186
// Declare fields for faceting. Number of hits found from
227
187
// these fields will be returned
@@ -234,6 +194,72 @@ Use the following function to get more or less facets.
234
194
client .setNumberOfFacets (20 );
235
195
```
236
196
197
+ ### Search analytics
198
+ #### Send search event to analytics
199
+ When search is executed, send the event to your AddSearch Analytics Dashboard.
200
+ ``` js
201
+ // If the numberOfResults is 0, the search is shown in the list of "queries with no hits"
202
+ client .sendStatsEvent (' search' , keyword, {numberOfResults: n});
203
+ ```
204
+
205
+ #### Send click event to analytics
206
+ When a search results is clicked, send the event to your AddSearch Analytics Dashboard. Click information is shown
207
+ in your statistics and used by the self-learning search algorithm.
208
+ ``` js
209
+ // documentId is the 32-character long id that is part of each hit in search results.
210
+ // position is the position of the document that was clicked, the first result being 1
211
+ client .sendStatsEvent (' click' , keyword, {documentId: id, position: n});
212
+ ```
213
+
214
+ #### Set or get stats session ID
215
+ Control the search session ID manually. Search queries with the same ID are grouped on the Analytics Dashboard.
216
+ For example, in a search-as-you-type implementation the final keyword of a given session is shown.
217
+ ``` js
218
+ client .getStatsSessionId ();
219
+ client .setStatsSessionId (id);
220
+ ```
221
+
222
+ #### Collect search events automatically
223
+ Send search events automatically to the Analytics Dashboard. Not recommended in search-as-you-type implementations,
224
+ as every keystroke would fire a statistics event
225
+ ``` js
226
+ // Control whether search queries are sent to your AddSearch Analytics Dashboard automatically or not (default: true)
227
+ client .setCollectAnalytics (false );
228
+ ```
229
+
230
+ ### Personalization
231
+
232
+ #### Set user token (for personalized search results)
233
+ ``` js
234
+ // Add a user token to the search request (if personalization in use)
235
+ client .setUserToken (' uuid' );
236
+ ```
237
+
238
+ #### Send personalization events with search query
239
+ In personalized search, user events are typically sent to AddSearch via API and a user token
240
+ is passed with the search query (see setUserToken function).
241
+ An alternative way is to send user events needed for personalization with the search query.
242
+
243
+ ``` js
244
+ // Events depend on the personalization strategy
245
+ // Contact AddSearch for more information
246
+ var events = [
247
+ {favorite_genre: ' rock' },
248
+ {favorite_band: ' Red Hot Chili Peppers' },
249
+ {least_favorite_genre: ' country' }
250
+ ];
251
+
252
+ client .setPersonalizationEvents (events);
253
+ ```
254
+
255
+ ### Other
256
+
257
+ #### Set JSON Web Token (for authentication)
258
+ ``` js
259
+ // Add JWT to the search request (if protected search index)
260
+ client .setJWT (token);
261
+ ```
262
+
237
263
## Supported web browsers and node.js versions
238
264
The client is tested on
239
265
- Chrome
@@ -251,6 +277,12 @@ To modify this client library, clone this repository to your computer and execut
251
277
npm install
252
278
```
253
279
280
+ #### Code
281
+ Re-compile automatically when source files are changed
282
+ ``` sh
283
+ npm run watch
284
+ ```
285
+
254
286
#### Run tests
255
287
``` sh
256
288
npm test
0 commit comments