Problem
I have a search page view (showing a search index). It has seven exposed filters and a facet to limit search results. When using multiple exposed filters to limit the search and after that using the facet to limit the search even more, the view shows zero results when there should be a result. See the attached screenshot.
Accidental fix
As I was debugging this issue I found, by accident, that putting the line:
$db_query->getArguments();
Into function:
public function search(QueryInterface $query)
Of file:
search_api_db/src/Plugin/search_api/backend/Database.php
Fixed the issue. As far as I can see only calling this method shouldn't do anything. Somewhere else something is wrong. When debugging the objects I found that query placeholders were being mixed up or even left out of the final query.
Comment | File | Size | Author |
---|---|---|---|
#5 | Screen Shot 2017-01-13 at 12.57.42.png | 397.01 KB | MartijnB |
Screen Shot 2016-08-18 at 16.44.24.png | 164.1 KB | MartijnB |
Comments
Comment #2
MartijnB CreditAttribution: MartijnB commentedComment #3
MartijnB CreditAttribution: MartijnB commentedComment #4
drunken monkeyDid you try with the latest dev release of this module (or Alpha 17)? Please note that you should uninstall it, then update and re-install, though, to make sure that no update-caused errors occur.
Then, can you provide a test case that's failing, or post the generated (Search API) query? (It would normally be visible in the Views preview, but of course you can't set facets there, so probably just add
to the beginning of
search()
. (Man, this is significantly more complicated in D8 …)Finally, which DBMS are you using? Postgres also had problems with complex arguments in D7 (which we ran into with the DB backend).
Edit: The empty strings in the above code are supposed to be opening and closing
<pre>
tags.Comment #5
MartijnB CreditAttribution: MartijnB commentedSorry for my very very late response! I finally had time to update Facets and Search API. Facets to 8.x-1.0-alpha7 and Search API to 8.x-1.0-beta3. No dev versions because it has to go into production and because of the tedious job of uninstalling and installing and creating everything again. Not something I want to do another time!
Unfortunately the bug is still there. :(
But when I put the same line:
$db_query->getArguments();
into the search function everything works fine again.
I've outputted the query with your line of code. See the image attached.
I'm using MariaDB.
Comment #6
drunken monkeyAs written:
That would make the output considerably more readable.
In any case, there doesn't seem to be anything obviously wrong with the search query, and a quick test shows me there also shouldn't be a problem in the select query generated by the DB backend. Still, could you maybe also find out and post the select query corresponding to the search?
Also, could you maybe check directly in the database whether there should be entities matching those search criteria? Maybe the counts displayed by Facets are just wrong.
Comment #7
MartijnB CreditAttribution: MartijnB commentedSo I used your drupal_set_message with pre tags this time. :) In the search I'm doing the facets counts are correct. I couldn't find any difference in the queries. But when I outputted $db_query at the end of the search function I got two different queries.
This one is wrong:
This one is correct:
Notice the line:
GROUP BY item_id, score, w0) t)) ))AND( (t_2.field_organization_type = :db_condition_placeholder_6) ))
Where db_placeholder_6 should be db_placeholder_8.
Funny thing: When I put the drupal_set_message, outputting $db_query, before the line:
$results = $query->getResults();
Things work ok again. That is also the spot where I put the line:
$db_query->getArguments();
Getting confused now! :-S
Comment #8
drunken monkeyThanks for the detailed findings, very helpful!
This sounds like it could have to do with this Core bug: #2142107-44: Complex cloned query dependent on __toString() call. Could you give the patch in #44 there a try?
Comment #9
drunken monkeyComment #10
MartijnB CreditAttribution: MartijnB commentedYes! The patch works! :)
Any idea when this patch is going to be in core?
Comment #11
drunken monkeyGood to hear, thanks for reporting back!
No, sorry. Getting bug fixes (or other patches) into Core requires a pretty large (mostly diplomatic) effort, so unless someone invests that, the patch might lie there for several more years. (As you can see, my first patch for the issue, for D7, is already two and a half years old.)
However, you should in any case report in the Core issue that the patch works for you. Maybe that will help at least a bit.
Comment #13
jordan.jamous CreditAttribution: jordan.jamous at Eighty Options commentedThanks @drunkin-monkey
patch in #44 [ref: https://www.drupal.org/comment/11885996#comment-11885996 Complex cloned query dependent on __toString() call] worked fine for me