Skip to content

Commit

Permalink
renaming match_facets to with_facets
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Aug 16, 2011
1 parent dc72da8 commit 8157abc
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.rdoc
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions features/step_definitions/xapit_steps.rb
Expand Up @@ -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|
Expand Down Expand Up @@ -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|
Expand Down
4 changes: 2 additions & 2 deletions lib/xapit/client/collection.rb
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions lib/xapit/server/query.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions spec/xapit/client/collection_spec.rb
Expand Up @@ -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
6 changes: 3 additions & 3 deletions spec/xapit/server/query_spec.rb
Expand Up @@ -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

0 comments on commit 8157abc

Please sign in to comment.