Is it possible to search across Rails models?

Hi, I am implementing Algolia using Rails. I have a question.

Suppose I have a photo.rb, video.rb, etc. I know how to search for single items, but if I want to search across these, how should I implement this?

I am using GitHub - algolia/algoliasearch-rails: AlgoliaSearch integration to your favorite ORM.

Thank you in advance.

-------------------------------- my environment

  • Rails version: 6.1.6.1
  • Algolia Rails integration version: 2.2.1

Hi! The Rails module plugs into ActiveRecord and creates an index per model. You should be able to see this in your Algolia dashboard.

To search across these indices, you’ll want to do a multi-index search on the front end. You can do this using the InstantSearch frontend libraries, but this is a place where Autocomplete.js really shines:

@chuck.meyer
Thank you for Advise!!
I understand how to do a across search on the front end, but is there any way to implement it on the backend?

I try search across in Rails backend.

Sorry I missed this. For backend search you’d need to make query calls using the Ruby client library against each index and then combine the resulting hits, but usually we discourage doing this type of search on the backend. Algolia is best when doing real time search directly in the front end as the user types.