Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding any_terms and all_terms custom clauses that can be accessed th…

…rough collection scope method
  • Loading branch information...
commit 29053a8dd8188149a24ffad32a4da62d09a8f7d9 1 parent a0b6a31
@ryanb authored
View
8 lib/xapit/client/collection.rb
@@ -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)
@@ -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)
View
4 lib/xapit/server/query.rb
@@ -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
View
5 spec/xapit/client/collection_spec.rb
@@ -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)
View
5 spec/xapit/server/query_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.