meilisearch / meilisearch-rails

Meilisearch integration for Ruby on Rails
https://www.meilisearch.com
MIT License
295 stars 48 forks source link

Support selecting specific attributes from a model #371

Closed StanBright closed 3 weeks ago

StanBright commented 3 weeks ago

Description How difficult would it be to support selecting specific attributes only when loading models after a search.

Basic example I'm imaging an option of ms_search that accepts a list of attributes to be selected.

e.g. Service.search("query", select: [:name, :slug])

For example, I've started using Meilisearch for autocomplete of products in SaaSHub. The model I'm searching has quite a few attributes (some of them big), and we only need the "name" & "slug" of that product.

i.e. without this feature/option, the server is loading (and deserializing) a dozen big models on every keystroke. At the same time, it's only the name and slug that are necessary.

StanBright commented 3 weeks ago

Never mind, I think that all I have to do is use the underlying index directly.

e.g. Service.index.search("query") ... and then load the models via the "hits" result.