ruby on rails - Searchkick search data working in test but not in browser -




i experiencing weird behavior elasticsearch wrapper ruby gem searchkick, , i'd love help!

the issue

the expected behavior should able search full name space in it. works in test, not in browser.

the code

account.rb

class account   searchkick word_start: [     :first_name,     :last_name,     :name, # <======================== key line     :email,     :phone,     :company,   ], callbacks: :async    def self.index_search(query:)     search(       query || '*',       fields: [         :first_name,         :last_name,         :name, # <======================== key line         :email,         :phone,         :company,       ],       match: :word_start,       where: { test_account: false },       order: { created_at: :desc },       limit: 20,       misspellings: false,     )   end    def search_data     {       first_name: first_name,       last_name: last_name,       name: "#{first_name} #{last_name}", # <======================== key line       created_at: created_at,       email: email,       phone: phone,       test_account: test_account,       company: company     }   end end 

account_test.rb - of these pass

class accounttest < activesupport::testcase   describe "::index_search"     let(:account_0)       factorygirl.create(:account, company: "xyz consulting")  # name: "testy mctesterson"     end     let(:account_1)       factorygirl.create(:account, first_name: "bob") # name: "bob mctesterson"     end     let(:search)       account.index_search(query: query)     end      before :all       account_0 , account_1 # instantiate       searchkick.disable_callbacks       account.reindex     end      describe "when there spaces in string"       let(:query) { "xyz con" }        "finds , appropriate records"         assert_equal [account_0.id], search.map(&:id)       end     end      describe "when query matches full name"       let(:query) { "bob mct" }        "finds , appropriate records"         assert_equal [account_1.id], search.map(&:id)       end     end   end end 

note: when comment out 3 'key lines' account.rb, second of tests fails. name: in #search_data method seems working.

search_controller.rb (essentially)

class searchcontroller < applicationcontroller   def index     puts "params[:query]: #{params[:query]}"     puts "custom_search.map(&:first_name): #{custom_search.map(&:first_name)}"     puts "custom_search.map(&:last_name): #{custom_search.map(&:last_name)}"   end    private    def custom_search    account.index_search(query: params[:query])   end end 

the complication

nonetheless, in browser, doesn't seem working. above code, searching via browser, can't reproduce success.

when search "bob ", output in server console is

params[:query]: bob custom_search.map(&:first_name): ["bob"] custom_search.map(&:last_name): ["mctesterdorff"] 

but search "bob m", "bob mct", or "bob mctesterdorff", empty results (respecitvely):

params[:query]: bob m custom_search.map(&:first_name): [] custom_search.map(&:last_name): []  params[:query]: bob mct custom_search.map(&:first_name): [] custom_search.map(&:last_name): []  params[:query]: bob mctesterdorff custom_search.map(&:first_name): [] custom_search.map(&:last_name): [] 

do have idea issue might be?





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -