gpt4 book ai didi

ruby-on-rails - 轮胎 Elasticsearch 的过滤问题

转载 作者:太空宇宙 更新时间:2023-11-03 18:18:14 26 4
gpt4 key购买 nike

Want to search for the title from the board with live_flag true.

class Board < ActiveRecord::Base
has_many :deals
include Tire::Model::Search

tire.mapping do
indexes :title, type: 'string'
indexes :deals do
indexes :title, type: 'string'
end
end

def to_indexed_json
{
:title => title,
:deals => {:title => self.deals.map(&:title)},
}.to_json
end

def self.search(params)
tire.search(load: true) do
query {string params[:query]+"*"}
filter :term, live_flag: true
sort { by :created_at, "desc" } if params[:query].blank?
end
end

end



Now it will not search anything.


It works properly when below code is used. Difference is that i have removed filter text from it.

def self.search(params)
tire.search(load: true) do
query {string params[:query]+"*"}
sort { by :created_at, "desc" } if params[:query].blank?
end
end

**But i want to get boards whose live_flag is true.**

最佳答案

现在您的索引不包含 live_flag只需将 live_flag 添加到您的 to_indexed_json 和映射

tire.mapping do
indexes :title, type: 'string'
indexes :live_flag, type: 'boolean'
indexes :deals do
indexes :title, type: 'string'
end
end

def to_indexed_json
{
:title => title,
:live_flag => live_flag,
:deals => {:title => self.deals.map(&:title)},
}.to_json
end

关于ruby-on-rails - 轮胎 Elasticsearch 的过滤问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22784386/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com