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
2016-08-25 17:17:26 +0100
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
f83de5f8342ca2038371bcb2d0545014a37e0508
f83de5f8
1 parent
f2ceba97
Fixed single word quoted search terms
Fixes #170
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
7 deletions
app/Entity.php
app/Repos/EntityRepo.php
tests/Entity/EntitySearchTest.php
app/Entity.php
View file @
f83de5f
...
...
@@ -167,7 +167,8 @@ class Entity extends Ownable
foreach
(
$terms
as
$key
=>
$term
)
{
$term
=
htmlentities
(
$term
,
ENT_QUOTES
);
$term
=
preg_replace
(
'/[+\-><\(\)~*\"@]+/'
,
' '
,
$term
);
if
(
preg_match
(
'/\s/'
,
$term
))
{
if
(
preg_match
(
'/".*?"/'
,
$term
))
{
$term
=
str_replace
(
'"'
,
''
,
$term
);
$exactTerms
[]
=
'%'
.
$term
.
'%'
;
$term
=
'"'
.
$term
.
'"'
;
}
else
{
...
...
@@ -206,5 +207,5 @@ class Entity extends Ownable
return
$search
->
orderBy
(
$orderBy
,
'desc'
);
}
}
...
...
app/Repos/EntityRepo.php
View file @
f83de5f
...
...
@@ -168,15 +168,16 @@ class EntityRepo
* @param $termString
* @return array
*/
p
rotected
function
prepareSearchTerms
(
$termString
)
p
ublic
function
prepareSearchTerms
(
$termString
)
{
$termString
=
$this
->
cleanSearchTermString
(
$termString
);
preg_match_all
(
'/"(.*?)"/'
,
$termString
,
$matches
);
preg_match_all
(
'/(".*?")/'
,
$termString
,
$matches
);
$terms
=
[];
if
(
count
(
$matches
[
1
])
>
0
)
{
$terms
=
$matches
[
1
];
foreach
(
$matches
[
1
]
as
$match
)
{
$terms
[]
=
$match
;
}
$termString
=
trim
(
preg_replace
(
'/"(.*?)"/'
,
''
,
$termString
));
}
else
{
$terms
=
[];
}
if
(
!
empty
(
$termString
))
$terms
=
array_merge
(
$terms
,
explode
(
' '
,
$termString
));
return
$terms
;
...
...
tests/Entity/EntitySearchTest.php
View file @
f83de5f
...
...
@@ -76,6 +76,14 @@ class EntitySearchTest extends TestCase
->
see
(
'Chapter Search Results'
)
->
seeInElement
(
'.entity-list'
,
$chapter
->
name
);
}
public
function
test_search_quote_term_preparation
()
{
$termString
=
'"192" cat "dog hat"'
;
$repo
=
$this
->
app
[
\BookStack\Repos\EntityRepo
::
class
];
$preparedTerms
=
$repo
->
prepareSearchTerms
(
$termString
);
$this
->
assertTrue
(
$preparedTerms
===
[
'"192"'
,
'"dog hat"'
,
'cat'
]);
}
public
function
test_books_search_listing
()
{
$book
=
\BookStack\Book
::
all
()
->
last
();
...
...
Please
register
or
sign in
to post a comment