mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
Closes #70.
Added the ability to search by multi-word terms using double quotes.
This commit is contained in:
parent
54e3122540
commit
5681f4dd69
@ -226,7 +226,14 @@ class BookRepo
|
|||||||
*/
|
*/
|
||||||
public function getBySearch($term, $count = 20, $paginationAppends = [])
|
public function getBySearch($term, $count = 20, $paginationAppends = [])
|
||||||
{
|
{
|
||||||
$terms = explode(' ', $term);
|
preg_match_all('/"(.*?)"/', $term, $matches);
|
||||||
|
if (count($matches[1]) > 0) {
|
||||||
|
$terms = $matches[1];
|
||||||
|
$term = trim(preg_replace('/"(.*?)"/', '', $term));
|
||||||
|
} else {
|
||||||
|
$terms = [];
|
||||||
|
}
|
||||||
|
$terms = array_merge($terms, explode(' ', $term));
|
||||||
$books = $this->book->fullTextSearchQuery(['name', 'description'], $terms)
|
$books = $this->book->fullTextSearchQuery(['name', 'description'], $terms)
|
||||||
->paginate($count)->appends($paginationAppends);
|
->paginate($count)->appends($paginationAppends);
|
||||||
$words = join('|', explode(' ', preg_quote(trim($term), '/')));
|
$words = join('|', explode(' ', preg_quote(trim($term), '/')));
|
||||||
|
@ -131,7 +131,14 @@ class ChapterRepo
|
|||||||
*/
|
*/
|
||||||
public function getBySearch($term, $whereTerms = [], $count = 20, $paginationAppends = [])
|
public function getBySearch($term, $whereTerms = [], $count = 20, $paginationAppends = [])
|
||||||
{
|
{
|
||||||
$terms = explode(' ', $term);
|
preg_match_all('/"(.*?)"/', $term, $matches);
|
||||||
|
if (count($matches[1]) > 0) {
|
||||||
|
$terms = $matches[1];
|
||||||
|
$term = trim(preg_replace('/"(.*?)"/', '', $term));
|
||||||
|
} else {
|
||||||
|
$terms = [];
|
||||||
|
}
|
||||||
|
$terms = array_merge($terms, explode(' ', $term));
|
||||||
$chapters = $this->chapter->fullTextSearchQuery(['name', 'description'], $terms, $whereTerms)
|
$chapters = $this->chapter->fullTextSearchQuery(['name', 'description'], $terms, $whereTerms)
|
||||||
->paginate($count)->appends($paginationAppends);
|
->paginate($count)->appends($paginationAppends);
|
||||||
$words = join('|', explode(' ', preg_quote(trim($term), '/')));
|
$words = join('|', explode(' ', preg_quote(trim($term), '/')));
|
||||||
|
@ -201,7 +201,14 @@ class PageRepo
|
|||||||
*/
|
*/
|
||||||
public function getBySearch($term, $whereTerms = [], $count = 20, $paginationAppends = [])
|
public function getBySearch($term, $whereTerms = [], $count = 20, $paginationAppends = [])
|
||||||
{
|
{
|
||||||
$terms = explode(' ', $term);
|
preg_match_all('/"(.*?)"/', $term, $matches);
|
||||||
|
if (count($matches[1]) > 0) {
|
||||||
|
$terms = $matches[1];
|
||||||
|
$term = trim(preg_replace('/"(.*?)"/', '', $term));
|
||||||
|
} else {
|
||||||
|
$terms = [];
|
||||||
|
}
|
||||||
|
$terms = array_merge($terms, explode(' ', $term));
|
||||||
$pages = $this->page->fullTextSearchQuery(['name', 'text'], $terms, $whereTerms)
|
$pages = $this->page->fullTextSearchQuery(['name', 'text'], $terms, $whereTerms)
|
||||||
->paginate($count)->appends($paginationAppends);
|
->paginate($count)->appends($paginationAppends);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user