Score feature
vincent opened this issue · comments
Hi, thank you for this library, love it.
My specific requirement is to find the "best match" ; that is a kind of score, to find the item matching the most query statements.
An advanced version could allow a "boost" keyword in some statements of a query.
Do you think it's a realistic feature to ask ? I understand it needs quite a big change.
If you're not interested to do it, could you point me some tips about how could I do it ?
Cheers
Hi, thanks for the comment. It sounds like an interesting feature. Please can you give an example with sample data and the type of result you would like
The idea is to have a kind-of should Elasticsearch query.
Here's an example of what I mean: https://gist.github.com/vincent/3a86441354458b7acaa3
In my personal requirement, I just need the best result, with or without the _score
metadata
@vincent please try out the score api in the above commit.
it "has a score method with a $boost operator", ->
collection = [
{ name:'dress', color:'red', price:100 }
{ name:'shoes', color:'black', price:120 }
{ name:'jacket', color:'blue', price:150 }
]
results = _.query.score( collection, { price: 100, color: {$in:['black'], $boost:3 }})
assert.equal _.findWhere(results, {name:'dress'})._score, 0.5
assert.equal _.findWhere(results, {name:'shoes'})._score, 1.5
awesome, thank you !
I'll try this asap.