Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
VietTH-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
4
Merge Requests
4
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
Tran Hoang Viet
VietTH-VenShop
Commits
f308e16c
Commit
f308e16c
authored
Jul 17, 2015
by
Tran Hoang Viet
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/develop' into vietth_feat_order_management
parents
1236556d
1cca49df
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
10 deletions
+27
-10
app/models/concerns/solr.rb
+27
-10
No files found.
app/models/concerns/solr.rb
View file @
f308e16c
...
...
@@ -5,7 +5,7 @@ module Solr extend ActiveSupport::Concern
# callbacks
def
push_data_to_solr
self
.
class
.
rsolr
.
add
(
self
.
slice
(
*
self
.
class
.
solr_
fields
))
self
.
class
.
rsolr
.
add
(
self
.
slice
(
*
self
.
class
.
solr_
options_data
[
:fields
]
))
self
.
class
.
rsolr
.
commit
end
...
...
@@ -16,26 +16,41 @@ module Solr extend ActiveSupport::Concern
end
module
ClassMethods
attr_
accessor
:solr_per_page
,
:solr_page
,
:solr_total_count
,
:solr_fields
attr_
reader
:solr_options_data
def
solr_options
(
fields
=
{})
@solr_per_page
=
fields
[
:per_page
]
||
5
@solr_fields
=
fields
[
:fields
]
||
[]
@solr_options_data
=
{
escape:
true
,
page:
1
,
per_page:
5
}.
merge
(
fields
)
end
def
search
(
query
,
options
=
{})
return
unless
query
.
is_a?
(
Hash
)
@solr_page
=
options
[
:page
]
||
1
query
=
query
.
inject
(
''
)
{
|
str
,
item
|
str
<<
"
#{
item
.
first
}
:(
#{
item
.
last
}
)"
<<
' '
}
@solr_options_data
=
solr_options_data
.
merge
(
options
)
query
=
query
.
inject
(
''
)
do
|
str
,
item
|
if
item
.
last
.
is_a?
(
Hash
)
value
=
item
.
last
[
:value
]
escape
=
item
.
last
[
:escape
].
nil?
||
item
.
last
[
:escape
].
present?
else
value
=
item
.
last
escape
=
solr_options_data
[
:escape
].
present?
end
value
=
%Q("
#{
value
}
")
if
escape
.
present?
str
<<
"
#{
item
.
first
}
:
#{
value
}
"
<<
' '
end
results
=
rsolr
.
paginate
(
solr_
page
,
solr_
per_page
,
solr_
options_data
[
:page
]
,
solr_
options_data
[
:per_page
]
,
'select'
,
params:
{
q:
query
,
fl:
self
.
primary_key
}
)
@solr_
total_count
=
results
[
'response'
][
'numFound'
].
to_i
@solr_
options_data
[
:total_count
]
=
results
[
'response'
][
'numFound'
].
to_i
parse
(
results
[
'response'
])
end
...
...
@@ -49,7 +64,9 @@ module Solr extend ActiveSupport::Concern
end
def
kaminari_paginate
Kaminari
.
paginate_array
([],
total_count:
solr_total_count
).
page
(
solr_page
).
per
(
solr_per_page
)
Kaminari
.
paginate_array
([],
total_count:
@solr_options_data
[
:total_count
])
.
page
(
solr_options_data
[
:page
])
.
per
(
solr_options_data
[
:per_page
])
end
def
clear_solr_index
...
...
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