Skip to content

Ruby hashes/arrays to Meilisearch filter expressions #616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AliOsm opened this issue Mar 28, 2025 · 3 comments · May be fixed by #617
Open

Ruby hashes/arrays to Meilisearch filter expressions #616

AliOsm opened this issue Mar 28, 2025 · 3 comments · May be fixed by #617
Labels
enhancement New feature or request

Comments

@AliOsm
Copy link

AliOsm commented Mar 28, 2025

Description

It would be nice to provide a class like Meilisearch::FilterBuilder that converts Ruby hashes/arrays to Meilisearch filter expressions.

I already did that in one of my projects and it provides a huge added value. I just get the params from the request, build the hash, then pass it to the builder.

The question is, will you be open to upstream the implementation of my builder into the gem? Or should I extract the class to my own gem ?,? (Any naming suggestions in this case 😅)

Basic example

Example 1

Ruby object:

or: [
  { genres: 'horror' },
  { and: [
    { genres: 'comedy' },
    { release_date: { gt: 795_484_800 } }
  ] }
]

Meilisearch filter expressions:

genres = horror OR (genres = comedy AND release_date > 795484800)

Example 2

Ruby object:

{ genres: 'horror', director: 'Jordan Peele' }

Meilisearch filter expressions:

genres = horror AND director = 'Jordan Peele'

Example 3

Ruby object:

{ not: { genres: { in: %w[horror comedy] } } }

Meilisearch filter expressions:

NOT (genres IN [horror, comedy])

Other

I have the implementation and the specs for it, but I'm not sure about publishing a PR to this gem, or extract it to my own gem.

@AliOsm AliOsm added the enhancement New feature or request label Mar 28, 2025
@ellnix
Copy link
Contributor

ellnix commented Mar 29, 2025

Since you have already done the work, there is no harm in opening a PR. This repo is open to outside contributors 😄

I personally like the idea, I'd like to see the implementation as well.

@AliOsm
Copy link
Author

AliOsm commented Mar 29, 2025

@ellnix I just submitted the PR #617, I hope it gets a positive feedback 😆

@ellnix
Copy link
Contributor

ellnix commented Mar 29, 2025

@AliOsm I saw it when you opened it, sorry it took a while to read and test. I'm looking forward to working with you on it 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants