From 8157abc45c7d722aa525f332112c7bfd388f2776 Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Tue, 16 Aug 2011 10:37:18 -0700 Subject: [PATCH] renaming match_facets to with_facets --- README.rdoc | 2 +- features/step_definitions/xapit_steps.rb | 4 ++-- lib/xapit/client/collection.rb | 4 ++-- lib/xapit/server/query.rb | 6 +++--- spec/xapit/client/collection_spec.rb | 10 ++++++++-- spec/xapit/server/query_spec.rb | 6 +++--- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/README.rdoc b/README.rdoc index 04e3c95..f626d49 100644 --- a/README.rdoc +++ b/README.rdoc @@ -104,7 +104,7 @@ Facets allow you to further filter the result set based on certain attributes. The facet option is passed in through the URL which you can add to the search. - Article.search("phone").facets(params[:facets]) + Article.search("phone").with_facets(params[:facets]) You can also list the applied facets along with a remove link. diff --git a/features/step_definitions/xapit_steps.rb b/features/step_definitions/xapit_steps.rb index b0b00cf..88909ac 100644 --- a/features/step_definitions/xapit_steps.rb +++ b/features/step_definitions/xapit_steps.rb @@ -71,7 +71,7 @@ end When /^I query "([^\"]*)" with facets "([^\"]*)"$/ do |keywords, facets| - @records = XapitMember.search(keywords).match_facets(facets) + @records = XapitMember.search(keywords).with_facets(facets) end Then /^I should find records? named "([^\"]*)"$/ do |joined_names| @@ -115,7 +115,7 @@ end When /^I query facets "([^\"]*)"$/ do |facets| - @records = XapitMember.search.match_facets(facets) + @records = XapitMember.search.with_facets(facets) end When /^I query "([^\"]*)" sorted by (.*?)( descending)?$/ do |keywords, sort, descending| diff --git a/lib/xapit/client/collection.rb b/lib/xapit/client/collection.rb index b25f29d..c1ea01b 100644 --- a/lib/xapit/client/collection.rb +++ b/lib/xapit/client/collection.rb @@ -50,8 +50,8 @@ def similar_to(member) scope(:similar_to, member.class.xapit_index_builder.document_data(member)) end - def match_facets(facets) - scope(:match_facets, facets.split("-")) + def with_facets(facets) + scope(:with_facets, facets.split("-")) if facets.to_s.length > 0 end def include_facets(*facets) diff --git a/lib/xapit/server/query.rb b/lib/xapit/server/query.rb index a6f5fda..04c556b 100644 --- a/lib/xapit/server/query.rb +++ b/lib/xapit/server/query.rb @@ -57,8 +57,8 @@ def facets def applied_facet_options facet_options = [] @clauses.each do |clause| - if clause[:match_facets] - clause[:match_facets].each do |identifier| + if clause[:with_facets] + clause[:with_facets].each do |identifier| facet_options << facet_option(identifier) end end @@ -156,7 +156,7 @@ def apply_clause(type, value) merge(:not, value.map { |c| "C#{c}" }) when :similar_to similar_to(value) - when :match_facets + when :with_facets merge(:and, facet_terms(value)) end end diff --git a/spec/xapit/client/collection_spec.rb b/spec/xapit/client/collection_spec.rb index c9c939c..48f37c5 100644 --- a/spec/xapit/client/collection_spec.rb +++ b/spec/xapit/client/collection_spec.rb @@ -26,12 +26,18 @@ end it "splits up matching facets into an array" do - collection = Xapit::Client::Collection.new([]).match_facets("foo-bar") - collection.clauses.should eq([{:match_facets => %w[foo bar]}]) + collection = Xapit::Client::Collection.new([]).with_facets("foo-bar") + collection.clauses.should eq([{:with_facets => %w[foo bar]}]) end it "splits range into from/to hash" do collection = Xapit::Client::Collection.new([]).where(:priority => 3..5) collection.clauses.should eq([{:where => {:priority => {:from => 3, :to => 5}}}]) end + + it "does not raise an exception when passing nil to with_facets" do + lambda { + Xapit::Client::Collection.new([]).with_facets(nil) + }.should_not raise_exception + end end diff --git a/spec/xapit/server/query_spec.rb b/spec/xapit/server/query_spec.rb index a010417..b323ea2 100644 --- a/spec/xapit/server/query_spec.rb +++ b/spec/xapit/server/query_spec.rb @@ -29,15 +29,15 @@ it "fetches results matching a given facet" do Xapit.database.add_document(:attributes => {:priority => {:value => "3", :field => {}, :facet => {}}}, :id => 123, :class => "Greeting") - query = Xapit::Server::Query.new([{:match_facets => [Xapit.facet_identifier(:priority, "3")]}]) + query = Xapit::Server::Query.new([{:with_facets => [Xapit.facet_identifier(:priority, "3")]}]) query.records.should eq([{:class => "Greeting", :id => "123", :relevance => 100}]) - query = Xapit::Server::Query.new([{:match_facets => [Xapit.facet_identifier(:priority, "4")]}]) + query = Xapit::Server::Query.new([{:with_facets => [Xapit.facet_identifier(:priority, "4")]}]) query.records.should eq([]) end it "fetches results containing applied facets" do Xapit.database.add_document(:attributes => {:priority => {:value => "3", :facet => {}}}, :id => 123, :class => "Greeting") - query = Xapit::Server::Query.new([{:match_facets => [Xapit.facet_identifier(:priority, "3")]}]) + query = Xapit::Server::Query.new([{:with_facets => [Xapit.facet_identifier(:priority, "3")]}]) query.applied_facet_options.should eq([{:name => "priority", :value => "3"}]) end end