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

Fix #146 : add a way to make queries that don't change the inner state #193

Merged
merged 8 commits into from Sep 1, 2015
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 33 additions & 1 deletion README.md
Expand Up @@ -569,7 +569,39 @@ helper.setIndex('index_orderByPrice').search();
#### Get the current index

```js
var currentIndex = helper.state.index;
var currentIndex = helper.getIndex();
```

### One time query

Sometime it's convenient to reuse the current search parameters with small changes
without changing the state stored in the helper. That's why there is a function
called `searchOnce`. This method does not trigger `change` or `error` events.

#### Using searchOnce with a callback

```js
var state =
helper.searchOnce(
helper.state.addFacetRefinement('facet', 'f2');,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small typo, trailing ;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would start with a simpler example instead of calling addFacetRefinement, something like:

helper.searchOnce({hitsPerPage: 1}, function(error, content, state) { /*... */ });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok makes sense. Actually I think this way of expressing the mutation of the state is nice but it involves creating a full new search state each time we call one of the methods which is not that wise...

function(error, content, state) {
// if an error occured it will be passed in error, otherwise its value is null
// content contains the results formatted as a SearchResults
// state is the instance of SearchParameters used for this search
});
```

#### Using searchOnce with a promise

```js
var state1 =
helper.searchOnce(helper.state.addFacetRefinement('facet', 'f1')).then(function(res) {
// res contains
// {
// content : SearchResults
// state : SearchParameters (the one used for this specific search)
// }
});
```

### Query parameters
Expand Down