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
2015-12-29 15:37:13 +0000
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
445f939822df06e89b136b6be00c1cde05582d33
445f9398
1 parent
05c4b208
Fixed issue with searching invalid chars and page-content compiliation
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
10 deletions
app/Entity.php
app/Repos/BookRepo.php
app/Repos/ChapterRepo.php
app/Repos/PageRepo.php
resources/views/pages/page-display.blade.php
tests/EntityTest.php
app/Entity.php
View file @
445f939
...
...
@@ -115,12 +115,12 @@ abstract class Entity extends Model
{
$termString
=
''
;
foreach
(
$terms
as
$term
)
{
$termString
.=
$term
.
'* '
;
$termString
.=
htmlentities
(
$term
)
.
'* '
;
}
$fields
=
implode
(
','
,
$fieldsToSearch
);
$termStringEscaped
=
\DB
::
connection
()
->
getPdo
()
->
quote
(
$termString
);
$search
=
static
::
addSelect
(
\DB
::
raw
(
'*, MATCH(name) AGAINST('
.
$termStringEscaped
.
' IN BOOLEAN MODE) AS title_relevance'
));
$search
=
$search
->
whereRaw
(
'MATCH('
.
$fields
.
') AGAINST(? IN BOOLEAN MODE)'
,
[
$termString
]);
$search
=
$search
->
whereRaw
(
'MATCH('
.
$fields
.
') AGAINST(? IN BOOLEAN MODE)'
,
[
$termString
Escaped
]);
// Add additional where terms
foreach
(
$wheres
as
$whereTerm
)
{
...
...
app/Repos/BookRepo.php
View file @
445f939
...
...
@@ -222,9 +222,9 @@ class BookRepo
*/
public
function
getBySearch
(
$term
)
{
$terms
=
explode
(
' '
,
preg_quote
(
trim
(
$term
))
);
$terms
=
explode
(
' '
,
$term
);
$books
=
$this
->
book
->
fullTextSearch
([
'name'
,
'description'
],
$terms
);
$words
=
join
(
'|'
,
$terms
);
$words
=
join
(
'|'
,
explode
(
' '
,
preg_quote
(
trim
(
$term
),
'/'
))
);
foreach
(
$books
as
$book
)
{
//highlight
$result
=
preg_replace
(
'#'
.
$words
.
'#iu'
,
"<span class=
\"
highlight
\"
>
\$
0</span>"
,
$book
->
getExcerpt
(
100
));
...
...
app/Repos/ChapterRepo.php
View file @
445f939
...
...
@@ -129,9 +129,9 @@ class ChapterRepo
*/
public
function
getBySearch
(
$term
,
$whereTerms
=
[])
{
$terms
=
explode
(
' '
,
preg_quote
(
trim
(
$term
))
);
$terms
=
explode
(
' '
,
$term
);
$chapters
=
$this
->
chapter
->
fullTextSearch
([
'name'
,
'description'
],
$terms
,
$whereTerms
);
$words
=
join
(
'|'
,
$terms
);
$words
=
join
(
'|'
,
explode
(
' '
,
preg_quote
(
trim
(
$term
),
'/'
))
);
foreach
(
$chapters
as
$chapter
)
{
//highlight
$result
=
preg_replace
(
'#'
.
$words
.
'#iu'
,
"<span class=
\"
highlight
\"
>
\$
0</span>"
,
$chapter
->
getExcerpt
(
100
));
...
...
app/Repos/PageRepo.php
View file @
445f939
...
...
@@ -177,11 +177,11 @@ class PageRepo
*/
public
function
getBySearch
(
$term
,
$whereTerms
=
[])
{
$terms
=
explode
(
' '
,
preg_quote
(
trim
(
$term
))
);
$terms
=
explode
(
' '
,
$term
);
$pages
=
$this
->
page
->
fullTextSearch
([
'name'
,
'text'
],
$terms
,
$whereTerms
);
// Add highlights to page text.
$words
=
join
(
'|'
,
$terms
);
$words
=
join
(
'|'
,
explode
(
' '
,
preg_quote
(
trim
(
$term
),
'/'
))
);
//lookahead/behind assertions ensures cut between words
$s
=
'\s\x00-/:-@\[-`{-~'
;
//character set for start/end of words
...
...
resources/views/pages/page-display.blade.php
View file @
445f939
<h1
id=
"bkmrk-page-title"
>
{{$page->name}}
</h1>
<div
v-pre
>
<h1
id=
"bkmrk-page-title"
>
{{$page->name}}
</h1>
{!! $page->html !!}
\ No newline at end of file
{!! $page->html !!}
</div>
\ No newline at end of file
...
...
tests/EntityTest.php
View file @
445f939
...
...
@@ -170,6 +170,16 @@ class EntityTest extends TestCase
->
seePageIs
(
$page
->
getUrl
());
}
public
function
testInvalidPageSearch
()
{
$this
->
asAdmin
()
->
visit
(
'/'
)
->
type
(
'<p>test</p>'
,
'term'
)
->
press
(
'header-search-box-button'
)
->
see
(
'Search Results'
)
->
seeStatusCode
(
200
);
}
public
function
testEntitiesViewableAfterCreatorDeletion
()
{
...
...
Please
register
or
sign in
to post a comment