I have an apachesolr_view with a "Apache Solr: Search" exposed filter which allows searching by keywords.

Problem is the link to remove a keyword in the "current search" block is incorrect: the keyword is still present in the link.

I found that the reason is that function apachesolr_search_currentsearch_block (in apachesolr_search.module) calls $query->get_path('') with a blank string to remove the existing keys. Problem is that apachesolr_views implementation of get_path() (in apachesolr_views_query.inc) has the following code that ignores any empty parameter, hence does not remove the keys because "empty" returns false on a blank string:

if (!empty($new_keys)) {
   $this->set_query($new_keys);
}

So I patched the code by replacing empty with is_null and now the removal links are properly created.

if (!is_null($new_keys)) {
   $this->set_query($new_keys);
}
CommentFileSizeAuthor
apachesolr_views_get_path.patch739 bytesdawansv
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ptrl’s picture

Status: Needs review » Needs work

If you remove a search term from the current search the text also gets removed. The text should remain but the term should only be removed.

dawansv’s picture

Hmmm not sure which one should be the expected behavior (clearing or no clearing). Clearing is also the behavior in the /search/apachesolr_search interface: text box gets cleared when you remove the search term.

ptrl’s picture

Checked the default Apache Solr vs this and it doesn't look like it works the same.

For example I have search on word and term

[x] Word
[x] Term

If I uncheck Word or Term in default apache solr (6-2.x) the other search string remains. But if I do this in apache solr views with this patch and uncheck Term the word also gets cleared.

dawansv’s picture

Oh sorry I didn't understand your first post then. I thought you meant the word got cleared in the search box when unchecking the word... Now I understand you meant when unchecking the term... I confirm this and, yes, that's definitely a bug...

nadu’s picture

Status: Needs work » Needs review

In function apachesolr_search_currentsearch_block() of apachesolr_search.module, I changed

$links[] = theme('apachesolr_unclick_link', $keys, $query->get_path(''), array('query' => $query->get_url_queryvalues()));

to:

$links[] = theme('apachesolr_unclick_link', $keys, $query->get_path(''));

and it works.

ckng’s picture

Consider proposed solutions so far are all hacks.
Here's my version of 'hack', hope it can give an idea to a proper solution.

<?php
function mytheme_apachesolr_unclick_link($facet_text, $path, $options = array()) {
  apachesolr_js();

  // handle unclick of apachesolr_views exposed text filter
  if (isset($options['query']['text']) && $options['query']['text'] == $facet_text) {
    $options['query']['text'] = '';
  }
  if (empty($options['html'])) {
    $facet_text = check_plain(html_entity_decode($facet_text));
  }
  else {
    // Don't pass this option as TRUE into apachesolr_l().
    unset($options['html']);
  }
  $options['attributes']['class'] = 'apachesolr-unclick';
  return apachesolr_l("(-)", $path, $options) . ' '. $facet_text;
}
?>