gpt4 book ai didi

ruby-on-rails - Tire + Elasticsearch:如何搜索值范围?

转载 作者:行者123 更新时间:2023-12-02 22:44:02 25 4
gpt4 key购买 nike

到目前为止,您一直很喜欢Tyre和elasticsearch,但无法弄清楚如何在以下范围之间搜索值:

  • age_from age_to
  • 18至20

  • 并返回年龄在这两个范围之间的所有配置文件?
    我有一个整数列Profile.age

    到目前为止功能不完整
    def self.search(params)

    #, default_operator: "AND
    tire.search(load: true, page: params[:page], per_page: 20) do
    query do
    should { string params[:query] } if params[:query].present?
    should { integer age_to[:age_to] } if params[:age_to].present?
    end
    to_curl
    end

    end

    最佳答案

    query do
    should { string params[:query] } if params[:query].present?
    should { range :age, { gte: params[:age_from], lte: params[:age_to] } } if params[:age_to].present? && params[:age_from].present?
    end

    关于ruby-on-rails - Tire + Elasticsearch:如何搜索值范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12216219/

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