I noticed a bug in the argument handler for text fields with the option widget when using value and label pairs
The handler receives the incoming argument, and checks it against the options available to the widget. If it finds it there, it then adds to the query.
However, if you have labels specified for the options, then it actually searches through the labels and therefore often returns an incorrect result.
e,g, if I set the allowed values for the field as follows
news|News Item
blog|Blog Post
I would want to use the arguments news, blog - but this would cause the argument to return an empty result since they are never even added to the query.
Here is a patch that rectifies this and searches only the option values. (it does also work if no labels are specified)
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | apachesolr_views_option_widget_handler3.patch | 3.32 KB | smoothify |
| #1 | apachesolr_views_option_widget_handler2.patch | 2.23 KB | smoothify |
| apachesolr_views_option_widget_handler.patch | 703 bytes | smoothify |
Comments
Comment #1
smoothify commentedI looked at this a bit more, when the validation of the argument against the options fails it isn't handled properly.
Right now, if it fails it doesn't return an error - it just doesn't add a filter to the query so if its your only argument you will get a full result from Solr.
I've created a new patch that moves the validation to a new function validate_argument_basic, which allows it to return FALSE if it doesn't match an allowed value. When it returns FALSE, it can then be handled in the regular views way - e.g - page not found or empty text etc.
Comment #2
smoothify commentedOne more change, I've added an option to the handler that allows you to disable the validation against the allowed values. This will allow the query to be run even if it doesn't match an option.
This could be useful if you have recently changed the allowed values, but some old records remain in the database - or if the handler is expanded to work with other widget types such as a regular text field.
Comment #3
Scott Reynolds commentedIf we are having problems validating the argument, then please create a validation handler.
What Apache Solr Search Integration version are you developing against?
Comment #4
Scott Reynolds commentedAhh nvm I get the validate_basic, no validate argument handler is needed. I like the approach, I don't like the 'only validate if the checkbox is there' though. Can explain more why you think that is necessary. Does the Standard CCK handler for option widget allow stale allowed values to 'work' ?
Comment #5
smoothify commentedFirstly, I'm developing with Apache Solr version 6.x-2.x-dev.
About the checkbox, In my use case I was thinking about expanding the handler to work with regular cck text fields as well as those with optionwidgets - but perhaps they could have their own handler.
The cck views handler (for all cck string fields) suprisingly doesn't seem to have any validation for allowed values at all. So it runs the query whatever is in the argument.
Comment #6
kenorb commentedComment #7
kenorb commentedVersion 6.x is no longer supported due to Drupal 6 End of Life. For Drupal 8.x, use Search API Solr Search instead.