我有TS 3.0.6,will_paginate 3.0.5和斯芬克斯2.0.4
我使用页面选项对搜索结果进行分页:
@products = Product.search(query_string, {
order: ordering,
ranker: :bm25,
sql: { include: :images },
with: {
price_type_for_search => min_price_conditions..max_price_conditions,
kind_cd: @params[:kind_cd],
brand_id: [*@params[:brand_ids]],
category_ids: categories_for_search,
property_value_names: [*params[:property_value_names]].map{ |s| Zlib.crc32(s) },
},
page: @params[:page],
per_page: @params[:per]
})我的错误就像
query 0 error: offset out of bounds (offset=12, max_matches=12); query 1 error: offset out of bounds (offset=12, max_matches=12); query 2 error: offset out of bounds (offset=12, max_matches=12); query 3 error: offset out of bounds (offset=12, max_matches=12)其中12是@params:params。
否则,我会在我的观点中使用will_paginate @products,但我认为这并不重要。为什么我会出错?我怎么才能避免呢?
我将这些参数发送到搜索:
order: :created_at
ranker: :bm25,
sql: { include: :images },
with: {
# no matter
},
page: 2,
per_page: 12如果我发送per_page == 18和页面== 2,那么如果我发送per_page == 12和页面== 3,我得到的是query 0 error: offset out of bounds (offset=18, max_matches=18) et.c.,在我的错误中得到(offset=36, max_matches=36)。
发布于 2014-05-22 10:36:05
好吧,我想我已经搞清楚了。这里的问题是,在上面的示例中,facets方法是在@products上调用的。Facet调用不喜欢:page和:per_page选项,因为facet调用只有一个页面。因此,查看页面两个或多个搜索结果会引发错误。
解决方法(我在本地测试过)是将大多数这些搜索选项放在一个共享方法中:
def common_search_options
{
order: ordering,
ranker: :bm25,
with: {
price_type_for_search => min_price_conditions..max_price_conditions,
kind_cd: @params[:kind_cd],
brand_id: [*@params[:brand_ids]],
category_ids: categories_for_search,
property_value_ids: [*params[:property_value_ids]],
}
}
end然后为搜索结果和facet结果创建单独的对象:
@products = Product.search(query_string, common_search_options.merge({
sql: { include: :images },
page: @params[:page],
per_page: @params[:per]
}))
@product_facets = Product.facets(query_string, common_search_options)当然,您需要将@products.facets的任何引用更改为@product_facets。这将确保方面搜索没有分页选项,现在一切都应该顺利进行。
https://stackoverflow.com/questions/23671541
复制相似问题