On a Search API index view, I have an "addressfield" (via the Address Field module) and normal field api fields. Some Addressfields with "Selective" work, and others don't.

For example, if I add "Locality (Selective)", it works, but not when I add "Country (Selective)". The following error message is shown:

Fatal error: Call to protected method SearchApiViewsHandlerFilterOptions::get_value_options() from context 'views_handler_filter_selective' in /var/aegir/platforms/panopoly-7.x-1.25/sites/hub/modules/views_selective_filters/views_handler_filter_selective.inc on line 487

I can't say what is the culprit in this case, since other fields within the Search API indexed view work without issues, and other Addressfields within the view work as well.

Thanks in advanced for your help.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

NWOM created an issue. See original summary.

david_garcia’s picture

Title: Adding Selective Country Addressfield indexed with search api results in error » Support Search API index country field
Category: Bug report » Feature request
Priority: Major » Normal
NWOM’s picture

Oh thanks. Hadn't realized it was a feature request.

Alex Bukach’s picture

Status: Active » Needs review
FileSize
723 bytes

Basically that method is not guaranteed to be public, so that the module should check whether it can call it (see the patch attached). On the other side, for Search API to work with the module that method should be public on Search API side (see the patch at https://www.drupal.org/node/2352853).

david_garcia’s picture

Status: Needs review » Closed (fixed)

Commited.

Thanks for the patch.

Alex Bukach’s picture

Status: Closed (fixed) » Closed (won't fix)

Just to make it clear, this patch was worth applying (since just existing of a method doesn't mean this method is callable), however it doesn't fix the original issue.

Unfortunately I have to state that Views Selective Filters module is generally not compatible with Search API Views in its current form, and it is compatible only with views making SQL request (since Search API Views can make e.g. Solr requests instead etc. depending on Search API server type).

david_garcia’s picture

Given that the module is internally relying on cloning the original view I can't see why it cannot be made on anything that works as a view such as Search API. That is why I built it that way to prevent dependency on anything behind Views. Probably someome with time/budget can make it work withou too much hassle.

But yes the patch was worth applying :)

Alex Bukach’s picture

David, the problem is that class SearchApiViewsHandlerFilter extends views_handler_filter, and class views_handler_filter_selective extends views_handler_filter_in_operator. In its turn views_handler_filter_in_operator class relies on SQL, in particular on using $this->query->add_where() method which is not available for SearchApiViewsHandlerFilter. Therefore attempt of views_handler_filter_in_operator class to call that method on SearchApiViewsHandlerFilter throws an error. To fix it we should either add add_where() method to all Search API query classes, or make views_handler_filter_in_operator extend generic views_handler_filter class and implement all methods without any proposal about view storage engine.

By previous comment I meant that the fact that the module doesn't work with Search API views is not a bug, the module is not intended to work with Search API as it is now.

NWOM’s picture

Should we set this back to "Active" then, since the original feature request has not been committed?

geek-merlin’s picture

Title: Support Search API index country field » Support Search API views
Status: Closed (won't fix) » Active

Although this might not be easy, it's a reasonable feature request.

pierostz’s picture

Hello guys,

I am jumping in just to clarify things for others and me.

As I can understand Search API and Views Selective Filters are not working together. So a feature request was opened and no changes were committed yet but is this discussion a workaround? Meaning.

To get this to work we need two patches
1. The patch provided here for the Views Selective Filter.
2. And this patch for the Search API part.

Am I reading through correctly?

david_garcia’s picture

To get this to work we need two patches
1. The patch provided here for the Views Selective Filter.
2. And this patch for the Search API part.

Am I reading through correctly?

Wrong. To get this to work, you need to someone to properly work on it and then share.

From #7

Unfortunately I have to state that Views Selective Filters module is generally not compatible with Search API Views in its current form, and it is compatible only with views making SQL request (since Search API Views can make e.g. Solr requests instead etc. depending on Search API server type).

Considering that we build on top of the Views abstraction layer, unless someone comes with a specific issue - such as underlying storage not supporting aggregation -, I can't see why this won't work with the Search API.

pierostz’s picture

Thanks for the quick reply david_garsia.

Please excuse my ignorance on the subject but can you elaborate on this one.

My situation is not like the issue at hand. It's much simpler. I have a Search API index and with that I index taxonomy terms. In my view I am populating a field with those terms and then I create a selective filter based on that field. The selective filter comes empty.

Considering that we build on top of the Views abstraction layer, unless someone comes with a specific issue - such as underlying storage not supporting aggregation -, I can't see why this won't work with the Search API.

Based on your statement above such a simple scenario works or not? If it's not working is this a bug or a feature? And also If is a bug or a feature do I open another issue?

Thanks

ccjjmartin’s picture

Throwing up a patch that solved this issue for my exact needs:
1) Patch is based off version 1.5
2) Allows integration with taxonomy terms and search api

If those are your only needs then you can probably apply the patch and it will start working.

I am putting up an incomplete patch because I almost gave up at some point through this because of the issue previously mentioned about the add_where() method missing. This patch still needs:

1) Further testing to verify it doesn't break existing views selective filters
2) To remove the reliance on the selective filter being tied to taxonomy terms (left a @todo code comment)
3) A possible refactor to replace most of this with a new views handler and some code in views_data_alter

Hope this gives the next person to come across this a jump start.

bmcclure’s picture

Here is a slight refactor and reroll against the latest dev of the last patch. I think it addresses item (2) from the list in the last comment in being more generic.

However, it still doesn't work for me, because I think that this assumes the field being loaded is on the main entity in the search index, when in fact it could be on a related entity of a different type. I'm not sure if that's the only issue or not, but I figured I would post an updated version of the last patch in case it helps anyone else in the meantime.