Tire: Document boost / "Not in" syntax


(Elad Ossadon) #1

2 questions:

  1. With Sunspot I could have a boost command and add score to a document
    based on a calculation

searchable do
...
boost { popularity * 0.1 }
end

this would boost an instance based on a numeric fields named popularity.

How do I implement it with Tire?

  1. How do I exclude results that match one value of a list? Let's say I
    want to exclude all documents with a field id is 1 or 2 or 3. (Like SQL's
    WHERE id NOT IN (1,2,3))

--


(Karel Minarik) #2

Ad 1/, you can use a custom_score_query, providing it a script.
See https://github.com/karmi/tire/blob/master/test/integration/custom_score_queries_test.rb#L29-45
for example code.

Ad 2/, it depends a bit on context, but you can either use a bool query
[http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html]
with a must_not clause, or a filtered query with a not filter
[http://www.elasticsearch.org/guide/reference/query-dsl/filtered-query.html,
http://www.elasticsearch.org/guide/reference/query-dsl/not-filter.html]

Karel

On Friday, October 26, 2012 2:05:29 AM UTC+2, Elad Ossadon wrote:

2 questions:

  1. With Sunspot I could have a boost command and add score to a document
    based on a calculation

searchable do
...
boost { popularity * 0.1 }
end

this would boost an instance based on a numeric fields named popularity.

How do I implement it with Tire?

  1. How do I exclude results that match one value of a list? Let's say I
    want to exclude all documents with a field id is 1 or 2 or 3. (Like SQL's
    WHERE id NOT IN (1,2,3))

--


(system) #3