algoliasearch-client-javascript icon indicating copy to clipboard operation
algoliasearch-client-javascript copied to clipboard

after setSettings function, the settings are not affected...

Open developer0116 opened this issue 5 years ago • 1 comments

index.setSettings({ 'customRanking': ['desc(followers)'] }).then(() => {
    index.search('query string', {
       attributesToRetrieve: ['firstname', 'lastname'],
       hitsPerPage: 50,
    }).then(({ hits }) => {
    console.log(hits);
   });
});

I wrote code like above, but the queried results are not sorted...

I'd like your help. Thanks

developer0116 avatar Sep 11 '20 17:09 developer0116

index
  .setSettings({ customRanking: ['desc(followers)'] })
  .wait() // essential; settings aren't synchronous
  .then(() =>
    index
      .search('query string', {
        attributesToRetrieve: ['firstname', 'lastname'],
        hitsPerPage: 50,
      })
      .then(({ hits }) => {
        console.log(hits);
      })
  );

indexing operations aren't synchronous, so you need to wait for completion if you want to do an operation based on it right after.

Haroenv avatar Sep 14 '20 07:09 Haroenv