Permalink
Browse files

Add more like this query

  • Loading branch information...
1 parent 5818e50 commit 9008adab0164406c363e07387d8bb9b796647e7d @AlphaB AlphaB committed Aug 26, 2012
Showing with 15 additions and 0 deletions.
  1. +5 −0 lib/tire/search/query.rb
  2. +10 −0 test/unit/search_query_test.rb
View
@@ -54,6 +54,11 @@ def fuzzy(field, value, options={})
@value = { :fuzzy => query }
end
+ def mlt(fields, value, options = {})
+ query = { :fields => Array.wrap(fields), :like_text => value }.deep_merge(options)
+ @value = { :more_like_this => query }
+ end
+
def boolean(options={}, &block)
@boolean ||= BooleanQuery.new(options)
block.arity < 1 ? @boolean.instance_eval(&block) : block.call(@boolean) if block_given?
@@ -126,6 +126,16 @@ class QueryTest < Test::Unit::TestCase
end
+ context "MoreLikeThatQuery" do
+ should "allow mlt search" do
+ assert_equal({ :more_like_this => { :fields => [:foo], :like_text => 'bar' } }, Query.new.mlt(:foo, 'bar'))
+ end
+
+ should "allow mlt search with options" do
+ assert_equal({ :more_like_this => { :fields => [:foo], :like_text => 'bar', :percent_terms_to_match => 0.4, :min_doc_freq => 10 } }, Query.new.mlt(:foo, 'bar', :percent_terms_to_match => 0.4, :min_doc_freq => 10))
+ end
+ end
+
context "BooleanQuery" do
should "not raise an error when no block is given" do

0 comments on commit 9008ada

Please sign in to comment.