The title may look somehow confusing so I try to explain this :)

getCurrentSearch() in SearchApiFacetapiAdapter relies on search_api_current_search() executed before with a SearchApiQuery as parameter.
If (for whatever reasons) getCurrentSearch() is called before search_api_current_search() has been called with a full query, it will always return NULL and you don't have a change to get the current search.

I know this is a rather edge case but I stumbled upon this creating breadcrumbs using facet links (with module Hansel).

Example:

<?php
// this will return NULL since there is no active search
$search = $adapter->getCurrentSearch();
// i.e search_api_views block
search_api_current_search($query->getOption('search id'), $query, $cache->data['search_api results']);
// the static $searches array is now filled ...
// but this call will return NULL again
$search = $adapter->getCurrentSearch();
?>

Simple patch follows.

Comments

stborchert’s picture

Status: Active » Needs review
StatusFileSize
new832 bytes

Here is the patch.

Simply removing the line $this->current_search = FALSE; would work also since ->current_search is not used outside this function.

Status: Needs review » Needs work

The last submitted patch, getCurrentSearch-2044711-1.patch, failed testing.

stborchert’s picture

Status: Needs work » Needs review
StatusFileSize
new722 bytes

Next try ...

drunken monkey’s picture

Status: Needs review » Fixed

You are right, that does make sense. We can't do anything about the first call returning NULL, but the second should still have a chance to retrieve the query. I think I prefer removing the $this->current_search = FALSE; line, but that's just details.
In any case, thanks a lot for your contribution! Committed.

Status: Fixed » Closed (fixed)

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