Hi, I am using acts_as_ferret and have a problem with scoring. I would like to organize it in such way that, if any of the searched terms fits, I get 1.0 score as a result. I will explain it on the example. I have in index: a) "one two three four" b) "one two three" c) "one two" d) "one" When I search for "one" I would like to get 1.0 score for all of indexed elements. When I search for "one two" I get 1.0 score for a),b),c). Thanks for any help! -- Posted via http://www.ruby-forum.com/.
On 23.08.2007, at 14:32, Mlynco Mlynco wrote:> I am using acts_as_ferret and have a problem with scoring. I would > like > to organize it in such way that, if any of the searched terms fits, I > get 1.0 score as a result. I will explain it on the example.Sounds to me like the wrong approach. You won''t get Ferret to score a document with 1.0 if there are more terms in the document than you search for.> I have in index: > > a) "one two three four" > b) "one two three" > c) "one two" > d) "one" > > When I search for "one" I would like to get 1.0 score for all of > indexed > elements. When I search for "one two" I get 1.0 score for a),b),c).Question is: What do you actually want to achieve? Why do you want the documents to be scored this way? I''m sure there''s a better way to do it. You might want to check out phrase queries (i.e. using quotes) and boolean operators and see if a combination of them might work for you. Cheers, Andreas
Andreas Korth wrote:> On 23.08.2007, at 14:32, Mlynco Mlynco wrote: > >> I am using acts_as_ferret and have a problem with scoring. I would >> like >> to organize it in such way that, if any of the searched terms fits, I >> get 1.0 score as a result. I will explain it on the example. > > Sounds to me like the wrong approach. You won''t get Ferret to score a > document with 1.0 if there are more terms in the document than you > search for. > >> I have in index: >> >> a) "one two three four" >> b) "one two three" >> c) "one two" >> d) "one" >> >> When I search for "one" I would like to get 1.0 score for all of >> indexed >> elements. When I search for "one two" I get 1.0 score for a),b),c). > > Question is: What do you actually want to achieve? Why do you want > the documents to be scored this way? I''m sure there''s a better way to > do it. > > You might want to check out phrase queries (i.e. using quotes) and > boolean operators and see if a combination of them might work for you. > > Cheers, > AndreasAndreas, Probably you are right. What I don''t what to do is to decrease the score for elements which have some additional terms. So, ie I am looking for a recipe. I have indexed some of them with such ingredients: recipe1: "beef" recipe2: "onion beef chicken" recipe3: "onion beef chicken tomato" Looking for a "beef" I wouldn''t like to "punish" recipe2 and recipe3 because they are richer, I would like to treat them in the same way. Actually the score does not have to be 1.0, but I would like it to be the same for all recipes mentioned above. Any suggestions? Thanks a lot, mlynco -- Posted via http://www.ruby-forum.com/.
On Thu, Aug 23, 2007 at 06:22:52PM +0200, Mlynco Mlynco wrote: [..]> > So, ie I am looking for a recipe. I have indexed some of them with such > ingredients: > > recipe1: "beef" > recipe2: "onion beef chicken" > recipe3: "onion beef chicken tomato" > > Looking for a "beef" I wouldn''t like to "punish" recipe2 and recipe3 > because they are richer, I would like to treat them in the same way. > Actually the score does not have to be 1.0, but I would like it to be > the same for all recipes mentioned above. > > Any suggestions?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. query = ConstantScoreQuery.new(QueryFilter.new(TermQuery.new(:ingredients, ''beef'')) looks like there should be an easier way to achieve this, though ;-) Jens -- Jens Kr?mer http://www.jkraemer.net/ - Blog http://www.omdb.org/ - The new free film database
Jens Kraemer 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. > > query = > ConstantScoreQuery.new(QueryFilter.new(TermQuery.new(:ingredients, > ''beef'')) > > looks like there should be an easier way to achieve this, though ;-) > > JensJens, 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: recipe1: "beef" recipe2: "onion beef chicken" recipe3: "onion beef chicken tomato" recipe4: "onion chicken" All results from that query are equal and that''s great: query = ConstantScoreQuery.new(QueryFilter.new(TermQuery.new(:ingredients, ''beef'')) 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 recipe3, 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. Any ideas? Thanks in advance, mlynco -- Posted via http://www.ruby-forum.com/.