Score based on integer value


(Chris Yuska) #1

I've searched and I can't seem to find anyone else asking this sort of
question. I have many Person objects that are searchable by name and
should be scored by name match and number of mutual friends. Saying I have
two people in my search results for "Chris":

person_id: 1
name: Chris Foo
friends:
id: 3
mutual_friends: 4
...
person_id: 2
name: Chris Bar
friends:
id: 3
mutual_friends: 6
...

How can I score the person 2 higher than person 1 based on the integer
value of mutual_friends? Note that I don't want to strictly sort based on
this number; I just want it to boost the overall score. I know I could do
something hacky like:

person_id: 1
name: Chris Foo
friends: [3, 3, 3, 3, ...]
person_id: 2
name: Chris Bar
friends: [3, 3, 3, 3, 3, 3, ...]

and the frequency of the friend_id would cause a boost, but surely there's
a better way..?

--


(David Pilato) #2

Did you look at custom scoring ?
I think it could help you even if I didn't use it myself.

http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query.html

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 31 août 2012 à 19:48, Chris Yuska chrisyuska@gmail.com a écrit :

I've searched and I can't seem to find anyone else asking this sort of question. I have many Person objects that are searchable by name and should be scored by name match and number of mutual friends. Saying I have two people in my search results for "Chris":

person_id: 1
name: Chris Foo
friends:
id: 3
mutual_friends: 4
...
person_id: 2
name: Chris Bar
friends:
id: 3
mutual_friends: 6
...

How can I score the person 2 higher than person 1 based on the integer value of mutual_friends? Note that I don't want to strictly sort based on this number; I just want it to boost the overall score. I know I could do something hacky like:

person_id: 1
name: Chris Foo
friends: [3, 3, 3, 3, ...]
person_id: 2
name: Chris Bar
friends: [3, 3, 3, 3, 3, 3, ...]

and the frequency of the friend_id would cause a boost, but surely there's a better way..?

--


(Chris Yuska) #3

I have, but I'm a little unsure of how it works exactly. Does it not
determine the score for the whole search? I'm actually matching on a slew
of other fields, but I left them out to simplify this post. It would be a
headache creating a custom score based on all of those fields as well. Or
am I misunderstanding custom_score and I can limit it to customizing the
score of just that field?

On Friday, August 31, 2012 2:13:23 PM UTC-4, David Pilato wrote:

Did you look at custom scoring ?
I think it could help you even if I didn't use it myself.

http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query.html

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 31 août 2012 à 19:48, Chris Yuska <chris...@gmail.com <javascript:>> a
écrit :

I've searched and I can't seem to find anyone else asking this sort of
question. I have many Person objects that are searchable by name and
should be scored by name match and number of mutual friends. Saying I have
two people in my search results for "Chris":

person_id: 1
name: Chris Foo
friends:
id: 3
mutual_friends: 4
...
person_id: 2
name: Chris Bar
friends:
id: 3
mutual_friends: 6
...

How can I score the person 2 higher than person 1 based on the integer
value of mutual_friends? Note that I don't want to strictly sort based on
this number; I just want it to boost the overall score. I know I could do
something hacky like:

person_id: 1
name: Chris Foo
friends: [3, 3, 3, 3, ...]
person_id: 2
name: Chris Bar
friends: [3, 3, 3, 3, 3, 3, ...]

and the frequency of the friend_id would cause a boost, but surely there's
a better way..?

--

--


(phill) #4

Any type o f query combined with another in a boolQuery and that part
of the expression boosted separately.

On 8/31/2012 12:56 PM, Chris Yuska wrote:

I have, but I'm a little unsure of how it works exactly. Does it not
determine the score for the whole search? I'm actually matching on a
slew of other fields, but I left them out to simplify this post. It
would be a headache creating a custom score based on all of those
fields as well. Or am I misunderstanding custom_score and I can limit
it to customizing the score of just that field?

--


(system) #5