Hi there,
I'm trying to index the Money module (a CCK field for amount+currency). Next I want to filter the data by a range, e.g. 10 < price < 1000. Ultimately I want to provide 2 blocks, one price range block for amount, another filter block for currency.
As I'm trying to build this, I'll document my steps and perhaps people can help out.
Step 1. Money module
---------------------
http://drupal.org/project/money
The module allows to store two values, and multiple values are allowed, like this:
$node->field_money[] = array('amount' => '10.00', 'currency' => 'EUR');
$node->field_money[] = array('amount' => '12.0000', 'currency' => 'USD');
The accuracy of the amount is currency-specific(!). E.g. it could have 2,3,4 or more decimals after the point. The money module handles this.
Learning from #283859: How to define addtional fields in schema.xml?, this is my best guess to setup the dynamic index, in my custom.module:
function custom_apachesolr_update_index(&$document, $node, $namespace) {
$key = apachesolr_index_key(array('index_type' => 'double', 'multiple' => TRUE, 'name' => 'field_money_amount'));
$document->{$key} = $node->field_money[0]['amount'];
$key = apachesolr_index_key(array('index_type' => 'string', 'multiple' => TRUE, 'name' => 'field_money_currency'));
$document->{$key} = $node->field_money[0]['currency'];
}
I'm not sure if this is the correct start. And I'm not sure how to handle multiple values either. As you can see, I am using two field names, _amount and _currency.
(to be continued)
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | apachesolr_money_v2.zip | 2.4 KB | Anonymous (not verified) |
| #2 | apachesolr_money.zip | 1.76 KB | Anonymous (not verified) |
Comments
Comment #1
Anonymous (not verified) commentedStep 2. ND Search, from the Node Display / Display Suite
-------------------------------------------------------
We need to index the money CCK field. I borrowed code from the ND Search modules from the Display Suite module.
I adapted their approach to get the right values from the Money CCK field, in a custom.module:
The following part detects the money field type, as called above:
Finally, you need your callbacks to map the actual amount and currency.
-------
With all this code in place I get a first result! I can go to /admin/reports/apachesolr and see for instance that
ps_field_money_amountexists and is indexed. In my case 150 unique values. Perfect.But the Facet Block does not work, it shows one facet with "Missing this field (150)". So, next step (tomorrow or later) will be to fix the block, to get it to read data from the new field_money_amount index.
Comment #2
Anonymous (not verified) commentedHere's my first result as a contrib module. So far it correctly indexes the Money CCK fields of choice, you can select the filters on admin/settings/apachesolr/enabled-filters in the fieldset "Apache Solr Money". For each CCK field there are two options: Field (Amount) and Field (Currency).
To do:
- create filter blocks (I'm not sure why they aren't created automatically)
- create price range filter (min < price < max)
P.S. At the top of apachesolr_money.module you'll see:
This is a custom sort implementation, I hardcoded my CCK field Solr index name "ps_field_product_price". You should change this to get sorting to work.
I'd like it if someone else had a look at it. And I really need help creating the "Price Range" facet block.
Comment #3
Anonymous (not verified) commentedJust for reference, the final idea is to create a price range filter like on http://www.thefind.com/search?query=drupal (top right "Prices").
Comment #4
Anonymous (not verified) commentedUpdate: the attached contrib module now shows the Filter Blocks, Amount and Currency, for each enabled money CCK facet. Also sorting by price is no longer hard-coded.
Comment #5
yeeloon commentedhi there,
do you have a demo site set-up for this module?
Comment #6
Anonymous (not verified) commentedYeah now I do,
http://www.icescan.com/s/Query
See the money slider in the top right. It pulls the min/max for the current search from solr, so the slider is always "most relevant" to your query. It's built with regular jQUery 1.2x / 1.3x "slider" plugin, from the jquery.ui.
Comment #7
Operations-1 commentedHello morningtime. I'm developing almost the exact same system as you, but for the brazilian market so, no competition :). Very nice what you did with the price range! I can see that you really know what you are doing! Can you specify better how did you achieve this price range facet with solr? Can you give a more step-by-step instructions? Or at least point me to the right direction?
Thanks
Comment #8
Anonymous (not verified) commented@Operations,
we will compete then, because I will also target Brazil.
But when I'm done, I will release my system as a Drupal installation profile. This may take about 12 months though, because I have to focus on building my business first.
Comment #9
Anonymous (not verified) commentedClosing this, I fixed my issues with a custom solution.
Comment #10
Anonymous (not verified) commentedI now published my solution as a module, Apache Solr Money Slider,
http://drupal.org/project/apachesolr_money