views:

50

answers:

3

I have a CCK field price which the user can fill in. I would like to create a search form with dropdown price field with different ranges (such as below 100$, 100$-1000$, more than 1000$). The problem is that the user input is an integer so I cannot achieve range search using filter exposure. The user would have to specify the exact value to perform searching, but this is rather useless. Is there a way ( amodule, etc) to create ranges out of integer values so that the user is able to perform range based search?

+1  A: 

The way I did it in the past was to use hook_form_alter to change that field to a select drop down range (a min and max drop down), then alter the views query if a value was provided.

The other way to do ranged facets would be to explore Apache Solr integration or Search Lucene facets. Keep in mind that its not exactly plug n play tech, though.

Kevin
Thanks, that's one thing that should be implemented in Drupal in the future. Did you use any tutorial for your solution?
Vafello
No I don't have a write up w code sorry. Take a look at hook_form_alter and $view->build_query using the Views API hooks. http://views2.logrus.com/doc/html/group__views__hooks.html
Kevin
+1  A: 

Obviously people grab views and CCK for most solutions. But often a small module sith just a hook_menu(), a calback and a theme function will suffice. In that callback you can perform whatever complex query you want.

Such modules, most of the time, contain less then 100 lines of PHP.

If you know PHP such a functionality might take you less then an hour to build. Whereas writing addons and behaviours for CCK and Views often costs much more. The advantage of building views and CCK addons, is that your code is better re-usable.

berkes
A: 

To sort out out your price into various categories you need to create a CCK Select list and then populate the list automatically using the Rules module. You need to also hide this select list using content permissions.

I've created a mini-case study on graphing using Rules & Views. As part of the mini case study, it shows you how to categorize the cost field using Rules -- which is precisely what you want. It also shows you how to hide the field using content permissions. Please check the below link for a video:

http://www.noparrots.com/content/mini-case-study-creating-a-bar-chart-in-drupal

Sid NoParrots

related questions