Commit 28e8b011 by vulehuan

search

parent e340ee6a
...@@ -48,6 +48,9 @@ group :development, :test do ...@@ -48,6 +48,9 @@ group :development, :test do
gem 'rspec-rails' gem 'rspec-rails'
gem 'faker', '1.1.2' gem 'faker', '1.1.2'
end end
group :development do
gem 'sunspot_solr'
end
group :test do group :test do
gem 'capybara' gem 'capybara'
gem 'factory_girl_rails' gem 'factory_girl_rails'
...@@ -55,4 +58,5 @@ end ...@@ -55,4 +58,5 @@ end
gem 'will_paginate', '3.0.4' gem 'will_paginate', '3.0.4'
gem 'will_paginate-bootstrap' gem 'will_paginate-bootstrap'
gem 'recaptcha-mailhide' gem 'recaptcha-mailhide'
gem "breadcrumbs_on_rails" gem "breadcrumbs_on_rails"
\ No newline at end of file gem 'sunspot_rails'
\ No newline at end of file
...@@ -66,13 +66,14 @@ GEM ...@@ -66,13 +66,14 @@ GEM
mime-types (~> 1.16) mime-types (~> 1.16)
treetop (~> 1.4.8) treetop (~> 1.4.8)
mime-types (1.25) mime-types (1.25)
mini_portile (0.5.1) mini_portile (0.5.2)
minitest (4.7.5) minitest (4.7.5)
multi_json (1.8.2) multi_json (1.8.2)
mysql2 (0.3.13) mysql2 (0.3.13)
nokogiri (1.6.0) nokogiri (1.6.0)
mini_portile (~> 0.5.0) mini_portile (~> 0.5.0)
polyglot (0.3.3) polyglot (0.3.3)
pr_geohash (1.0.0)
rack (1.5.2) rack (1.5.2)
rack-test (0.6.2) rack-test (0.6.2)
rack (>= 1.0) rack (>= 1.0)
...@@ -93,6 +94,8 @@ GEM ...@@ -93,6 +94,8 @@ GEM
rdoc (3.12.2) rdoc (3.12.2)
json (~> 1.4) json (~> 1.4)
recaptcha-mailhide (0.1.1) recaptcha-mailhide (0.1.1)
rsolr (1.0.9)
builder (>= 2.1.2)
rspec-core (2.14.6) rspec-core (2.14.6)
rspec-expectations (2.14.3) rspec-expectations (2.14.3)
diff-lcs (>= 1.1.3, < 2.0) diff-lcs (>= 1.1.3, < 2.0)
...@@ -121,6 +124,13 @@ GEM ...@@ -121,6 +124,13 @@ GEM
actionpack (>= 3.0) actionpack (>= 3.0)
activesupport (>= 3.0) activesupport (>= 3.0)
sprockets (~> 2.8) sprockets (~> 2.8)
sunspot (2.0.0)
pr_geohash (~> 1.0)
rsolr (~> 1.0.7)
sunspot_rails (2.0.0)
nokogiri
sunspot (= 2.0.0)
sunspot_solr (2.0.0)
thor (0.18.1) thor (0.18.1)
thread_safe (0.1.3) thread_safe (0.1.3)
atomic atomic
...@@ -158,6 +168,8 @@ DEPENDENCIES ...@@ -158,6 +168,8 @@ DEPENDENCIES
rspec-rails rspec-rails
sass-rails (~> 4.0.0) sass-rails (~> 4.0.0)
sdoc sdoc
sunspot_rails
sunspot_solr
turbolinks turbolinks
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
will_paginate (= 3.0.4) will_paginate (= 3.0.4)
......
...@@ -48,6 +48,14 @@ class ProductsController < ApplicationController ...@@ -48,6 +48,14 @@ class ProductsController < ApplicationController
@products = Product.get_user_items(limit: 16, page: params[:page], user_id: params[:user_id], all_status: all_status) @products = Product.get_user_items(limit: 16, page: params[:page], user_id: params[:user_id], all_status: all_status)
end end
def search
add_breadcrumb "Search results", url_for(action: 'search')
if params[:keyword] == nil
redirect_to products_path
end
@products = Product.search { fulltext params[:keyword] }
end
private private
def product_params def product_params
......
class Product < ActiveRecord::Base class Product < ActiveRecord::Base
validates :name, :code, :condition, :image_medium, :price, :price_currency, presence: true validates :name, :code, :condition, :image_medium, :price, :price_currency, presence: true
belongs_to :product_category belongs_to :product_category
searchable do
text :title, :description
string :headline, :code, :condition, :price_currency
double :price
integer :product_category_id, :user_id
end
# Returns recommended products (order by rate, and available) # Returns recommended products (order by rate, and available)
def self.get_recommended_products(options = { limit: 8 }) def self.get_recommended_products(options = { limit: 8 })
......
<% provide(:title, "Search results") %>
<div class="body-box list-view margin-1">
<h2 class="sprite-2">
Search results<span class="sprite-2"></span>
</h2>
<%= render 'shared/grid', items: @newest_items %>
</div>
\ No newline at end of file
...@@ -3,6 +3,7 @@ VenshopApp::Application.routes.draw do ...@@ -3,6 +3,7 @@ VenshopApp::Application.routes.draw do
get "products/index" get "products/index"
get "products/show" get "products/show"
get "products/user_items" get "products/user_items"
get "products/search"
get "cards/index" get "cards/index"
get "cards/checkout" get "cards/checkout"
post "cards/checkout" post "cards/checkout"
......
production:
solr:
hostname: localhost
port: 8983
log_level: WARNING
# read_timeout: 2
# open_timeout: 0.5
development:
solr:
hostname: localhost
port: 8982
log_level: INFO
test:
solr:
hostname: localhost
port: 8981
log_level: WARNING
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment