Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2017-04-15 19:31:11 +0100
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
73844b9eeb7d193236dc44fa8f86991ffed8301d
73844b9e
1 parent
dcde5997
Enabled type search filter in book search
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
3 deletions
app/Services/SearchService.php
app/Services/SearchService.php
View file @
73844b9
...
...
@@ -97,10 +97,16 @@ class SearchService
public
function
searchBook
(
$bookId
,
$searchString
)
{
$terms
=
$this
->
parseSearchString
(
$searchString
);
$entityTypes
=
[
'page'
,
'chapter'
];
$entityTypesToSearch
=
isset
(
$terms
[
'filters'
][
'type'
])
?
explode
(
'|'
,
$terms
[
'filters'
][
'type'
])
:
$entityTypes
;
$results
=
collect
();
$pages
=
$this
->
buildEntitySearchQuery
(
$terms
,
'page'
)
->
where
(
'book_id'
,
'='
,
$bookId
)
->
take
(
20
)
->
get
();
$chapters
=
$this
->
buildEntitySearchQuery
(
$terms
,
'chapter'
)
->
where
(
'book_id'
,
'='
,
$bookId
)
->
take
(
20
)
->
get
();
return
$results
->
merge
(
$pages
)
->
merge
(
$chapters
)
->
sortByDesc
(
'score'
)
->
take
(
20
);
foreach
(
$entityTypesToSearch
as
$entityType
)
{
if
(
!
in_array
(
$entityType
,
$entityTypes
))
continue
;
$search
=
$this
->
buildEntitySearchQuery
(
$terms
,
$entityType
)
->
where
(
'book_id'
,
'='
,
$bookId
)
->
take
(
20
)
->
get
();
$results
=
$results
->
merge
(
$search
);
}
return
$results
->
sortByDesc
(
'score'
)
->
take
(
20
);
}
/**
...
...
Please
register
or
sign in
to post a comment