Searching for multiple words using "OR" condition is actually impossible due to this block of code here:
if ($mul_words) {
$db_query->having('COUNT(DISTINCT t.word) >= ' . $var, array($var => $subs));
}
else {
$db_query->having('COUNT(DISTINCT t.word) >= ' . $var, array($var => $subs));
}
1) When multiple words are provided to filter results using an OR condition, any matching word should result in a hit.
However, this block of code requires at least $var hits, where $var is the number of words provided.
Effectively, this transforms the query into an "AND", since the only hits will be those records which match all inputs.
2) The if() condition is unnecessary since the behavior is always the same.
Comments
Comment #1
aaronbaumanHere is the generated query:
As you can see, the inner-most query `t` uses an "OR" condition, but the `subquery` requires two hits for any match.
Comment #2
drunken monkeyThanks for reporting this issue!
You are doubtlessly correct about the
ifbeing useless, that really doesn't make any sense. It seems to have been introduced in the early stages of the module, with this change (3e930208):So maybe we should just remove the
DISTINCTin theelsebranch? It makes sense: if there aren't multiple words, there will be just a single "distinct" word. There is some weird magic with nested keys going on, though, so I'm not entirely sure. God give I'd still understand my own code … I guess, for this module I never really did.Anyways, that being said, I can't really find any actual bug that occurs related to this. (As said, my interpretation would be that the
DISCTINCTis unnecessary, but not problematic.) Attached are some additional tests (which we could of course add in any case), all of which pass without a problem (with or without the secondDISTINCT).Can you come up with a test that fails? How did you generate the above query?
Comment #3
drunken monkeyI now committed the patch with the additional tests (and removed the
DISTINCTin theelsebranch), can't do any harm to have them.If you can provide more information about what you think is actually going wrong, please re-open.