Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I am trying to load full facet blocks on non search page to put them in cache.

What I am doing is looping through items with taxonomy $tid, then

$params = array('fq' => 'tid:' . $tid);
$current_query = apachesolr_drupal_query('apachesolr', $params, '', 'search/site');
$response = apachesolr_do_query($current_query);
$facet_block = module_invoke('facetapi', 'block_view', $block_id);

When I dsm $response->request, on each iteration I always see the first $tid in the query string ("q.alt=tid..."). The result I get is the same block for every terms, on each apachesolr_do_query requests.

Anyone got a clue on what is going on there ? The purpose of this is to generate cached facet blocks from non search pages, for several tid as the apache solr search parameter.

share|improve this question

1 Answer

up vote 1 down vote accepted

The problem is, apachesolr_do_query checks if a query has already been made:

apachesolr.module line 1470 :

  // Verify if this query was already executed in the same page load
  if ($response = apachesolr_static_response_cache($searcher)) {
    // Return cached query object
    return array($query, $response);
  }

So, all you have to do to process multiple ApacheSolr queries is to reset the Drupal static variable like so:

drupal_static_reset('apachesolr_static_response_cache');
share|improve this answer
 
Awesome, really useful to know that thanks –  Clive Jun 11 at 11:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.