【发布时间】:2016-01-11 08:01:59
【问题描述】:
我在我的 rails 应用程序中使用 sunspot 2.2.2 来搜索结果, 我的模型中有用于分组的代码:
def self.search_products(params, currency = nil, page_uri = nil)
search_products = Sunspot.search(VariantPrice) do
group :code do
if params[:gallery_order].present?
order_by :price, params[:gallery_order].downcase.to_sym
elsif params[:new_arrival].present? || params[:name] == "new-arrivals"
order_by :product_created_at, :desc
else
if params[:fashion_type] == "fashion"
order_by :price, :asc
elsif params[:sort] != "lowhigh"
order_by :price, :asc
else
order_by :price, :asc
end
end
limit 1
end
end
我的控制器中有这段代码:
variant_prices = Product.search_products(params, @currency, request.original_fullpath)
@variant_prices = []
variant_prices.group(:code).groups.each do |group|
group.results.each do |result|
@variant_prices << result
end
end
@variant_prices = @variant_prices.paginate(:page => params[:page], :per_page => PER_PAGE_VALUE)
@variant_prices_count = variant_prices.group(:code).total
现在我得到了@variant_prices_count 的预期计数,在我的情况下为 1400,但我将@variant_prices 计数为 60,这在我的情况下是错误的,这里我期望得到 1400。然后我想要用这个结果进行分页。无法理解是 will_paginate 问题还是其他问题。 救命!
【问题讨论】:
-
您的 PER_PAGE_VALUE 值设置为多少?
-
variant_prices.group(:code).total 给出 1400 个计数作为结果,我想在 1400 个结果数据上对其进行分页,但最终结果我只得到 60 个值
-
默认有 19 个值
标签: ruby-on-rails ruby sunspot sunspot-solr