Skip to content

Commit 744d8e3

Browse files
committed
Add stats docs. Reorganize order
1 parent 5b8f89e commit 744d8e3

File tree

1 file changed

+63
-33
lines changed

1 file changed

+63
-33
lines changed

README.md

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -90,49 +90,39 @@ client.setAutocompleteSize(20);
9090
client.setFuzzyMatch(false);
9191
```
9292

93-
#### Collect analytics
93+
### Search analytics
94+
#### Send search event to analytics
95+
When search is executed, send the event to your AddSearch Analytics Dashboard.
9496
```js
95-
// Control whether search queries are sent to your AddSearch Analytics Dashboard or not (default: true)
96-
client.setCollectAnalytics(false);
97+
// If the numberOfResults is 0, the search is shown in the list of "queries with no hits"
98+
client.sendStatsEvent('search', keyword, {numberOfResults: n});
9799
```
98100

99101
#### Send click event to analytics
100102
When a search results is clicked, send the event to your AddSearch Analytics Dashboard. Information on clicks is used
101103
in your statistics and in the self-learning search algorithm.
102104
```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);
105+
// documentId is the 32-character long id that is part of each hit in search results.
106+
// position is the position of the document that was clicked, the first result being 1
107+
client.sendStatsEvent('click', keyword, {documentId: id, position: n});
106108
```
107109

108-
#### Set JSON Web Token (for authentication)
110+
#### Set or get stats session ID
111+
Control the search session ID manually. Search queries with the same ID are grouped on the Analytics Dashboard.
112+
For example, in a search-as-you-type implementation the final keyword of a given session is shown.
109113
```js
110-
// Add JWT to the search request (if protected search index)
111-
client.setJWT(token);
114+
client.getStatsSessionId();
115+
client.setStatsSessionId(id);
112116
```
113117

114-
#### Set user token (for personalized search results)
118+
#### Collect search events automatically
119+
Not recommended. For example, search-as-you-type implementation would fire a statistics event after every keystroke
115120
```js
116-
// Add a user token to the search request (if personalization in use)
117-
client.setUserToken('uuid');
121+
// Control whether search queries are sent to your AddSearch Analytics Dashboard automatically or not (default: false)
122+
client.setCollectAnalytics(true);
118123
```
119124

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-
```
125+
### Filters
136126

137127
#### Define language filter
138128
```js
@@ -194,7 +184,14 @@ var filter = {
194184
client.setFilterObject(filter);
195185
```
196186

197-
#### Manage paging
187+
#### Set result type
188+
```js
189+
// By default, fetch all search results
190+
// If "organic", Pinned results and Promotions are left out
191+
client.setResultType('organic');
192+
```
193+
194+
### Pagination
198195
Set page number, page size and sorting parameters. It's possible to order results by:
199196
- relevance (descending)
200197
- date (ascending or descending)
@@ -214,13 +211,40 @@ client.nextPage();
214211
client.previousPage();
215212
```
216213

217-
#### Set result type
214+
### Personalization
215+
216+
#### Set user token (for personalized search results)
218217
```js
219-
// By default, fetch all search results
220-
// If "organic", Pinned results and Promotions are left out
221-
client.setResultType('organic');
218+
// Add a user token to the search request (if personalization in use)
219+
client.setUserToken('uuid');
220+
```
221+
222+
#### Send personalization events with search query
223+
In personalized search, user events are typically sent to AddSearch via API and a user token
224+
is passed with the search query (see setUserToken function).
225+
An alternative way is to send user events needed for personalization with the search query.
226+
227+
```js
228+
// Events depend on the personalization strategy
229+
// Contact AddSearch for more information
230+
var events = [
231+
{favorite_genre: 'rock'},
232+
{favorite_band: 'Red Hot Chili Peppers'},
233+
{least_favorite_genre: 'country'}
234+
];
235+
236+
client.setPersonalizationEvents(events);
237+
```
238+
239+
### Other
240+
241+
#### Set JSON Web Token (for authentication)
242+
```js
243+
// Add JWT to the search request (if protected search index)
244+
client.setJWT(token);
222245
```
223246

247+
224248
#### Facets
225249
```js
226250
// Declare fields for faceting. Number of hits found from
@@ -251,6 +275,12 @@ To modify this client library, clone this repository to your computer and execut
251275
npm install
252276
```
253277

278+
#### Code
279+
Re-compile automatically when source files are changed
280+
```sh
281+
npm run watch
282+
```
283+
254284
#### Run tests
255285
```sh
256286
npm test

0 commit comments

Comments
 (0)