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 all 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
36 changes: 35 additions & 1 deletion README.md
Expand Up @@ -585,7 +585,41 @@ 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.

In the following, we are using `searchOnce` to fetch only a single element using
all the other parameters already set in the search parameters.

#### Using searchOnce with a callback

```js
var state = helper.searchOnce(
{hitsPerPage: 1},
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({hitsPerPage: 1})
.then(function(res) {
// res contains
// {
// content : SearchResults
// state : SearchParameters (the one used for this specific search)
// }
});
```

### Query parameters
Expand Down