I have created a views filter handler that extends apachesolr_views allowing it to filter results by numeric fields. To use this you must already have numeric fields in the solr index. The fields must be of type: 'number_decimal', 'number_float', 'formatted_decimal' or 'formatted_float'.

What this provides:
- Allows admins to build views that restrict search results by numeric fields
- Includes all operators <, <=, =, !=, >=, >, between, not between
- Allows admins to expose the filter so that end user can input values to limit results
- Form values can be optional
- Form values validated numeric

e.g. You can create an exposed filter for Car Horsepower using between operator. This provides the end user with a form where they can specify the minimum and maximum horsepower. If maximum value is omitted then it will return all results that are greater than the minimum (and vice versa for omitted minimum).

Tested all operators on all field types. I have been using this for months but only had time to build patch now. Would appreciate if this could be included into dev.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tinker’s picture

Remove .txt extension from apachesolr_views_handler_filter_numeric.inc.txt (can't attach .inc file)

BTW this also extends the numeric argument handler to use more numeric fields.

rjbrown99’s picture

tinker’s picture

No this is not a duplicate. The post you mention exposes the fields for display in views but does not provide a handler to filter the results or expose filters so that user's can search numeric fields.

The only thing it changes in existing Apache Solr View code is extending types to include 'number_float', 'formatted_decimal', 'formatted_float'. The filter handler is all new functionality.

rjbrown99’s picture

Thanks for this, had a use for it and it works beautifully. Just a note to others - I had to index fields as tis* and not is* to make the ranges work correctly. If you are having problems try using a tis field.