【问题标题】:rails sunspot searchable enumrails sunspot 可搜索枚举
【发布时间】:2015-11-19 00:10:59
【问题描述】:

如何使用太阳黑子搜索 Rails 中的枚举?

枚举类型:[ :restaurant, :travel, :hotel ]

searchable do
    text :name, :boost => 5
    text :description
    integer :type
    time :created_at
end

我的控制器:

@search = Product.search do
  fulltext params[:search]
end

仍然没有结果,有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails enums sunspot-rails sunspot-solr


    【解决方案1】:

    您可以将可搜索字段定义从整数更改为字符串,并使用with(:field, params[:search_query])

    型号:

    searchable do
      string :enum_field
    end
    

    控制器:

    @search = Product.search do
      with(enum_field: params[:search_query])
    end
    

    编辑:另外,我刚刚想到您可能需要重命名枚举列,因为 ActiveRecord 使用 type 来表示单表继承。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-17
      • 2010-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-29
      相关资源
      最近更新 更多