Skip to content

Commit

Permalink
Implementing the search titles scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
eee-c committed Apr 20, 2009
1 parent c7abfae commit c866cf4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
3 changes: 2 additions & 1 deletion eee.rb
Expand Up @@ -17,7 +17,8 @@
end

get '/recipes/search' do
data = RestClient.get "#{@@db}/_fti?q=all:#{params[:q]}"
query = "all:#{params[:q]}".sub(/(\w+):(\w+):/, "\\2:")
data = RestClient.get "#{@@db}/_fti?q=#{query}"
@results = JSON.parse(data)

haml :search
Expand Down
8 changes: 5 additions & 3 deletions features/recipe_search.feature
Expand Up @@ -34,8 +34,8 @@ Feature: Search for recipes
Scenario: Searching titles

Given a "pancake" recipe
And a "french toast" recipe with a summary of "not a pancake"
And a 1 second wait to allow the search index to be updated
And a "french toast" recipe with a "not a pancake" summary
And a 0.25 second wait to allow the search index to be updated
When I search titles for "pancake"
Then I should see the "pancake" recipe in the search results
And I should not see the "french toast" recipe in the search results
Expand All @@ -44,7 +44,7 @@ Feature: Search for recipes

Given a "pancake" recipe with "chocolate chips" in it
And a "french toast" recipe with eggs in it and a summary of "does not go well with chocolate"
And a 1 second wait to allow the search index to be updated
And a 0.25 second wait to allow the search index to be updated
When I search ingredients for "chocolate"
Then I should see the "pancake" recipe in the search results
And I should not see the "french toast" recipe in the search results
Expand All @@ -54,3 +54,5 @@ Feature: Search for recipes
Scenario: Sorting (name, date, preparation time, number of ingredients)

Scenario: No matching results

Scenario: Invalid search parameters
19 changes: 19 additions & 0 deletions features/step_definitions/recipe_search.rb
Expand Up @@ -70,6 +70,21 @@
:content_type => 'application/json'
end

Given /^a "(.+)" recipe$/ do |title|
date = Date.new(2009, 4, 19)
permalink = "id-#{title.gsub(/\W/, '-')}"

recipe = {
:title => title,
:date => date,
}

RestClient.put "#{@@db}/#{permalink}",
recipe.to_json,
:content_type => 'application/json'
end


Given /^a ([.\d]+) second wait/ do |seconds|
sleep seconds.to_f
end
Expand All @@ -78,6 +93,10 @@
visit("/recipes/search?q=#{keyword}")
end

When /^I search titles for "(.+)"$/ do |keyword|
visit("/recipes/search?q=title:#{keyword}")
end

Then /^I should see the "(.+)" recipe in the search results$/ do |title|
response.should have_selector("a",
:href => "/recipes/id-#{title.gsub(/\W/, '-')}",
Expand Down
8 changes: 8 additions & 0 deletions spec/eee_spec.rb
Expand Up @@ -68,5 +68,13 @@

get "/recipes/search?q=eggs"
end

it "should not include the \"all\" field when performing fielded searches" do
RestClient.should_receive(:get).
with("#{@@db}/_fti?q=title:eggs").
and_return('{"total_rows":1,"rows":[]}')

get "/recipes/search?q=title:eggs"
end
end
end

0 comments on commit c866cf4

Please sign in to comment.