Skip to content

Commit

Permalink
adding any_terms and all_terms custom clauses that can be accessed th…
Browse files Browse the repository at this point in the history
…rough collection scope method
  • Loading branch information
ryanb committed Oct 19, 2011
1 parent a0b6a31 commit 29053a8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/xapit/client/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ def respond_to?(method, include_private = false)
Array.method_defined?(method) || super
end

def scope(type, args)
Collection.new(@clauses + [{type => args}])
end

private

def where_conditions(conditions)
Expand Down Expand Up @@ -151,10 +155,6 @@ def query
@query ||= Xapit.database.query(@clauses)
end

def scope(type, args)
Collection.new(@clauses + [{type => args}])
end

def method_missing(method, *args, &block)
if Array.method_defined?(method)
records.send(method, *args, &block)
Expand Down
4 changes: 4 additions & 0 deletions lib/xapit/server/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ def apply_clause(type, value)
similar_to(value)
when :with_facets
merge(:and, facet_terms(value))
when :all_terms
merge(:and, value)
when :any_terms
merge(:and, Xapian::Query.new(xapian_operator(:or), value))
end
end

Expand Down
5 changes: 5 additions & 0 deletions spec/xapit/client/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
collection.clauses.should eq([{:where => {:priority => {:from => 3, :to => 5}}}])
end

it "supports a custom clause" do
collection = Xapit::Client::Collection.new.scope(:foo, "bar")
collection.clauses.should eq([{:foo => "bar"}])
end

it "does not raise an exception when passing nil to with_facets" do
lambda {
Xapit::Client::Collection.new.with_facets(nil).should be_kind_of(Xapit::Client::Collection)
Expand Down
5 changes: 5 additions & 0 deletions spec/xapit/server/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,10 @@
query = Xapit::Server::Query.new([{:where => {:priority => {:lte => 3}}}])
query.records.map { |r| r[:id] }.should eq(%w[1 2 3])
end

it "fetches results matching exact terms" do
query = Xapit::Server::Query.new([{:any_terms => ["Xpriority-1", "Xpriority-2"]}])
query.records.map { |r| r[:id] }.should eq(%w[1 2])
end
end
end

0 comments on commit 29053a8

Please sign in to comment.