Git Product home page Git Product logo

Comments (5)

USvER avatar USvER commented on August 28, 2024 1

Thank you for explanation! Now everything clear!

from algoliasearch-client-ruby.

raphi avatar raphi commented on August 28, 2024

Hi @USvER

You can simply store the returned client in a variable, and call this method multiple times:

client_one = Algolia.init(application_id: 'APP_ID_1', api_key: 'API_KEY')
client_two = Algolia.init(application_id: 'APP_ID_2', api_key: 'API_KEY')

Enjoy

from algoliasearch-client-ruby.

USvER avatar USvER commented on August 28, 2024

Thanks! I was under impression that .init stores application_id and api_key in global variables and will interfere each other.

from algoliasearch-client-ruby.

raphi avatar raphi commented on August 28, 2024

Indeed, for backward compatibility, we kept it. Each time you call .init, it keeps the last client as a singleton. If you use Algolia.methods, it will use the most recent instantiated client. But we don't recommend to use these methods. Instead, we've implemented them inside each Client and Index class as well, and we encourage you to use these!

from algoliasearch-client-ruby.

Spone avatar Spone commented on August 28, 2024

Hi @USvER

You can simply store the returned client in a variable, and call this method multiple times:

client_one = Algolia.init(application_id: 'APP_ID_1', api_key: 'API_KEY')
client_two = Algolia.init(application_id: 'APP_ID_2', api_key: 'API_KEY')

Enjoy

⚠️ Warning! If you do that in a Rails app (that uses algoliasearch-rails) you will need to call the Algolia.init method once again with your standard parameters, else you will end up with the latest Algolia application as the default.

Here is what we ended up doing:

client_one = Algolia.init(application_id: 'APP_ID_1', api_key: 'API_KEY')
client_two = Algolia.init(application_id: 'APP_ID_2', api_key: 'API_KEY')

Algolia.init(
  application_id: AlgoliaSearch.configuration[:application_id],
  api_key: AlgoliaSearch.configuration[:api_key]
)

But it's clearly not ideal. I hope the algoliasearch-rails gem will support multiple Algolia apps in the future.

from algoliasearch-client-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.