【发布时间】:2014-06-04 05:32:38
【问题描述】:
我正在尝试在我的一个模型上设置价格分面,但我似乎无法让它正常工作。无论我选择哪个方面,它都只会返回价格等于 0 美元的列表。我不确定我在这里缺少什么。任何帮助将非常感激。这是我的代码:
迁移
class CreateListings < ActiveRecord::Migration
def change
create_table :listings do |t|
t.references :member
t.text :title
t.text :link
t.text :category
t.text :description
t.decimal :price, :precision => 8, :scale => 2
t.timestamps
end
add_index :listings, :member_id
add_attachment :listings, :feature
end
end
型号
class Listing < ActiveRecord::Base
searchable :auto_index => true, :auto_remove => true do
text :title, :boost => 5
text :marker_list, :boost => 2
text :category
string :marker_list, :multiple => true, :stored => true
float :price
end
end
控制器
class ListingsController < ApplicationController
def index
@listings = Listing.order('created_at desc').page(params[:page]).per_page(60)
@search = Listing.search do
fulltext params[:search]
facet(:marker_list, :limit => 48, :sort => :count)
with(:marker_list, params[:tag]) if params[:tag].present?
facet(:price) do
row("$0 - $25") do
with(:price, 0.00..25.00)
end
row("$25 - $75") do
with(:price, 25.01..75.00)
end
row("$75 - $250") do
with(:price, 75.01..250.00)
end
row("$250+") do
with(:price).greater_than(250.00)
end
end
with(:price, params[:price]) if params[:price].present?
end
@query = params[:search]
@facet = params[:tag]
@price_facet = params[:price]
@results = @search.results
respond_to do |format|
format.html # index.html.erb
format.json { render json: @listings }
end
end
end
查看
<% for row in @search.facet(:price).rows %>
<span class="eloc"><%= link_to row.value, :price => row.value %></span>
<% end %>
【问题讨论】:
标签: ruby-on-rails solr sunspot faceted-search sunspot-rails