Rails searchkick无法根据where查询得到结果

Rails searchkick cannot get results based on where query

我在我的应用程序的事件模型上使用 Searchkick。我正在尝试仅搜索状态为:"published" 的结果。我正在控制台中对此进行测试,到目前为止我知道 "Quiz" 有一个事件。我得到一个结果。我可以查看显示该状态的结果:"draft"。但是,当我尝试将此查询写入结果以确认结果计数时,它只是没有考虑状态:"draft" 并给我带回 1 个结果。下面是我正在使用的代码和搜索结果。根据文档,我看不出哪里出错了。

results = Event.search "quiz"

回复:

=> #<Searchkick::Results:0x00007feb0a2d57d8 @klass=Event(id: integer, title: string, content: text, category_id: integer, user_id: integer, created_at: datetime, updated_at: datetime, slug: string, status: integer, featured: boolean, recommended: boolean, excerpt: text, sold_out: boolean, ticketsolve_url: string, meta_title: string, meta_description: text, ticketsolve_event_id: string, featured_video: string, show_video: boolean, author_name: string, expiry: date, manual_seo: boolean, price_details: text, remove_booking_button: boolean, tags: string), @response={"took"=>4, "timed_out"=>false, "_shards"=>{"total"=>5, "successful"=>5, "skipped"=>0, "failed"=>0}, "hits"=>{"total"=>1, "max_score"=>41.952984, "hits"=>[{"_index"=>"events_development_20181122112141928", "_type"=>"event", "_id"=>"3", "_score"=>41.952984}]}}, @options={:page=>1, :per_page=>10000, :padding=>0, :load=>true, :includes=>nil, :model_includes=>nil, :json=>false, :match_suffix=>"analyzed", :highlight=>nil, :highlighted_fields=>[], :misspellings=>true, :term=>"quiz", :scope_results=>nil, :index_name=>nil, :total_entries=>nil}>

results.total_count 等于 1,这是正确的。

结果。[0]显示此事件。

回复:

=> #<Event id: 3, title: "It's A Table Quiz! 2018", content: "<!DOCTYPE html>\r\n<html>\r\n<head>\r\n</head>\r\n<body>\r\n...", category_id: 10, user_id: 2, created_at: "2018-09-20 12:57:01", updated_at: "2018-11-07 19:15:29", slug: "it-s-a-table-quiz-2018", status: "draft", featured: false, recommended: false, excerpt: "On October 4th get yourself and three of your smar...", sold_out: false, ticketsolve_url: "https://firstfortnight.ticketsolve.com/shows/87359...", meta_title: "First Fortnight Event Title", meta_description: "First Fortnight Event Description", ticketsolve_event_id: "1111111", featured_video: "", show_video: false, author_name: nil, expiry: "2019-01-18", manual_seo: false, price_details: nil, remove_booking_button: false, tags: nil>

我们可以看到状态是"draft"。所以现在我要尝试使用测验进行搜索,并在状态等于 "draft" 的位置尝试获得结果 1。

results = Event.search "quiz", where: {status: "draft"}

结果计数等于 0。

我也尝试过 status: 1 或 status: :draft 的其他变体,但这些都没有返回任何结果。再加上看到上面的结果,我认为正确的搜索是 where: {status: "draft"} 无论如何。

我会添加我的模型代码以防我做了一些愚蠢的事情。任何帮助都会非常感谢。

型号:

class Event < ApplicationRecord
    extend FriendlyId

    # Search kick with callback so that when data is committed search runs reindex
    searchkick callbacks: :async
    # Controlled data that is indexed. Allows the user to find posts by author.
    def search_data
    {
            title: title,
            stats: status,
            content: content,
            excerpt: excerpt,
            tags: tags,
      author_name: user.name
    }
  end

    enum status: {draft: 0, published: 1}
end

再次阅读并确认我没有发疯后,我注意到模型中有一个该死的错字。结果现在控制台工作正常。谢谢。