Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've updated the search_api module to dev version, because I need the node_access check functionality. After that, when I try to search for something as anonymous user, I get the error message »Unknown field in filter clause: status.«. When I'm logged in with uid 1, everything works fine. As server type I use search_api_db and a view with FullTextSearch filter as an exposed filter in a block.
I attach an exported feature of the search server, index and view, so you can check my settings.
Comments
Comment #1
mhh CreditAttribution: mhh commentedOk, I found the reason for this error.
When you enable the Node Access alteration in the workflow tab in the Search Index settings, you also have to enable »Published« in the fields tab.
Maybe it is possible to implement some functionality, that enables the Published option automatically as soon as the Node Access alteration is enabled.
Comment #2
drunken monkeyAh, of course! Sorry, was silly to overlook that. I don't have time to look into this right now, but will think of a way to alleviate this through some notes, or even fix it automatically as you say.
Comment #3
dawehnerOne way to do it would be perhaps to set $index->options['fields']['status'] = 1 on configurationFormSubmit.
Does this make sense?
Comment #4
drunken monkeyYeah, it would probably be the best solution. The thing is hard-coded for nodes anyways, so some additional customizations don't matter, I guess. (The last key is 'indexed', not 'status', though.)
And we should also append this to the notes saying that you have to have the „Node access information“ field indexed for this to work, and likewise add it to the corresponding checks in the query alter hook.
(Oh, and fix the watchdog constant on line 1264 of search_api.module – oops!)
Comment #5
dawehnerAssign to myself, hopefully i will find time tonight.
Comment #6
dawehnerOkay here is a short patch which automatically alters the index.
Did i already said that i like the clean-code of searchapi ?
Comment #7
drunken monkeyThis goes in the right direction, but fails to check whether the Node access data alteration was enabled. Like it is, this will set the „Published“ field to „indexed“ every time the „Workflow“ form is submitted.
You'll additionally have to check whether the data alteration was previously disabled but now enabled in the form – only in this case do we automatically set the fields added by the data alteration to „indexed“ as well.
Comment #8
dawehnerThis seems to make sense, what about this patch?
Comment #9
drunken monkeyYes, quite good. However, we should also check if the field is enabled when altering the query, or the exception might still occur. Patch attached.
Comment #10
drunken monkeyComment #11
drunken monkeyComment #12
dawehnerPlease look at your patch, sure it's helpful but it doubt it can work like this ;)
Comment #13
drunken monkey:-/
Comment #14
dawehnerHere is a slighly small change with renames $f to $fields because that's a bit easier to understand.
The last change you made looks fine!
Comment #15
drunken monkeyOK, just chose
$f
so the line wouldn't be so awefully long, but I guess that's not really helping readability.Anyways, looks good to me! Anyone else want to test/review?
Comment #16
drunken monkeyOK, committed. Thanks again for you help, Daniel!