@@ -70,11 +70,12 @@ client.suggestions('a', callback);
7070client .setSuggestionsSize (20 );
7171```
7272
73- #### Fetch custom field autocompletion
73+ #### Custom field autocompletion
7474Custom fields autocomplete can be used for predictive search. For example, product names or categories can be
7575suggested as the keyword is being typed in.
7676``` 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"
7879client .autocomplete (' custom_fields.brand' , ' a' , callback);
7980```
8081
@@ -86,57 +87,36 @@ client.setAutocompleteSize(20);
8687
8788#### Search with fuzzy matching
8889``` 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 );
9193```
9294
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* )
94100``` 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 );
97103```
98104
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.
107106
108- #### Set JSON Web Token (for authentication)
109107``` 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 ();
113110
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 ();
118113```
119114
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
136116
137117#### Define language filter
138118``` js
139- // Documents in specific language (e.g. "en" or "de")
119+ // Fetch documents in specific language (e.g. "en" or "de")
140120client .setLanguage (' en' );
141121```
142122
@@ -194,34 +174,14 @@ var filter = {
194174client .setFilterObject (filter);
195175```
196176
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-
217177#### Set result type
218178``` js
219179// By default, fetch all search results
220180// If "organic", Pinned results and Promotions are left out
221181client .setResultType (' organic' );
222182```
223183
224- #### Facets
184+ ### Facets
225185``` js
226186// Declare fields for faceting. Number of hits found from
227187// these fields will be returned
@@ -234,6 +194,72 @@ Use the following function to get more or less facets.
234194client .setNumberOfFacets (20 );
235195```
236196
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+
237263## Supported web browsers and node.js versions
238264The client is tested on
239265- Chrome
@@ -251,6 +277,12 @@ To modify this client library, clone this repository to your computer and execut
251277npm install
252278```
253279
280+ #### Code
281+ Re-compile automatically when source files are changed
282+ ``` sh
283+ npm run watch
284+ ```
285+
254286#### Run tests
255287``` sh
256288npm test
0 commit comments