-
Notifications
You must be signed in to change notification settings - Fork 37
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
Adds customizable default operator to concatenate conditions #49
Conversation
hi, thx for the fast PR. Very cool. Two points from my side: a) The grammar ist not yet fully correct The following test should work, but it doesn't (maybe add it to the test suite as well) def test_specific_operator
expected = create(:product, :title => "Title Avengers")
rejected = create(:product, :title => "Title Inception")
results = Product.search_with_or_operator("Title AND Avengers")
assert_includes results, expected
refute_includes results, rejected
end b) I'd probably prefer to add the option as a query option instead of a scope option. Product.search("Avengers Movie", default_operator: :or) What do you think? |
the rule should be
|
I was going to say I will need a little help with the grammar, thank for that. I'm ok having the default_operator as query parameter, actually it's look better in terms of responsibilities. going to update the code to pass default_operator as query parameter |
@mrkamel the tests locally are failing intermittently. Really odd, any idea why? |
@mrkamel Can you confirm if the grammar is correct? |
hm, i think the issue is: you can't use the reflection like this. The reflection object is build when the search_scope gets defined. Thus, it is global and using it like this would not be thread safe. The pipeline fails, because it is not reset to |
Refactored to pass the options hash along the query. Also renamed the variable to query_options, seems more descriptive. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice, only some minor improvements are required before we can merge it.
Two questions:
|
sure, extract it. Add a SearchCop::Helpers class/module with a
You just need to adapt
|
hey @mrkamel, can you take a look on the CI? The tests are not running
|
pipeline is fixed in master |
Already updated the branch and the tests are passing 🚀 |
Awesome, great job! I'm fine with it. I'll do some final manual tests and then merge it. Feel free to add something to the readme. |
Ok, I will add some examples to the readme |
Based on the issue #48.
This PR adds an option to define the default operator to join the conditions.
By default multiple conditions on
where
are joined withAND
operator and this new option allows to define to operator (AND
orOR
) to join the multiple conditions