Skip to content

Conversation

@scambra
Copy link
Contributor

@scambra scambra commented Jul 8, 2025

There are cases where I want to use a simpler grammar, for example one which only supports words and quoted words, and use AND to find results with all tokens, or another grammar which uses OR to find results with any token.

With this option, I was able to do it writting a grammar (treetop file and modules with to_sql methods), but still use the search method and the association resolver.

@scambra
Copy link
Contributor Author

scambra commented Jul 8, 2025

I see my change breaks usage with associations in ruby 2.x, but ruby 2 is EOL, do you want to keep supporting those versions?

For example, this is broken for all versions:
LogicalQueryParser.search("aa AND bb", Doc, :title, tags: :name)

But this way works for ruby 3.x, I changed a spec in this way to fix tests on ruby 3.x:
LogicalQueryParser.search("aa AND bb", Doc, :title, { tags: :name })

To have it working in ruby 2.x, this way is required, which is a bit weird:
LogicalQueryParser.search("aa AND bb", Doc, :title, { tags: :name }, **Hash.new)

I can change the spec to use **Hash.new so it works for all ruby versions, but a note may be needed in the README, but I think you could release the nexte version with supporting ruby 2.x, and old rails versions, lower than 6.0, which don't work with ruby 3.

@scambra
Copy link
Contributor Author

scambra commented Jul 11, 2025

I found another way to provide a parser, which works with ruby 2.x, and also works if the model has a parser association. It doesn't change the syntax when no parser is provided. If another parser is provided, it requires to use columns: [...], parser: ...

@scambra
Copy link
Contributor Author

scambra commented Feb 9, 2026

As 0.5.0 requires ruby >= 3, I changed the code to support providing a parser, without breaking any existing code using LogicalQueryParser.search.

I copied the existing specs for search, and added parser option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant