I am trying to use hook_views_query_alter, to modify an exposed filter value in a Search API Index view. It is a field collection item field. Any help in getting the query field would be welcome.

Thanks, in anticipation.

Comments

drunken monkey’s picture

Issue tags: -Search API, -#views

Use hook_search_api_views_query_alter() instead. See includes/query.inc in the Search API Views module for the definition of the views query class. $query->getSearchApiQuery() gives you the Search API query object. See includes/query.inc in the Search API module to see what you can do with that.

alamp’s picture

Here is the output of dpm ($query->getSearchApiQuery());

 ... (Object) SearchApiViewsQuery
    group_operator (String, 3 characters ) AND
    pager (NULL)
    view (NULL)
    display (NULL)
    plugin_type (String, 5 characters ) query
    plugin_name (String, 22 characters ) search_api_views_query
    options (Array, 3 elements)
    definition (Array, 10 elements)
    is_plugin (Boolean) TRUE
    base_table (String, 35 characters ) search_api_index_default_node_index
    base_field (String, 13 characters ) search_api_id
    where (Array, 1 element) 
drunken monkey’s picture

First off, this looks much more like dpm($query); If it is really dpm ($query->getSearchApiQuery());, then there is a weird bug there.

Second: What do you want to say with this? Is it good, bad, do you want help or do you want to help?

alamp’s picture

It is kind of you to correct something wrong if it is not true.

I just posted it for someone who might have an interest in the value of $query->getSearchApiQuery().

pritamprasun’s picture

How can we do groupby here like $query->add_groupby('nid'); in hook_vews_query_alter() ?

drunken monkey’s picture

Status: Active » Fixed

How can we do groupby here like $query->add_groupby('nid'); in hook_vews_query_alter() ?

It's possible to do something similar by using the Search API Grouping module (though that works globally on all searches for the index) with Solr. (Or by using the same query options manually.)
Other than that, grouping isn't supported by the Search API.

Status: Fixed » Closed (fixed)

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