Commit 434e224e by Tan Phat Nguyen

fix solr search text special

parent e75398e8
......@@ -112,8 +112,12 @@ h2 {
}
.prod-title {
//height: 40px;
font-size: 18px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
\ No newline at end of file
text-overflow: ellipsis;
}
.form-control {
width: 25%;
}
......@@ -6,7 +6,8 @@ class Order < ActiveRecord::Base
has_many :line_items, dependent: :destroy
belongs_to :user
validates :name, :address, :email, :pay_type, presence: true
validates :name, :address, :pay_type, presence: true
validates :email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, on: :create }
validates :pay_type, inclusion: PAYMENT_TYPES
paginates_per 10
......
class Searcher
def self.find_products_by(params = {})
solr = RSolr.connect url: Rails.configuration.solr_host.to_s
response = solr.paginate params[:page], Rails.configuration.paginates_per, "select", params: { q: params[:search], wt: 'ruby' }
keyword_search = params[:search].strip
SOLR_QUERY_SPECIAL_CHAR.each { |value| keyword_search.gsub!(value, "\\#{value}") }
response = solr.paginate params[:page], Rails.configuration.paginates_per, "select", params: { q: keyword_search, wt: 'ruby' }
response['response']
end
end
<div class='col-xs-6 col-sm-3 placeholder'>
<div style='height: 234px;'>
<%= image_tag product.photo_url.to_s, width: '140', height: '140', class: 'img-thumbnail' %>
<div class='col-xs-6 col-sm-3 placeholder'>
<div style='height: 234px;'>
<%= image_tag product.photo_url.to_s, width: '140', height: '140', class: 'img-thumbnail' %>
</div>
<div class='prod-title'>
<%= link_to product.name, product_path(product), title: product.name %>
</div>
<div class='prod-title'><h4><%= link_to product.name, product_path(product) %></h4></div>
<span class='price-col'>$<%= product.price %></span>
<%= button_to 'Add to Cart', line_items_path(product_id: product), { class: 'btn btn-default' } %>
</div>
\ No newline at end of file
</div>
<div class='col-xs-6 col-sm-3 placeholder'>
<div style='height: 234px;'>
<%= image_tag Product.find(product['id']).photo_url.to_s, width: '140', height: '140', class: 'img-thumbnail' %>
<div class='col-xs-6 col-sm-3 placeholder'>
<div style='height: 234px;'>
<%= image_tag Product.find(product['id']).photo_url.to_s, width: '140', height: '140', class: 'img-thumbnail' %>
</div>
<div class='prod-title'><h4><%= link_to product['name'], product_path(product['id']) %></h4></div>
<div class='prod-title'><%= link_to product['name'], product_path(product['id']) %></div>
<span class='price-col'>$<%= product['price'] %></span>
<%= button_to 'Add to Cart', line_items_path(product_id: product['id']), { class: 'btn btn-default' } %>
</div>
\ No newline at end of file
</div>
......@@ -75,4 +75,20 @@ Rails.application.configure do
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
config.action_mailer.default_url_options = { host: '192.168.1.204' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
authentication: 'plain',
user_name: ENV['email_user'],
password: ENV['email_password'],
enable_starttls_auto: true
}
config.solr_host = 'http://192.168.1.204:8080/solr/phatshop'
config.paginates_per = 10
end
SOLR_QUERY_SPECIAL_CHAR = ['+', '-', '&&', '||', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':', '\\']
......@@ -6,6 +6,6 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
%w(Books HealthPersonalCare OutdoorLiving Appliances Magazines).each do |category|
['Books', 'Health Personal Care', 'Outdoor Living', 'Appliances', 'Magazines'].each do |category|
Category.create(name: category)
end
......@@ -80,7 +80,7 @@ namespace :db do
end
def category_hash
{ 'Books' => '1000', 'HealthPersonalCare' => '3760931', 'OutdoorLiving' => '286168',
{ 'Books' => '1000', 'Health Personal Care' => '3760931', 'Outdoor Living' => '286168',
'Appliances' => '2619525011', 'Magazines' => '599872' }
end
end
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