apachesorl_l() is great but I have need for an apachesolr_url() equivalent.

/**
 * This is the url version of apachesolr_l
 *
 */
function apachesolr_url($path, $options = array()) {

  // Merge in defaults.
  $options += array(
    'attributes' => array(),
    'html' => FALSE,
    'query' => array(),
  );

  // Don't need this, and just to be safe.
  unset($options['attributes']['title']);
  // Double encode + characters for clean URL Apache quirks.
  if (variable_get('clean_url', '0')) {
    $path = str_replace('+', '%2B', $path);
  }

  // Retain GET parameters that ApacheSolr knows nothing about.
  $query = apachesolr_current_query();
  $get = array_diff_key($_GET, array('q' => 1, 'page' => 1), $options['query'], $query->get_url_queryvalues());
  $options['query'] += $get;

  return check_url(url($path, $options));
}

Comments

sime’s picture

Status: Active » Closed (won't fix)

I have approached the problem in a different way.

sime’s picture

Status: Closed (won't fix) » Active

LOL, again this came up so re-opening. I was building a url for a drupal_goto, I created a new SOLR query object and added the filters, then I basically reimplemented the above logic because apachesolr_l() does too much.

sime’s picture

I would modify this a bit. I think it needs to be possible to build up what is needed for a drupal_goto or #redirect on a $form, which means the path and options are separated further.

sime’s picture

Update, it appears that I can do:

// $query is the result from apachesolr_drupal_query()
$query->add_filter('some_facet', 'the value', FALSE);
$query_string = drupal_query_string_encode($query->get_url_queryvalues()); 
drupal_goto('search/node/' . $keys, $query_string);
pwolanin’s picture

Status: Active » Closed (won't fix)

6.x-2.x is unsupported