0
class Product < ActiveRecord::Base
belongs_to :city
has_and_belongs_to_many :categories
before_destroy { categories.clear }
searchkick locations: ["location"]

def search_data
    {
        istatus: i_status,  
        name: name,
        price: price,
        city_id: city_id,
        value: value,
        discount: discount,
        expiry_date: expiry_date,
        created_at: created_at,
        products_sold: products_sold, 
        city: city.name,
        deal_type: deal_type,
        country: city.country.name,
        category_id: categories.map(&:id),
        location: [latitude, longitude]
    }
end

def self.apply_filters(request)
    # @product = Product.search "Tex-Mex", limit:10  #=>this works
    @product = Product.search body: {match: {name: "Tex-Mex"}},limit: 10 #=>does not work, the limit part work
    end
end

当我使用 body 进行高级搜索时.. 它不会返回所需的结果,尽管限制:10 部分我们工作,因为它只返回 10 个结果

4

3 回答 3

0

我相信文档中缺少一些信息。

这是对基于 SearchKick 中编写的测试的正文查询的引用: https ://github.com/ankane/searchkick/blob/c8f8dc65df2e85b97ea508e14ded299bb8111942/test/index_test.rb#L47

为了使高级搜索起作用,它的编写方式应该是:

@product = Product.search body: { query: { match: {name: "Tex-Mex"}}},limit: 10

您需要querybody.

于 2015-07-03T03:50:28.423 回答
0

您需要使用 Elasticsearch DSL构建查询。具体来说,使用sizematch

Product.search body: { query: { match: {name: "Tex-Mex"} }, size: 10 }

使用高级搜索时,Searchkick 会忽略正文散列之外的参数。而主体哈希允许您使用完整的 ES DSL。

于 2018-01-22T14:30:42.897 回答
0

// 条件 = {}

query = Product.search params[:query], execute: false, where : conditions

query.body[:query] =  { match: {name: "Tex-Mex"} }

query.body[:size] = 10

query.execute
于 2016-02-12T05:26:57.077 回答