Hi David,

A few days ago i came across your Faceted Search project while looking for a module to search CCK content. With the current version of views, it isn't possible to make "between x and y" searches for CCK integer fields, so i was looking for alternative search methods other than views. Then faceted search caught my attention, but there was a problem in my case. I have integer cck fields (for example, age) and when i used faceted search with such fields i get lots of categories (one category per number). Obviously, that would be a bad design. So instead, i thought of creating number ranges as vocabulary terms, such as 1-10, 11-20, etc. But that would mean editing all the existing nodes to add these new terms. This would be a cumbersome work if done manually so with my limited knowledge of php-mysql and drupal, i wrote a basic module, AutoTerm, to automate the process.

AutoTerm basically assigns a term to a node if a specified CCK field has a value greater than a given threshold value for that term. So, first i create the vocabulary and add some terms, then form {term, CCK field, threshold value} relations, and then run the module et voila: all the terms are assigned the appropriate terms! Now that all the existing nodes have been categorized appropriately, i am able take full advantage of faceted search.

As you can see from the code, it's poorly written. The variables are hardcoded, and they need to be edited for every vocabulary and content type. Also, there are only two options in the module administration, bulk delete and bulk create. I haven't written any drupal modules before, so i have copied some parts from the hello_world module :) But in the end, it works for me. Certainly, it would be better with some flexibility but i have neither the time nor knowledge for this. I hope this module (or at least the idea behind it) will catch your attention and will be developed further.

p.s. If needed, i may create some mockup images to better explain the functionality and use of the module.

Comments

David Lesieur’s picture

Title: An additional module suggestion » Group categories into ranges of values

This kind of grouping would be very useful indeed. We can imagine not only numerical ranges, but also date ranges, alphabetical ranges, etc.

Ideas and mockups are very much welcome!

David Lesieur’s picture

See also this other request for more examples of use.

drupaloSa’s picture

In my opinion, we need an interface where we could define rules to be processed. Each rule needs to be composed of four basic parts:

- a content type (choosable from a list of all available types),
- a CCK field (choosable from a list of all available fields),
- a vocabulary term (choosable from a list of all available terms),
- and a condition that will be used for the IF check

Condition also needs to be composed two parts (or ANDed sets of these two parts):

- Type (exact match, contains, in the range of, GT, LT, isempty, etc.)
- Value (integer, date, etc. which will be entered by the user)

Using this interface, we can define a rule as follows:

- Content Type: Product
- CCK Field: field_price
- Term: €10-100
- Condition: (Range, [10,100])

After defining the rule, it will be fired and all the nodes of product type having a price between €10 and €100 will be tagged as €10-100.

You should be able to define as many rules as you want, and fire them independently. Also there should be a way to revert fired rules, by deleting all the related term_data table entries.

asak’s picture

And possibly adding that as an Action the be fired automatically when a node of that type is created/updated.

mooffie’s picture

I've just finished writing a module (a little package of modules, actually) to do this. Not that I needed it: I did it for fun. I fell in love with this "faceted search" concept a few days ago and looked for a little something to do. Is there still interest in this?

David, I'm impressed with the quality of your code.

asak’s picture

@mooffie - In one word - Yes!

What i'm using now is an extra field, as i described here, which acts as the group.

Does your module automatically assign the term as nodes are created/updated? or must one "fire" an action/rule for a mass-update?

Some info about how your module works will be great... and i'll happily test it in any case ;)

drupaloSa’s picture

I'm still interested :)

crow_gl’s picture

May be you can resolve this problem with the help of URL-based arguments in Faceted Search's VIEW (http://drupal.org/node/236162).

David Lesieur’s picture

@mooffie: Does your system require any change in Faceted Search itself? How about putting your package in a sandbox on drupal.org's CVS repository? Or if you are confident about it, you could even create a full-blown project on drupal.org. ;)

mooffie’s picture

(I'll put the package tomorrow in my sandbox. Things will be clear by then, asak. David: no, it doesn't require any change in Faceted Search itself.)

mooffie’s picture

Ok, the package is now in the sandbox.

You can view the RAEDME.txt here

You can download the package by doing:

cvs -d :pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib co -d fsrange contributions/sandbox/mooffie/fsrange

This will download it into a 'fsrange' folder.

You must use a recent 'dev' version of Faceted Search or else you'll see complaints about missing 'faceted_search_quoted_query_extract()'.

To wet your appetite, here's how ranges are defined in a settings page:

0..10        | Cheap ($0 to $10)
  0..1]      | Dirt cheap (1 dollar or less)
10..80       | Medium ($10 to $80)
80..inf      | Expensive ($80 and up)
  1000..inf  | Really expensive ($1000 and up)
  10000..inf | Really really expensive ($10,000 and up)
mooffie’s picture

Now, the main problem with my package is that the user himself is not free to specify his own range. He can't ask to see all products ranging from, say, $45 to $68. He must use the pre-defined ranges.

That's not quite what I had in mind when I started with this. What I had in my mind is: histograms. It seems off-topic, so let me explain:

'facetmap.com' has a faceted search demonstration on their site. You'll notice the graphic widget they have for choosing prices:

Only local images are allowed.

There's only one problem with this widget: it's almost completely useless. Imagine how useful it'd be if it showed a histogram in the background:

Only local images are allowed.

(I did that with a paint program.)

The histogram shows the number of nodes found for each value. It's not useful just for 'prices'. It can be most useful for dates. Perhaps I'll be working on this.

David Lesieur’s picture

asak’s picture

Is this going anywhere?

asak’s picture

@mooffie: Timeline project seems like it's going that direction. it's nice. http://drupal.org/project/timeline

I'm using somthing close (but not optimal) with a patched exposed view filter - http://drupal.org/node/151989#comment-569848.

asak’s picture

This worked for me before, but now I tried to install fsrange on another site, and i'm getting the follwoing error after enabling the modules:

Fatal error: Class 'fsrange_handler' not found in /home/.../sites/all/modules/fsrange/fsrange_basic_handler.inc on line 11

Jurgen8en’s picture

Hi,

I installed this module. It looks fine. (Drupal 5.2)
I use ubercart, how did I get 'sell price' be recognized as a numeric field?

Best Regards,

Jurgen
www.iGadgets.be

Jurgen8en’s picture

This function must be extended?

function fsrange_number_fsrange_fields() {

with..

$field['field_name'] = 'sell_price';
      $db_info = content_database_info($field);
      $fields[$field['field_name']] = array(
        'table' => $db_info['table'],
        'field' => $db_info['columns']['value']['column'],
        'handler' => 'fsrange_number_handler',
        'cck_fieldname' => $field['field_name'],
        'label' => $field['widget']['label'] .' ('. $field['field_name'] .')',
        'group' => t('Numeric fields'),
      );
  

Then I got the error:
user warning: Table 'igadgets_test.faceted_search_facets' doesn't exist query: SELECT env_id FROM faceted_search_facets WHERE facet_key = 'range_1_sell_price' AND status = 1 in /usr/local/psa/home/vhosts/igadgets.be/httpdocs/includes/database.mysql.inc on line 172.

asak’s picture

Just tried this code again - but i'm getting the same error as I did before (comment #16).

FIX: Seems you must first install the 2 basic modules, and only then install the textual/numeric/etc. modules.

QUESTION: after succesfully installing the module set, and defining a range, i get this error (same as above):

user warning: Table 'something_some.faceted_search_facets' doesn't exist query: SELECT env_id FROM faceted_search_facets WHERE facet_key = 'range_1_field_p_size' AND status = 1 in /home/.../public_html/includes/database.mysql.inc on line 174.

Any idea where/why this is comming from?

asak’s picture

Looking into the database, I can see that the table 'faceted_search_facets' really doesn't exist. furthermore, i see this could be the 'faceted_search_filters' for it's looking for stuff that's in there.

I tried to mess with the module file, changed instances of _facets to _filters , now i get no errors - but i can't see the new range facet in the faceted environment settings...

Helo... please... thanks!

asak’s picture

Ok, can't get this to work.

Just tried uninstalling faceted search entirly, reinstalling, reinstalling fsrange, created a range - but can't see it in the available facetes so that i'll be able to add it to an enviroment.

Any ideas?

mooffie’s picture

Just tried this code again - but I'm getting the same error

Asaf, I wrote that package many many months ago. Faceted Search was in 'alpha' stage then. Several things have changed in it during these months, so the package is no longer compatible with it. Unfortunately, I can't run Drupal nowadays, so I can't update the package.

asak’s picture

Ohh that's such a shame (both the package issue and the fact you can't run Drupal)...

Seems there are 3 options then:

1. Trying to fix what was working...
2. Finding a way to use computed fields (which will check and store the ranges automaticaly) as facets
3. Check out if "that other" faceted search module could be of more use in this case...
4. Finding a way to systematically attach terms (ranges) to nodes based on ... something ... i would like this to work with CCK and Ubercart so this could be more of a problem.

Ranges of values are such a beauty - real estate, e-commerce, e-papers and archives - all would really enjoy a range based faceted search.

Is there some other solution out there which i'm missing...?

;)

asak’s picture

Ok - this may be a super-hack but from a little testing this actually works:

I want to group products prices from Ubercart. I've got the price at $node->sell_price. I create two fielde:
1. A text field (so that faceted search will be able to make it into a facet)
2. A computed field

I don't know how "legal" this is, but by placing a code like:
$node->field_my_text_field[0]['value'] = $node->sell_price;
In the computed field php code box, I can get the price in the text field - which means i can now use it with faceted search!

The only thing left is using some simple php to check what range that price is in, so that it's saved in the text field.

So - is it ok to use a computed field in such a way? would it be possible to skip the computed field and use the php code box of the first field?

Now, maybe, I could use a cck -> taxonomy field of some kind instead of the text field to save ranges and sub-ranges as terms and children terms (?!)

Anyway, this looks good. it's strange - but it's gonna work.

dillonm’s picture

Any change of this making it in the next version of the module?

lavanyadotr’s picture

Hi,

Is there any Slider like widgets apply for individual facets, So that i can show in a SlIDER format instead Showing in a LIST.

bbence’s picture

Hi David,

First of all, thank for the great module! It really does improve the user experience of serching.
However I'm also looking for a way to integrate a range facet, because I'm doing a site where I have multiple number type fields which would be much more sensible in a range facet instead of showing the top 10 distinct values.

Any chances of reviewing mooffie-s modules and integrate that functionality to faceted search? I will have a go at it today, but I have limited drupal development experience, so I'm not sure how far I can get.

Thanks in advance!

Best wishes,
Bence

Attila’s picture

Is there any chance that there will be a 6.x version of your module pack, mooffie?