开发者

Range search based on price field in drupal

开发者 https://www.devze.com 2023-01-08 01:35 出处:网络
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

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 t开发者_如何学Pythonhere a way ( amodule, etc) to create ranges out of integer values so that the user is able to perform range based search?


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消