excellalabs / nefarious-octo-kumquat

2 stars 0 forks source link

Notes #1

Open drewbailey opened 8 years ago

drewbailey commented 8 years ago

Pre-reqs

rails new search_app 
rails g scaffold Question text:string slug:string blurb:string, answer:string
rake db:migrate 
gem 'searchkick'
gem 'searchjoy'

install elasticsearch locally (?) http://stackoverflow.com/questions/22850247/installing-elasticsearch-on-osx-mavericks, probably want to cover linux (& windows :-1: )

First pass

class Question < ActiveRecord::Base
  searchkick
end

Make sure we are running elasticsearch locally (elasticsearch in a different tab in OSX)

rake searchkick:reindex:all
rails c
Question.search('what')

 Question Search (93.2ms)  curl http://localhost:9200/questions_development/_search?pretty -d '{"query":{"dis_max":{"queries":[{"match":{"_all":{"query":"what","operator":"and","boost":1,"fuzziness":1,"prefix_length":0,"max_expansions":3,"analyzer":"searchkick_search"}}},{"match":{"_all":{"query":"what","operator":"and","boost":1,"fuzziness":1,"prefix_length":0,"max_expansions":3,"analyzer":"searchkick_search2"}}},{"match":{"_all":{"query":"what","operator":"and","boost":10,"analyzer":"searchkick_search"}}},{"match":{"_all":{"query":"what","operator":"and","boost":10,"analyzer":"searchkick_search2"}}}]}},"size":100000,"from":0,"fields":[]}'
  Question Search (93.2ms)  curl http://localhost:9200/questions_development/_search?pretty -d '{"query":{"dis_max":{"queries":[{"match":{"_all":{"query":"what","operator":"and","boost":1,"fuzziness":1,"prefix_length":0,"max_expansions":3,"analyzer":"searchkick_search"}}},{"match":{"_all":{"query":"what","operator":"and","boost":1,"fuzziness":1,"prefix_length":0,"max_expansions":3,"analyzer":"searchkick_search2"}}},{"match":{"_all":{"query":"what","operator":"and","boost":10,"analyzer":"searchkick_search"}}},{"match":{"_all":{"query":"what","operator":"and","boost":10,"analyzer":"searchkick_search2"}}}]}},"size":100000,"from":0,"fields":[]}'

 => #<Searchkick::Results:0x007fc55f0ab618 @klass=Question (call 'Question.connection' to establish a connection), @response={"took"=>77, "timed_out"=>false, "_shards"=>{"total"=>5, "successful"=>5, "failed"=>0}, "hits"=>{"total"=>1, "max_score"=>0.067124054, "hits"=>[{"_index"=>"questions_development_20150924124506706", "_type"=>"question", "_id"=>"1", "_score"=>0.067124054}]}}, @options={:page=>1, :per_page=>100000, :padding=>0, :load=>true, :includes=>nil, :json=>false}> 

So what was that? Searchkick just curl'd our elasticsearch index and returned results!

We can see our results of questions that came back below.

2.2.2 :002 > _.results
  Question Load (0.7ms)  SELECT "questions".* FROM "questions" WHERE "questions"."id" = 1
  Question Load (0.7ms)  SELECT "questions".* FROM "questions" WHERE "questions"."id" = 1
 => [#<Question id: 1, text: "What color is the sky?", slug: "what_color_is_the_sky", blurb: nil, answer: nil, created_at: "2015-09-24 16:44:47", updated_at: "2015-09-24 16:44:47">] 
drewbailey commented 8 years ago

Creating views for searching

Applying SearchJoy and search conversions

Deploying to heroku with nightly cron job to reindex