Jens K. wrote:
have a look at ConstantScoreQuery. It allows to turn a Filter into a
query where all results score equally.
To get this Filter, you could use the QueryFilter class, which allows
you to turn your original query into a Filter.
looks like there should be an easier way to achieve this, though
Thanks a lot for help. The ConstantScoreQuery with QueryFilter and
TermQuery/MultiTermQuery work fine. I am able to get constant value for
all of the ingredients inserted into the query.
The problem appears when I would like to get more precise results with
multiple ingredients inserted. So, coming back to my example:
recipe2: “onion beef chicken”
recipe3: “onion beef chicken tomato”
recipe4: “onion chicken”
All results from that query are equal and that’s great:
When I put more than one ingredient into account I would like to
distinguish different scores for recipes which: include three of them,
include two of them, recipes which has one of them only.
So I would like create a query which return 100% hits for recipe2 and
appropriately less for recipe4 and adequately less for recipe1.
I created multi query like that:
multi_term_query = MultiTermQuery.new(:ingredients)
multi_term_query << “onion” << “beef” << “chicken”
query = ConstantScoreQuery.new(QueryFilter.new(multi_term_query)
but it doesn’t work at all.
Thanks in advance,