mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-04-08 15:50:21 +08:00
parent
f2ceba978a
commit
f83de5f834
@ -167,7 +167,8 @@ class Entity extends Ownable
|
|||||||
foreach ($terms as $key => $term) {
|
foreach ($terms as $key => $term) {
|
||||||
$term = htmlentities($term, ENT_QUOTES);
|
$term = htmlentities($term, ENT_QUOTES);
|
||||||
$term = preg_replace('/[+\-><\(\)~*\"@]+/', ' ', $term);
|
$term = preg_replace('/[+\-><\(\)~*\"@]+/', ' ', $term);
|
||||||
if (preg_match('/\s/', $term)) {
|
if (preg_match('/".*?"/', $term)) {
|
||||||
|
$term = str_replace('"', '', $term);
|
||||||
$exactTerms[] = '%' . $term . '%';
|
$exactTerms[] = '%' . $term . '%';
|
||||||
$term = '"' . $term . '"';
|
$term = '"' . $term . '"';
|
||||||
} else {
|
} else {
|
||||||
|
@ -168,15 +168,16 @@ class EntityRepo
|
|||||||
* @param $termString
|
* @param $termString
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function prepareSearchTerms($termString)
|
public function prepareSearchTerms($termString)
|
||||||
{
|
{
|
||||||
$termString = $this->cleanSearchTermString($termString);
|
$termString = $this->cleanSearchTermString($termString);
|
||||||
preg_match_all('/"(.*?)"/', $termString, $matches);
|
preg_match_all('/(".*?")/', $termString, $matches);
|
||||||
|
$terms = [];
|
||||||
if (count($matches[1]) > 0) {
|
if (count($matches[1]) > 0) {
|
||||||
$terms = $matches[1];
|
foreach ($matches[1] as $match) {
|
||||||
|
$terms[] = $match;
|
||||||
|
}
|
||||||
$termString = trim(preg_replace('/"(.*?)"/', '', $termString));
|
$termString = trim(preg_replace('/"(.*?)"/', '', $termString));
|
||||||
} else {
|
|
||||||
$terms = [];
|
|
||||||
}
|
}
|
||||||
if (!empty($termString)) $terms = array_merge($terms, explode(' ', $termString));
|
if (!empty($termString)) $terms = array_merge($terms, explode(' ', $termString));
|
||||||
return $terms;
|
return $terms;
|
||||||
|
@ -76,6 +76,14 @@ class EntitySearchTest extends TestCase
|
|||||||
->see('Chapter Search Results')->seeInElement('.entity-list', $chapter->name);
|
->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()
|
public function test_books_search_listing()
|
||||||
{
|
{
|
||||||
$book = \BookStack\Book::all()->last();
|
$book = \BookStack\Book::all()->last();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user