Hi,
The script parseFloat(eval(doc['catSequences'].value)[categoryId])
takes the value of catSequences for the product:
({76715:373.0,48124:141.0,76704:62.0,48122:325.0,76710:21.0})
and evals it so that we can index the object by the currently selected
categoryId. This gives us a value for the score. 62.0 when categoryId
is set to 76704
Life would be so much simpler if a product only existed in a single
category or the display order was not determined by the category!
Extracting the score value may be faster using string parsing rather
than eval, I have not tested this yet. Still pretty much prototyping.
We already use sorting on multiple fields, once the category entries
are beyond the first few pages there is no position set so we sort the
rest by best selling.
The problem with groovy is I get the error [script_lang not supported
[groovy]] when I set "lang" : "groovy". It looks like the plugin has
installed correctly, I have a lang-groovy directory in plugins which
contains the two jars. Haven't spent too much time looking into this
yet.
On Dec 1, 12:43 am, Shay Banon shay.ba...@elasticsearch.com wrote:
I think I understand, not sure I understand the script though (maybe gmail
garbled it up). What was the problem with groovy?
Also, you can sort on several fields, not just one, maybe that would help as
well?
On Wed, Dec 1, 2010 at 12:33 AM, Timber tim.berke...@gmail.com wrote:
Hi Shay,
I am trying too allow the products in each of our categories to be
ordered in a category specific order. The first page of two of
products in each category browsed are to be displayed in an order
determined by our marketing team. When a search term is used we just
use relevance.
The catSequences field is indexed as "catSequences":
"({76715:373.0,48124:141.0,76704:62.0,48122:325.0,76710:21.0})" which
puts each product in an ordered position in the category. This is
obviously a sparse mapping.
On a side note I had no luck using groovy as the scripting language.
Thanks
Tim
On Nov 30, 9:25 pm, Shay Banon shay.ba...@elasticsearch.com wrote:
Hi,
Great that its working. I am not sure I got the script you are
executing,
what are you trying to do? (just want to see if it can be optimized).
On Tue, Nov 30, 2010 at 3:08 PM, Clinton Gormley <
clin...@iannounce.co.uk>wrote:
On Tue, 2010-11-30 at 04:45 -0800, Timber wrote:
Thanks for pointing that out. The query is now working fine
You can reduce that further to this:
"query" : {
"custom_score" : {
"query" : {
"bool" : {
"must_not" : {
"term" : {
"group.vip" : "T"
}
},
"must" : {
"term" : {
"category.pathIds" : "77705"
}
}
}
},
"script" :
"parseFloat(eval(doc['catSequences'].value)[categoryId])",
"params" : {
"categoryId" : 77705
},
"lang" : "js"
}
}
clint