Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

docs: update event signature #701

Merged
merged 1 commit into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ var helper = algoliasearchHelper(client, 'indexName', {
disjunctiveFacets: ['director']
});

helper.on('result', function(data){
console.log(data.hits);
helper.on('result', function(event){
console.log(event.results);
});

helper.addDisjunctiveFacetRefinement('director', 'Clint Eastwood');
Expand Down Expand Up @@ -110,9 +110,9 @@ angular.module('searchApp', ['ngSanitize', 'algoliasearch'])
disjunctiveFacets: ['category', 'manufacturer'],
hitsPerPage: 5,
});
$scope.helper.on('result', function(content) {
$scope.helper.on('result', function(event) {
$scope.$apply(function() {
$scope.content = content;
$scope.content = event.results;
});
});
$scope.toggleRefine = function($event, facet, value) {
Expand Down Expand Up @@ -168,8 +168,8 @@ var helper = algoliasearchHelper(client, 'indexName'/*, parameters*/);

3. read the results (with the event "result" handler) and update the UI with the results<br/>
```
helper.on('result', function(results) {
updateUI(results);
helper.on('result', function(event) {
updateUI(event.results);
});
```

Expand All @@ -196,8 +196,8 @@ Example:
var helper = algoliasearchHelper(client, indexName);

// Let's monitor the results with the console
helper.on('result', function(content) {
console.log(content);
helper.on('result', function(event) {
console.log(event.results);
});

// Let's make an empty search
Expand Down Expand Up @@ -431,8 +431,8 @@ You will get a hierarchical presentation of your facet values: a navigation menu
of your facet values.

```js
helper.on('result', function(data){
console.log(data.hierarchicalFacets[0]);
helper.on('result', function(event){
console.log(event.results.hierarchicalFacets[0]);
// {
// 'name': 'products',
// 'count': null,
Expand Down Expand Up @@ -624,9 +624,9 @@ helper.clearRefinements(function(value, attribute, type) {
#### Get the values of a facet with the default sort

```js
helper.on('result', function(result) {
helper.on('result', function(event) {
// Get the facet values for the attribute age
result.getFacetValues('age');
event.results.getFacetValues('age');
// It will be ordered :
// - refined facets first
// - then ordered by number of occurence (bigger count -> higher in the list)
Expand All @@ -637,9 +637,9 @@ helper.on('result', function(result) {
#### Get the values of a facet with a custom sort

```js
helper.on('result', function(result) {
helper.on('result', function(event) {
// Get the facet values for the attribute age
result.getFacetValues('age', {sortBy: ['count:asc']});
event.results.getFacetValues('age', {sortBy: ['count:asc']});
// It will be ordered by number of occurence (lower number => higher position)
// Elements that can be sorted : count, name, isRefined
// Type of sort : 'asc' for ascending order, 'desc' for descending order
Expand All @@ -651,9 +651,9 @@ helper.on('result', function(result) {
*This only apply on numeric based facets/attributes.*

```js
helper.on('result', function(result) {
helper.on('result', function(event) {
// Get the facet values for the attribute age
result.getFacetStats('age');
event.results.getFacetStats('age');
});
```

Expand Down
20 changes: 10 additions & 10 deletions documentation-src/metalsmith/content/gettingstarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ Once you've added those lines, you need to listen to the results coming from Alg
For now, we'll implement a very basic display of the JSON response in the page.

```javascript
helper.on('result', function(content) {
renderHits(content);
helper.on('result', function(event) {
renderHits(event.results);
});

function renderHits(content) {
Expand Down Expand Up @@ -139,12 +139,12 @@ see how to add a search input to let our users do a textual search in the data.

Before going further, let's customize a little bit the display of our results.
We're going to focus on the actual results computed by Algolia. The
results are returned in the `hits` attribute of the `content`. Let's display
results are returned in the `hits` attribute of the `results`. Let's display
only the `name` of each product for now.

```javascript
helper.on('result', function(content) {
renderHits(content);
helper.on('result', function(event) {
renderHits(event.results);
});

function renderHits(content) {
Expand Down Expand Up @@ -181,8 +181,8 @@ results returned by Algolia. This way the users can easily understand why the
results match their query.

```javascript
helper.on('result', function(content) {
renderHits(content);
helper.on('result', function(event) {
renderHits(event.results);
});

function renderHits(content) {
Expand Down Expand Up @@ -267,9 +267,9 @@ an attribute. The object returned by this method contains three properties:
Let's add the rendering of the facet list into the `result` handler.

```javascript
helper.on('result', function(content) {
renderFacetList(content);
renderHits(content);
helper.on('result', function(event) {
renderFacetList(event.results);
renderHits(event.results);
});
```

Expand Down
4 changes: 2 additions & 2 deletions documentation-src/metalsmith/content/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ You will get a hierarchical presentation of your facet values: a navigation menu
of your facet values.

```js
helper.on('result', function(data){
console.log(data.hierarchicalFacets[0]);
helper.on('result', function(event){
console.log(event.results.hierarchicalFacets[0]);
// {
// 'name': 'products',
// 'count': null,
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ var SearchResults = require('./src/SearchResults');
* facets: ['shipping'],
* disjunctiveFacets: ['category']
* });
* helper.on('result', function(result) {
* console.log(result);
* helper.on('result', function(event) {
* console.log(event.results);
* });
* helper
* .toggleFacetRefinement('category', 'Movies & TV Shows')
Expand Down
6 changes: 3 additions & 3 deletions src/SearchResults/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,11 @@ function vanillaSortFn(order, data) {
* @return {FacetValue[]|HierarchicalFacet} depending on the type of facet of
* the attribute requested (hierarchical, disjunctive or conjunctive)
* @example
* helper.on('results', function(content){
* helper.on('result', function(event){
* //get values ordered only by name ascending using the string predicate
* content.getFacetValues('city', {sortBy: ['name:asc']});
* event.results.getFacetValues('city', {sortBy: ['name:asc']});
* //get values ordered only by count ascending using a function
* content.getFacetValues('city', {
* event.results.getFacetValues('city', {
* // this is equivalent to ['count:asc']
* sortBy: function(a, b) {
* if (a.count === b.count) return 0;
Expand Down
45 changes: 23 additions & 22 deletions src/algoliasearch.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,59 @@ var version = require('./version');
/**
* Event triggered when a parameter is set or updated
* @event AlgoliaSearchHelper#event:change
* @property {SearchParameters} state the current parameters with the latest changes applied
* @property {SearchResults} lastResults the previous results received from Algolia. `null` before
* the first request
* @property {object} event
* @property {SearchParameters} event.state the current parameters with the latest changes applied
* @property {SearchResults} event.results the previous results received from Algolia. `null` before the first request
* @example
* helper.on('change', function(state, lastResults) {
* helper.on('change', function(event) {
* console.log('The parameters have changed');
* });
*/

/**
* Event triggered when a main search is sent to Algolia
* @event AlgoliaSearchHelper#event:search
* @property {SearchParameters} state the parameters used for this search
* @property {SearchResults} lastResults the results from the previous search. `null` if
* it is the first search.
* @property {object} event
* @property {SearchParameters} event.state the parameters used for this search
* @property {SearchResults} event.results the results from the previous search. `null` if it is the first search.
* @example
* helper.on('search', function(state, lastResults) {
* helper.on('search', function(event) {
* console.log('Search sent');
* });
*/

/**
* Event triggered when a search using `searchForFacetValues` is sent to Algolia
* @event AlgoliaSearchHelper#event:searchForFacetValues
* @property {SearchParameters} state the parameters used for this search
* it is the first search.
* @property {string} facet the facet searched into
* @property {string} query the query used to search in the facets
* @property {object} event
* @property {SearchParameters} event.state the parameters used for this search it is the first search.
* @property {string} event.facet the facet searched into
* @property {string} event.query the query used to search in the facets
* @example
* helper.on('searchForFacetValues', function(state, facet, query) {
* helper.on('searchForFacetValues', function(event) {
* console.log('searchForFacetValues sent');
* });
*/

/**
* Event triggered when a search using `searchOnce` is sent to Algolia
* @event AlgoliaSearchHelper#event:searchOnce
* @property {SearchParameters} state the parameters used for this search
* it is the first search.
* @property {object} event
* @property {SearchParameters} event.state the parameters used for this search it is the first search.
* @example
* helper.on('searchOnce', function(state) {
* helper.on('searchOnce', function(event) {
* console.log('searchOnce sent');
* });
*/

/**
* Event triggered when the results are retrieved from Algolia
* @event AlgoliaSearchHelper#event:result
* @property {SearchResults} results the results received from Algolia
* @property {SearchParameters} state the parameters used to query Algolia. Those might
* be different from the one in the helper instance (for example if the network is unreliable).
* @property {object} event
* @property {SearchResults} event.results the results received from Algolia
* @property {SearchParameters} event.state the parameters used to query Algolia. Those might be different from the one in the helper instance (for example if the network is unreliable).
* @example
* helper.on('result', function(results, state) {
* helper.on('result', function(event) {
* console.log('Search results received');
* });
*/
Expand All @@ -77,9 +77,10 @@ var version = require('./version');
* Event triggered when Algolia sends back an error. For example, if an unknown parameter is
* used, the error can be caught using this event.
* @event AlgoliaSearchHelper#event:error
* @property {Error} error the error returned by the Algolia.
* @property {object} event
* @property {Error} event.error the error returned by the Algolia.
* @example
* helper.on('error', function(error) {
* helper.on('error', function(event) {
* console.log('Houston we got a problem.');
* });
*/
Expand Down