Instantsearch.js: Changing index with sortBy doesn't use a custom client

Created on 24 Apr 2017  路  5Comments  路  Source: algolia/instantsearch.js

Do you want to request a feature or report a bug?

bug

@Ardalic can you make a jsfiddle with https://jsfiddle.net/vvoyer/0wm3donb/4/ as a base?

Bug: What is the current behavior?

When injecting a custom client) and then changing the index to a replica (e.g: change sort by index_by_price_asc replica), the custom client isn't used.

Bug: What is the expected behavior?

The provided custom client is used

What is the version you are using? Always use the latest one before opening a bug issue.

@Ardalic, what version are you using?

see https://github.com/algolia/instantsearch.js/issues/1738#issuecomment-296707399

Bug

Most helpful comment

Glad we came to a solution!

All 5 comments

Hello,

I'll try to describe the issue:

I want to show more than 1000 records in Algolia instantsearch.js, which is already sufficient to serve as a category page. That's why I tried #2118 , but as a solution I came up with is injecting a custom client with createAlgoliaClient parameter which has paginationLimitedTo parameter inside.

This works only if you are on same index as custom client. E.g: when you ad a sortBySelector widget, because indexes/replicas are different, this custom client becomes useless and the settings set inside doesn't work.

@Ardalic can you make a jsfiddle with https://jsfiddle.net/vvoyer/0wm3donb/4/ as a base?

This is roughly what I did:

https://jsfiddle.net/0wm3donb/10/

Since the data is example data, and there is no custom api key with search and browse features, fiddle cannot be run without changing the api keys

To reproduce the error:

  1. Pass a custom client while initializing instantsearch. This client should have a custom ACL with search and browse. Also add the same key to apiKey while setting instantsearch() (please see my fiddle)
  2. See search results
  3. Go to last page from pagination, it'll show more than 1000 records
  4. Change sortBySelector to something different
  5. Go to last page. It won't show more than 1000 records and now you have an error in the console.

In the end, you'll also see an error on the console like this:

73ed0bca-2916-11e7-9460-ded1f02e1c89

(Method not allowed with this API key)

So my idea is that, because there's an initIndex() method passed to algoliasearch() (please see my fiddle line number 2 and 3), different indexes are not recognised / changed in custom client.

@Ardalic, what version are you using?

I'm using Algoliaclient v3 and instantsearch v1 from CDN. Here are my links that I source on the webpage:

https://cdn.jsdelivr.net/algoliasearch/3/algoliasearch.min.js
https://cdn.jsdelivr.net/instantsearch.js/1/instantsearch.min.js
https://cdn.jsdelivr.net/instantsearch.js/1/instantsearch.min.css

Thanks for the interest, it's greatly appreciated!

Thanks @ardakilic, that's a complete report. I'll have a look. I think the error might be in the js helper, though.

The setting of paginationLimitedTo should be done in the index configuration. This is not a query time parameter. Setting it in the helper or via instantsearch.js configuration won't have any effect.

When you reindex your data, you should then apply paginationLimitedTo. For example using the JS Client:

var client = algoliaSearch(/* params go here */);
var index = client.initIndex();
index.setSettings({
  paginationLimitedTo: 2000
});

Since it's a sensible parameter, you need either the admin key or a key with set settings rights. To create a new key, you can go to https://www.algolia.com/api-keys/restricted and click on create new key. Then at the bottom, check the set settings check box.

@bobylito Aha, got you now!

So you're saying is that I have to save settings "once" for each index and replica. So it's to be run also for replicas. That's what I've been missing!

Thank you! It's fixed. So no need to inject a custom client neither.

Glad we came to a solution!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timkelty picture timkelty  路  3Comments

jvreeken picture jvreeken  路  3Comments

devwax picture devwax  路  3Comments

ChristopherDosin picture ChristopherDosin  路  4Comments

zackify picture zackify  路  4Comments