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
Comment #1
stborchertHere is the patch.
Simply removing the line
$this->current_search = FALSE;would work also since ->current_search is not used outside this function.Comment #3
stborchertNext try ...
Comment #4
drunken monkeyYou 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.