I have solr working but now I want to include a facet to filter by price. How is that possible?

Comments

pahariwalla’s picture

A facet will be created automatically for

  • each taxonomy Category
  • each CCK field that has "options widgets (facets don't make sense otherwise), or fields that have specific mappings." (as per docs in apachesolr.module).

Each facet will be represented by a block, so you must enable that block in admin/build/blocks jn order to see it on your search results.

It sounds like Price is not a "select value" type of field, so it won't generate a facet. You would probably want to have a "Price Range" field of type "Select" or "Radio" and that will produce a facet. An alternative would be a Category called "Price Range" with terms for each range.

Hope this helps.

nquery’s picture

pahariwalla,
Yes, that helped. Thank you.

I guess what really stumped me was:

"each CCK field that has "options widgets (facets don't make sense otherwise), or fields that have specific mappings."

There is a bug (5.x-1.x-dev) which prevents mapped CCK fields (non-options) from being faceted.

In apachesolr.module this offending line:
if (($row->type == 'text' && in_array($row->widget_type, array('options_select', 'options_buttons'))) || in_array($row->type, array_keys($mappings))) {

Should be changed so that it looks like:
if (($row->type == 'text' && in_array($row->widget_type, array('options_select', 'options_buttons'))) || in_array($row->field_name, array_keys($mappings))) {

Otherwise the mapped fields will never be applied!

asak’s picture

Might be a stupid question but... What's a non-option mapped CCK field?

pahariwalla’s picture

@nquery, @asak

I believe a "non-option mapped" field is one where there could be an unlimited number of values entered, , i.e. a free form text field.

e.g. Your Dog's Name could end up with thousands of values.

I think the reason for excluding these is because the facet block for "Your Dog's Name" would contain thousands of "filter by" entries. An interesting idea for CCK would be to add a functions that maintains a "range" field along with free text fields.

For instance, in relation to @nquery's original question, this cool function would hook into nodeapi 'update', automatically look for the min and max of Price, and adjust the associated "Price Range" field, spreading the choices into, say 10 ranges...

Have fun !

JacobSingh’s picture

Status: Active » Closed (fixed)