Hi there. I could use some support getting search facets up and running.
I'm setting up a Drupal Commerce web store, and want to enable facetted searching for the products within the store. Eventually I'd like to filter by price, brand, etc. For now, however (for the sake of this post), I'm focused on a brand facet (filter based on a taxonomy field for the brand).
I'm certain I have all the correct api's / modules installed (definitely: facet api, search api, entity api, search facets, search views). I've created the search server (just a local database search) and Product Display index, along with a search view that filters for the full text search. Everything works great with the view, it displays everything when no search term is entered, and doing simple searches by keyword returns just the expected results (can be sorted, etc). I'll note that in this view, the field for the "brand" is also populated properly. So far so good.
I start to have problems as soon as I do anything with facets. As soon as I enable any facet (on the search index settings tab for "facets") then the search-view stops showing any results. I set the block up for the corresponding facet to display in a sidebar, but it also doesn't show anything (except the "empty text" if I've set it). This leads me to think the facet has no items for some reason? I've tried to "add facet for missing values" or set the "minimum" to 0, but I still never get any closer... the search-view displays absolutely no results, and the facet block only displays the empty text.
If I disable that facet, then the search view returns to displaying / sorting correctly again.
What am I missing? From what I've read, facet search should be possible with this collection of modules. In fact, the demo store for commerce kickstart seems to do a pretty good job of providing the facets also. I've reviewed everything I can imagine and just can't seem to get it running for the life of me. Any pointers appreciated.
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 : 2
Story Points: 2
Comments
Comment #1
cpliakas commentedHi JemBijoux.
Facet API is simply a display layer an abstraction for interaction with the backend. Drupal Commerce = Search API, so I would start there actually performs the facet calculations.
Thanks,
Chris
Comment #2
StaceyF commentedFor anyone else having this issue, I solved this by giving the database user connected with the drupal website "CREATE TEMPORARY TABLES" permissions. Once I enabled this, everything worked properly. Hope it helps someone else!
Comment #3
user654 commented.
Comment #4
cpliakas commentedMoving to the Search API Database Search's queue.
Comment #5
user654 commented.
Comment #6
StaceyF commented@pinkonomy:
Sorry for the delay (been on holidays). Not sure if you've figured it out by now but how you'll set the "CREATE TEMPORARY TABLES" permission will depend on you are able to administer your website's database and it's users. For me, that was using the cPanel control panel that came with the hosting. The hosting company this website was using had the ability enabled for me to create database users and set their corresponding permissions (click on the the database user name assigned to the database). Your setup may be different in cPanel if that is what your hosting is using. If you are still having issues I'd recommend contacting your hosting company as they should be able to help you. If you're working locally, you can use the command line to set permissions.
I hope that helps.
Comment #7
drunken monkeyWhile I don't think we can/should do anything about this not working without the proper permission, we should still properly catch and report the exception, return the other search results normally and also note this problem in the
README.txt. Thanks for bringing it to my attention!Patch attached, please review!
Comment #8
drunken monkeyComment #9
drunken monkeyRe-rolled and committed.
Comment #12
ioannis.cherouvim commentedThanks. The title of this issue saved me after 3 hours of trying to figure out why my facets where empty.
Comment #13
drunken monkeyNeeds to be ported to D8.
Comment #14
drunken monkeyComment #15
nick_vhComment #16
dpovshed commentedComment #17
dpovshed commentedPlease take a look at the patch.
Since in the proposed solution try/catch used inside Database::getTemporaryResultsTable() function, it should cover also usage of temp tables in getAutocompleteSuggestions(), not only in getfacets().
Comment #18
nick_vhI haven't looked in to the issue yet but it looks like the original patch was much broader? For example, it also adds documentation to the readme file that we need temporary table permissions etc. Also the error message is different? If you are radically changing a patch, please add some information why and that it covers the whole use-case.
And maybe a silly question, but can we somehow test if a certain permission failed?
Comment #19
dpovshed commentedNick,
1) thanks for pointing my attention about README.txt update, I added that in next version of the patch;
2) changing error message text: maybe I was not clear, but now this can be generated not only while working with Facets;
3) lesser amount of code changed: I wrapped with try/catch only the place where we do "create temp table"; if there something wrong with query manipulations like $db_query->getExpressions() and $db_query->distinct() this IMHO not related to the ticket (but I am OK if it is better to wrap entire function context);
4) about testing - have no idea how to test this even manually :) I did not found anything related in UI. But I had generated exception and tested that current catch/watchdog_exception stores readable and informative message in log.
I'll un-assign myself from the issue in case someone with better knowledge of SearchAPI internals wants to chime in.
Comment #20
drunken monkeyThanks a lot for your work, looks good!
Just a few minor things:
Should break at as close to 80 characters as possible.
As in D7, we should just catch the
PDOExceptionhere, I'd say.Please use the same pattern as used elsewhere for
watchdog_exception()calls. (With that, the error message variable will also automatically be provided.)Please see the attache patch, which I'd call RTBC.
I don't think so, especially not in a DBMS-independent way. And I don't think it's worth it to try, just for a better error message in an edge case.
Comment #21
borisson_I agree with RTBC.
Comment #22
drunken monkeyThanks for reviewing!
Committed.
Thanks again, everyone!
Comment #25
dimr commentedI got this issue with Drupal 8.4.2, Facet dev version (released alpha-11) trying to use the "Range slider" with a Date Range field and PostgreSQL 9.6.6.
I have a view with a list of elements and a block with the facet widget "Range slider" but when I try to move the slider then I get the error:
Drupal\Core\Database\DatabaseExceptionWrapper while trying to create a temporary table: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near ")" LINE 4: ...IN ('event')) AND (t.field_date_period BETWEEN '1479917913') ^: CREATE TEMPORARY TABLE {db_temporary_1} AS SELECT DISTINCT t.item_id AS item_id FROM {search_api_db_default_index} t WHERE (t.type IN (:db_condition_placeholder_0)) AND (t.field_date_period BETWEEN :db_condition_placeholder_1); Array ( [:db_condition_placeholder_0] => event [:db_condition_placeholder_1] => 1479917913 ) in Drupal\search_api\Entity\Server->search() (line 461 of web/modules/contrib/search_api/src/Entity/Server.php).