Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
venshop
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tan Phat Nguyen
venshop
Commits
434e224e
Commit
434e224e
authored
Nov 27, 2014
by
Tan Phat Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix solr search text special
parent
e75398e8
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
33 additions
and
7 deletions
+33
-7
app/assets/stylesheets/custom_bootstrap.css.scss
+5
-1
app/models/order.rb
+2
-1
app/services/searcher.rb
+3
-1
app/views/products/_product.html.erb
+3
-1
app/views/products/_search_product.html.erb
+1
-1
config/environments/production.rb
+16
-0
config/initializers/constants.rb
+1
-0
db/seeds.rb
+1
-1
lib/tasks/db.rake
+1
-1
No files found.
app/assets/stylesheets/custom_bootstrap.css.scss
View file @
434e224e
...
...
@@ -112,8 +112,12 @@ h2 {
}
.prod-title
{
//height: 40
px;
font-size
:
18
px
;
white-space
:
nowrap
;
overflow
:
hidden
;
text-overflow
:
ellipsis
;
}
.form-control
{
width
:
25%
;
}
app/models/order.rb
View file @
434e224e
...
...
@@ -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
...
...
app/services/searcher.rb
View file @
434e224e
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
app/views/products/_product.html.erb
View file @
434e224e
...
...
@@ -2,7 +2,9 @@
<div
style=
'height: 234px;'
>
<%=
image_tag
product
.
photo_url
.
to_s
,
width:
'140'
,
height:
'140'
,
class:
'img-thumbnail'
%>
</div>
<div
class=
'prod-title'
><h4>
<%=
link_to
product
.
name
,
product_path
(
product
)
%>
</h4></div>
<div
class=
'prod-title'
>
<%=
link_to
product
.
name
,
product_path
(
product
),
title:
product
.
name
%>
</div>
<span
class=
'price-col'
>
$
<%=
product
.
price
%>
</span>
<%=
button_to
'Add to Cart'
,
line_items_path
(
product_id:
product
),
{
class:
'btn btn-default'
}
%>
</div>
app/views/products/_search_product.html.erb
View file @
434e224e
...
...
@@ -2,7 +2,7 @@
<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>
config/environments/production.rb
View file @
434e224e
...
...
@@ -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
config/initializers/constants.rb
0 → 100644
View file @
434e224e
SOLR_QUERY_SPECIAL_CHAR
=
[
'+'
,
'-'
,
'&&'
,
'||'
,
'!'
,
'('
,
')'
,
'{'
,
'}'
,
'['
,
']'
,
'^'
,
'"'
,
'~'
,
'*'
,
'?'
,
':'
,
'\\'
]
db/seeds.rb
View file @
434e224e
...
...
@@ -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
lib/tasks/db.rake
View file @
434e224e
...
...
@@ -80,7 +80,7 @@ namespace :db do
end
def
category_hash
{
'Books'
=>
'1000'
,
'Health
PersonalCare'
=>
'3760931'
,
'Outdoor
Living'
=>
'286168'
,
{
'Books'
=>
'1000'
,
'Health
Personal Care'
=>
'3760931'
,
'Outdoor
Living'
=>
'286168'
,
'Appliances'
=>
'2619525011'
,
'Magazines'
=>
'599872'
}
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment