I have two exposed filters one for content and one for a boolean field. The exposed filter for content is working well.

But the boolean field is giving me trouble. Using just a text field to provide the value, when the value is "1" I see the proper entries in the apache_solr_query object and the query returns the correct results:
where[1]['conditions'][0]['field'] = "content"
where[1]['conditions'][0]['value'] = "4afrika"
where[1]['conditions'][0]['operator'] = null

where[1]['conditions'][0]['field'] = "bm_field_current_archived"
where[1]['conditions'][0]['value'] = "1"
where[1]['conditions'][0]['operator'] = "="

However, when I send "0" through the textfield, the second where condition isn't created.

I've experimented with add_filter(), add_filter_string(), injecting the value in a form submit handler earlier in the process, all to no avail. I can't seem get the zero to be converted to a valid where condition.

Can anyone shed light on what I am missing here?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MiroslavBanov’s picture

If you find out anything do share, please :)
What I can suggest is to negate the filter for the 1 value.

j1mb0b’s picture

I have noticed in apachesolr_views_handler_filter.inc:

if (!empty($this->value)) {
  if (is_array($this->value)) {
    $this->value = implode(' OR ', $this->value);
  }
  $this->query->add_where($this->options['group'], $this->real_field, $this->value, $this->operator);
}

The !empty() check will treat 0 as empty therefore it skips the filter when building the query. I think this "if" statement is unnecessary since you may want to filter on empty values.

Update:
I am using version 7.x-1.1-beta1

MiroslavBanov’s picture

This is consistent with many views filter handlers to have the !empty check. It is for example standard to have multiple select, and when the value is empty array, not to filter and to show all results, but when there is a value to filter.

Maybe what we need is a separate apachesolr_views_handler_filter_boolean.

j1mb0b’s picture

stefan.r’s picture

Category: Support request » Bug report
Priority: Normal » Major
Status: Active » Needs review
+++ b/handlers/apachesolr_views_handler_filter.inc
@@ -13,12 +13,10 @@ class apachesolr_views_handler_filter extends views_handler_filter {
-    if (!empty($this->value)) {

Maybe we could just special case the boolean here? so !empty($this->value) || $this->value === '0'

j1mb0b’s picture

My boolean field in Apache Solr is treated as a string when using as an exposed filters. I have tested this patch and it solves my issue.

stefan.r’s picture

Status: Needs review » Reviewed & tested by the community

Adding a boolean handler may be nice but I'm not sure it's needed here. As this fixes not being able to input the 0 from Solr in manual testing, I think this can just be committed as-is?

MiroslavBanov’s picture

Status: Reviewed & tested by the community » Fixed

Fixed and thanks for the help.

Status: Fixed » Closed (fixed)

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