This issue is complicated to explain. But I'll do my best.
Not sure if it's a support request or a bug.

I got a seriously advanced and custom search page with facets.
On that page I do several search api queries to build my page.
Now I got the issue that the facets only appear if the index that is linked to the facets is called first.

But I need another query first, because I use that output to build a filter for the *main* query.
It's that main query that has the filters I need to show.
When debugging the query I saw the facets gets build perfectly and the facets get build but somehow they don't "popup".
I tried debugging the facet api block code but I failed.

Is this a support request? A bug? Facet api problem?

Any help would be appreciated. I can do some digging myself but I need some guidance at this moment...

Comments

aspilicious’s picture

Component: Framework » Facets
Category: Support request » Bug report
Priority: Normal » Major

A bug report for search api after all. After 6 hours of debugging I finally found the cause :D.

It's located in the search_api_facetapi module. The query type term plugin contains following logic.

  /**
   * Initializes the facet's build array.
   *
   * @return array
   *   The initialized render array.
   */
  public function build() {
    $facet = $this->adapter->getFacet($this->facet);
    // The current search per facet is stored in a static variable (during
    // initActiveFilters) so that we can retrieve it here and get the correct
    // current search for this facet.
    $search_ids = drupal_static('search_api_facetapi_active_facets', array());

    if (empty($search_ids[$facet['name']]) || !search_api_current_search($search_ids[$facet['name']])) {
      return array();
    }
    $search_id = $search_ids[$facet['name']];
    $search = search_api_current_search($search_id);
    $build = array();

I'm not sure *how* everything works but 'search_api_curent_search' always contains an array keyed as follow

SearchApiQuery
SearchApiQuery-1
SearchApiQuery-2

Search ID in my case always return "SearchApiQuery". So it alway will use the first one. In my case however the valid current search is placed second, under the key "SearchApiQuery-1".

Changing the key to SearchApiQuery-1 make my blocks appear again! :D
BUT thats just an ugly hack, is there a proper fix possible?

drunken monkey’s picture

Ah, good to hear you were able to debug this!
Before I look into it, could you just ensure that you don't have the facets configured to run for the SearchApiQuery search?
(Also, if you are programmatically executing searches, it's a good idea to always set the search id option to something meaningful, precisely for this reason. Otherwise, this will go wrong if the order of execution changes, or the third query is sometimes the only one executed.)

aspilicious’s picture

Yeah there is only one query that has facets configured.
How do I set the search ID? Can't find a method that does that.

drunken monkey’s picture

Get it with $query->getOption('search id'), set it with $query->setOption('search id').

And you are sure that in the facet display setting, you have "Display for searches" and "Search IDs" set in a way that will only activate them for the SearchApiQuery-1 ID? (You'll have to change that, of course, when you change the search IDs you are using.)

aspilicious’s picture

And you are sure that in the facet display setting, you have "Display for searches" and "Search IDs" set in a way that will only activate them for the SearchApiQuery-1 ID

Where can I find those settings? I clicked around everywhere but can't find them? Configure display doesn't show me that?

*feels he is almost there*

aspilicious’s picture

Whoaha! Setting the search_ID was enough....

o_O

Thnx!

drunken monkey’s picture

Category: Bug report » Support request
Priority: Major » Normal
Status: Active » Fixed

No problem, glad it worked.

yusufsarac’s picture

@aspilicious

Can you share your code about how you created facet blocks for your custom query page. I'm trying to make similar thing.

I have a custom query page created by apache solr module's API. I want to create custom facet blocks for that query. But I think facet API facets pull information from original "apache solr" default query.

How can I alter that ?

I asket this here and here

But no luck so far

Status: Fixed » Closed (fixed)

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