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?
Comment | File | Size | Author |
---|---|---|---|
#6 | apachesolr_views-exposed-filters-2423231-5.patch | 572 bytes | j1mb0b |
#4 | apachesolr_views-exposed-filters-2423231-2.patch | 838 bytes | j1mb0b |
Comments
Comment #1
MiroslavBanov CreditAttribution: MiroslavBanov commentedIf you find out anything do share, please :)
What I can suggest is to negate the filter for the
1
value.Comment #2
j1mb0b CreditAttribution: j1mb0b commentedI have noticed in apachesolr_views_handler_filter.inc:
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
Comment #3
MiroslavBanov CreditAttribution: MiroslavBanov commentedThis 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.
Comment #4
j1mb0b CreditAttribution: j1mb0b commentedComment #5
stefan.r CreditAttribution: stefan.r commentedMaybe we could just special case the boolean here? so !empty($this->value) || $this->value === '0'
Comment #6
j1mb0b CreditAttribution: j1mb0b as a volunteer commentedMy 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.
Comment #7
stefan.r CreditAttribution: stefan.r commentedAdding 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?
Comment #9
MiroslavBanov CreditAttribution: MiroslavBanov commentedFixed and thanks for the help.