Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cleaning-portalmec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Richard Fernando Heise Ferreira
cleaning-portalmec
Commits
0c071080
Commit
0c071080
authored
8 years ago
by
Israel Barreto Sant'Anna
Browse files
Options
Downloads
Patches
Plain Diff
Added tests for collection and user search, and user autocomplete
Signed-off-by:
Israel Barreto Sant'Anna
<
ibsa14@inf.ufpr.br
>
parent
3979944f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/services/search_service.rb
+11
-12
11 additions, 12 deletions
app/services/search_service.rb
test/services/search_service_test.rb
+74
-10
74 additions, 10 deletions
test/services/search_service_test.rb
with
85 additions
and
22 deletions
app/services/search_service.rb
+
11
−
12
View file @
0c071080
...
...
@@ -21,17 +21,20 @@ class SearchService
get_thumbnail
=
nil
get_type
=
nil
if
@search
.
learning_object?
params_hash
=
{
fields:
[
'name^10'
,
'description'
,
'author'
]
}
get_thumbnail
=
Proc
.
new
{
|
obj
|
image_path
(
obj
.
default_thumbnail
)
}
params_hash
=
{
where:
{
state:
validate_object
},
fields:
[
'name^10'
,
'description'
,
'author'
]
}
get_thumbnail
=
Proc
.
new
{
|
obj
|
obj
.
default_thumbnail
}
get_type
=
Proc
.
new
{
|
obj
|
obj
.
object_type
.
try
(
:name
)
}
elsif
@search
.
collection?
params_hash
=
{
where:
{
privacy:
"public"
},
fields:
[
'name^10'
,
'description'
,
'owner'
]
}
get_thumbnail
=
Proc
.
new
{
|
obj
|
image_path
(
"/assets/icons/collection"
)
}
get_thumbnail
=
Proc
.
new
{
|
obj
|
"/assets/icons/collection"
}
get_type
=
Proc
.
new
{
|
obj
|
"Collection"
}
else
else
#User
params_hash
=
{
fields:
[
'name'
]
}
get_thumbnail
=
Proc
.
new
{
|
obj
|
image_path
(
obj
.
avatar
.
url
(
:thumb
)
,
32
)
}
get_thumbnail
=
Proc
.
new
{
|
obj
|
obj
.
avatar
.
url
(
:thumb
)
}
get_type
=
Proc
.
new
{
|
obj
|
"User"
}
end
...
...
@@ -45,7 +48,7 @@ class SearchService
end
def
search_learning_object
LearningObject
.
search
(
@search
.
query
,
where:
where_hash
,
order:
lo_order_hash
(
@search
.
order
),
page:
@search
.
page
,
per_page:
@search
.
results_per_page
).
results
LearningObject
.
search
(
@search
.
query
,
where:
lo_
where_hash
,
order:
lo_order_hash
(
@search
.
order
),
page:
@search
.
page
,
per_page:
@search
.
results_per_page
).
results
end
def
search_collection
...
...
@@ -58,7 +61,7 @@ class SearchService
def
autocomplete_search
(
search_class
,
query
,
params_hash
=
{},
get_type
,
get_thumbnail
)
response
=
[]
search_params
=
{
limit:
10
,
misspellings:
{
below:
5
}
,
where:
{
state:
validate_object
}
}
search_params
=
{
limit:
10
,
misspellings:
{
below:
5
}
}
objs
=
search_class
.
search
(
query
,
search_params
.
merge
(
params_hash
))
objs
.
each
do
|
obj
|
hash
=
{}
...
...
@@ -71,7 +74,7 @@ class SearchService
response
end
def
where_hash
def
lo_
where_hash
hash
=
{}
hash
[
:tags
]
=
@search
.
tags
unless
@search
.
tags
.
blank?
hash
[
:object_type
]
=
@search
.
types
unless
@search
.
types
.
blank?
...
...
@@ -123,8 +126,4 @@ class SearchService
return
[
'published'
,
'suspended'
,
'draft'
]
end
def
image_path
(
image
,
width
=
56
,
height
=
32
)
ActionController
::
Base
.
helpers
.
path_to_image
image
,
width:
width
,
height:
height
end
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/services/search_service_test.rb
+
74
−
10
View file @
0c071080
...
...
@@ -2,23 +2,87 @@ require 'test_helper'
class
SearchServiceTest
<
ActiveSupport
::
TestCase
test
'fetch with all search params'
do
LearningObject
.
reindex
LearningObject
.
searchkick_index
.
refresh
#FIXME: tags not working
params
=
{
:page
=>
1
,
:results_per_page
=>
10
,
:order
=>
'score'
,
test
'fetch learning object with all search params'
do
reindex
LearningObject
service
=
SearchService
.
new
(
Search
.
new
(
los_complete_search
),
users
(
:john
))
assert_equal
[
learning_objects
(
:search
)],
service
.
fetch
end
test
'fetch all public collections'
do
reindex
Collection
service
=
SearchService
.
new
(
Search
.
new
(
collections_search
),
users
(
:john
))
assert_equal
[
collections
(
:ufpr
)],
service
.
fetch
end
test
'fetch users named john'
do
reindex
User
service
=
SearchService
.
new
(
Search
.
new
(
users_john_search
),
users
(
:john
))
assert_equal
[
users
(
:john
),
users
(
:one
)],
service
.
fetch
end
test
'autocomplete users named john'
do
reindex
User
service
=
SearchService
.
new
(
Search
.
new
(
users_john
),
users
(
:john
))
assert_equal
users_autocomplete_hashes
([
users
(
:john
),
users
(
:one
)]),
service
.
autocomplete
end
private
def
los_complete_search
default_params
.
merge
({
:query
=>
'teste'
,
:search_class
=>
'LearningObject'
,
:tags
=>
[
'Matemática'
],
:types
=>
[
'Imagem'
],
:sources
=>
[
'UFPR institution'
]
})
end
def
collections_search
default_params
.
merge
({
:search_class
=>
'Collection'
})
end
def
users_john_search
default_params
.
merge
(
users_john
)
end
def
users_john
{
:query
=>
'John'
,
:search_class
=>
'User'
}
end
service
=
SearchService
.
new
(
Search
.
new
(
params
),
users
(
:john
))
assert_equal
[
learning_objects
(
:search
)],
service
.
fetch
def
default_params
{
:page
=>
1
,
:results_per_page
=>
10
,
:order
=>
'score'
}
end
def
reindex
(
klass
)
klass
.
reindex
klass
.
searchkick_index
.
refresh
end
def
users_autocomplete_hashes
(
users
=
[])
hashes
=
[]
users
.
each
do
|
user
|
hash
=
{}
hash
[
"id"
]
=
user
.
id
hash
[
"name"
]
=
user
.
name
hash
[
"type"
]
=
"User"
hash
[
"thumbnail"
]
=
user
.
avatar
.
url
(
:thumb
)
hashes
<<
hash
end
hashes
end
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment