Searchkick如何运行精确的查询匹配(不区分大小写)

时间:2017-11-20 05:46:29

标签: ruby-on-rails elasticsearch filter rspec searchkick

我正在使用searchkick实现elasticsearch搜索方法。我的设置如下:

#elastic search settings:
  searchkick 

 def search_data
    attributes.merge(
      title: title,
      last_name: author(&:last_name),
      publisher_name: publisher(&:name),
    )
end

我的搜索如下:

self.search(query, fields: [:title, {publisher_name: :exact}, {last_name: :exact}]).records      

但是,如果我在工厂运行rspec测试,我会得到结果,告诉我确切无效。例如:

author1 = create(:author, first_name: "Kate", last_name: "White")       
publisher1 = create(:publisher, name: "HarperCollins")
book1 = create(:book, title: "The Secrets You Keep: A Novel", author_id: author1.id, publisher_id: publisher1.id)

publisher3 = create(:publisher, name: "Pamela Dorman Books;")
author3 = create(:author, first_name: "Shari", last_name: "Lapena")  
book3 = create(:book, title: "Couple Next Door", author_id: author3.id, publisher_id: publisher3.id)


author4 = create(:author, first_name: "Lauren", last_name: "Graham")       
publisher4 = create(:publisher, name: "Ballantine Books")
book4 = create(:book, title: "Someday, Secrets Someday, Maybe", author_id: author4.id, publisher_id: publisher4.id)


author5 = create(:author, first_name: "Fictious", last_name: "Secrets")       
publisher5 = create(:publisher, name: "Ballantine Books")
book5 = create(:book, title: "Fictious Book 1", author_id: author5.id, publisher_id: publisher5.id)

author9 = create(:author, first_name: "Lauren", last_name: "xyz")       
publisher9 = create(:publisher, name: "Secrets halo")
book9 = create(:book, title: "Cool Book", author_id: author9.id, publisher_id: publisher9.id)

Rspec查询:

expect(Book.search_instead_with_elastic_search('Secrets')).to match_array([book1, book4, book5, book9])

通过。

但是,如果我指定了确切的,为什么要考虑"Secrets halo"book9不应包含在我的搜索结果中。

0 个答案:

没有答案