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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mhh’s picture

Category: bug » feature

Ok, 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.

drunken monkey’s picture

Component: Database search » Framework
Issue tags: +D7 stable release blocker

Ah, 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.

dawehner’s picture

One way to do it would be perhaps to set $index->options['fields']['status'] = 1 on configurationFormSubmit.
Does this make sense?

drunken monkey’s picture

Yeah, 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!)

dawehner’s picture

Assigned: Unassigned » dawehner

Assign to myself, hopefully i will find time tonight.

dawehner’s picture

Assigned: dawehner » Unassigned
Status: Active » Needs review
FileSize
1.42 KB

Okay here is a short patch which automatically alters the index.

Did i already said that i like the clean-code of searchapi ?

drunken monkey’s picture

Status: Needs review » Needs work

This 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.

dawehner’s picture

Status: Needs work » Needs review
FileSize
1.74 KB

This seems to make sense, what about this patch?

drunken monkey’s picture

Yes, quite good. However, we should also check if the field is enabled when altering the query, or the exception might still occur. Patch attached.

drunken monkey’s picture

drunken monkey’s picture

Category: feature » bug
dawehner’s picture

Please look at your patch, sure it's helpful but it doubt it can work like this ;)

drunken monkey’s picture

dawehner’s picture

Here 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!

drunken monkey’s picture

OK, 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?

drunken monkey’s picture

Status: Needs review » Fixed

OK, committed. Thanks again for you help, Daniel!

Automatically closed -- issue fixed for 2 weeks with no activity.