We should, internally, add some new operators in D8, which have been missed regularly in D7: IN, NOT IN, BETWEEN and NOT BETWEEN.
We should then of course also use and support them in the Views integration (could be a follow-up issue, though).
Estimated Value and Story Points
This issue was identified as a Beta Blocker for Drupal 8. We sat down and figured out the value proposition and amount of work (story points) for this issue.
Value and Story points are in the scale of fibonacci. Our minimum is 1, our maximum is 21. The higher, the more value or work a certain issue has.
Value: 8
Story Points: 13
Comments
Comment #2
drunken monkeyComment #3
stborchertOk, lets start with the tests to see which direction this takes ...
Comment #4
borisson_There is a bunch of places in the patch where you change
arrayto[], Search API only uses the long array notation. If you can revert that change it'll be easier to see what changes are actually needed here.Comment #5
borisson_back to NW.
Comment #6
stborchertOk, changed short array syntax back to long arrays.
Comment #7
borisson_I think this looks good and I like that there's additional testcoverage. I did find some things that can be improved.
Why is this now a public method?
Let's make this more explicit, it's
string|string[].Again,
string|string[]This is the only method where an early return is added, let's put the foreach in an
elsestatement; like the other processorsComment #8
stborchertUh, I forgot to change the function visibility back after some debugging attempts ...
Added your changes.
Comment #9
borisson_I think this looks great, let's see what @drunken_monkey thinks about this patch. The added testcases are awesome!
Comment #10
stborchertUhm, but it's not complete, yet :)
I will have look into search_api_db to see, what has to be done there.
Comment #11
borisson_Alright, setting back to NW.
Comment #12
stborchertNext round.
I updated the tests for search_api_db and think, it's complete now. Please note that "NOT BETWEEN" doesn't seem supported by Drupal core itself yet. I've created an issue to see, if we could add it (#2686483: Add support for database condition operator "NOT BETWEEN").
Additional question: do we want to prefix the assertion messages (i.e. within
\Kernel\BackendTest) with at least the function name? Because the test uses only one test function (testFramework()) it is very hard to debug, which specific test fails.Comment #13
stborchertForgot the interdiff.
Comment #14
drunken monkeyAwesome job, thanks a lot!
I'll try to take a closer look and provide a detailed review later this week.
Doesn't it report the line number anyways?
From what I remember, I never had a problem with this yet.
Comment #15
stborchertUnfortunately it always prints line 93 (function stub of
testFramework()).Comment #16
drunken monkeyThanks again a lot for your work!
After a bit of reviewing, this still looks very good. The main issue I found was that the processor plugins shouldn't have to change – that's what our
FieldsProcessorPluginBaseclass is there for. I fixed that in the attached patch.Otherwise, it's mostly a bit of re-phrasing or reformatting.
Anyways, please test/review!
Comment #19
drunken monkeyThis should fix it.
Tests/reviews still welcome!
Comment #22
rosinegrean commentedHello,
I've re created the patch. It applies now.
Here it goes.
Comment #25
rosinegrean commentedSorry, here goes again.
Comment #26
drunken monkeyThanks a lot!
You just seem to have introduced a small whitespace error – patch without it attached.
Can you otherwise confirm that the patch works as expected and looks good, code-wise?
Anyone else want to test/review?
Do we want to also adapt our Views filter plugins here to include those operators, or should we create a follow-up issue for that? (If the patch is otherwise RTBC, I guess a follow-up makes more sense, before the patch becomes out-dated again.)
Comment #27
borisson_I think it looks great code-wise, pretty sure that the views part can be a follow-up.
Comment #28
drunken monkeyToo late, already needed a re-roll!
But if the test bot is still happy, I'll just commit it.
Comment #30
drunken monkeyOK, committed!
I agree with you regarding a follow-up, here it is: #2695627: Add support for (NOT) IN and BETWEEN operators to Views.
Especially a good choice not doing this here because this one is a beta blocker, but the follow-up could even wait until after stable.
In any case, thanks again everyone in here – especially stBorchert, of course!
Comment #31
drunken monkeyI want to re-open this to discuss whether we don't want to add a "NOT BETWEEN" operator after all. That the operator isn't directly supported by the Drupal database layer isn't really an argument: the DB backend would just have to re-write the condition in a more complex way, but I don't think it's impossible (or even difficult) to do.
All other backends don't have the luxury of using operators as-is anyways, and without adding the operator I don't think developers can emulate that logic "manually" (like they could for
IN, for instance).Any other opinions?
Comment #32
mkalkbrennerI now added the support for BETWEEN to the Solr backend as well.
But I'm against "NOT BETWEEN" because the programmer who requires that should be able to do the required conversion by himself using the existing operators, for example BETWEEN a,b OR BETWEEN c,d instead of
BETWEEN a,d AND NOT BETWEEN b,c.
Comment #33
drunken monkeyBut if you don't have a given range, there's no way to re-write this correctly. Also, it's not possible to use that in, e.g., a Views filter, and the Search API isn't just meant for developers.
Comment #34
mkalkbrennerIf you really like, you can add NOT BETWEEN.
For sure we could handle this in the solr backend as well, even if the query API isn't intuitive for people coming from Solr. I feels more like SQL. Personally I don't like that direction, but that's just me ;-)
Comment #35
drunken monkeyThanks, that's very generous of you!
Patch attached. As mentioned, it's also not quite as simple in the DB backend, unfortunately, but not too complicated either.
Comment #37
drunken monkeyComment #38
drunken monkeyNeeded a re-roll.
Comment #39
drunken monkeyComment #41
drunken monkeyCommitted.
Comment #43
R.Muilwijk commentedI run into a problem with the IN operator using the database backend:
1) Add ViewsData for a search_api_field to InOperator:
2. Now expose the field in views and it's a select (or multiselect).
3. The error I get is: Unknown operator 'in' used in search query condition.
The BackendPluginBase::validateOperator validates on 'IN' and not on 'in'.