Refactored search-based code to its own folder

Also applied StyleCI changes
This commit is contained in:
Dan Brown 2022-08-16 11:27:22 +01:00
parent 2b06e86d53
commit 837fd74bf6
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
16 changed files with 31 additions and 45 deletions

View File

@ -74,9 +74,8 @@ class PermissionApplicator
}
foreach ($chain as $currentEntity) {
if (is_null($currentEntity->restricted)) {
throw new InvalidArgumentException("Entity restricted field used but has not been loaded");
throw new InvalidArgumentException('Entity restricted field used but has not been loaded');
}
if ($currentEntity->restricted) {

View File

@ -249,6 +249,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
}
$this->avatarUrl = $avatar;
return $avatar;
}

View File

@ -3,7 +3,7 @@
namespace BookStack\Console\Commands;
use BookStack\Entities\Models\Entity;
use BookStack\Entities\Tools\SearchIndex;
use BookStack\Search\SearchIndex;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

View File

@ -11,7 +11,6 @@ use BookStack\Auth\Permissions\EntityPermission;
use BookStack\Auth\Permissions\JointPermission;
use BookStack\Auth\Permissions\JointPermissionBuilder;
use BookStack\Auth\Permissions\PermissionApplicator;
use BookStack\Entities\Tools\SearchIndex;
use BookStack\Entities\Tools\SlugGenerator;
use BookStack\Interfaces\Deletable;
use BookStack\Interfaces\Favouritable;
@ -19,6 +18,8 @@ use BookStack\Interfaces\Loggable;
use BookStack\Interfaces\Sluggable;
use BookStack\Interfaces\Viewable;
use BookStack\Model;
use BookStack\Search\SearchIndex;
use BookStack\Search\SearchTerm;
use BookStack\Traits\HasCreatorAndUpdater;
use BookStack\Traits\HasOwner;
use Carbon\Carbon;

View File

@ -3,9 +3,9 @@
namespace BookStack\Http\Controllers\Api;
use BookStack\Entities\Models\Entity;
use BookStack\Entities\Tools\SearchOptions;
use BookStack\Entities\Tools\SearchResultsFormatter;
use BookStack\Entities\Tools\SearchRunner;
use BookStack\Search\SearchOptions;
use BookStack\Search\SearchResultsFormatter;
use BookStack\Search\SearchRunner;
use Illuminate\Http\Request;
class SearchApiController extends ApiController

View File

@ -27,9 +27,9 @@ class PageRevisionController extends Controller
{
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
$revisions = $page->revisions()->select([
'id', 'page_id', 'name', 'created_at', 'created_by', 'updated_at',
'type', 'revision_number', 'summary',
])
'id', 'page_id', 'name', 'created_at', 'created_by', 'updated_at',
'type', 'revision_number', 'summary',
])
->selectRaw("IF(markdown = '', false, true) as is_markdown")
->with(['page.book', 'createdBy'])
->get();
@ -38,7 +38,7 @@ class PageRevisionController extends Controller
return view('pages.revisions', [
'revisions' => $revisions,
'page' => $page,
'page' => $page,
]);
}

View File

@ -3,10 +3,10 @@
namespace BookStack\Http\Controllers;
use BookStack\Entities\Queries\Popular;
use BookStack\Entities\Tools\SearchOptions;
use BookStack\Entities\Tools\SearchResultsFormatter;
use BookStack\Entities\Tools\SearchRunner;
use BookStack\Entities\Tools\SiblingFetcher;
use BookStack\Search\SearchOptions;
use BookStack\Search\SearchResultsFormatter;
use BookStack\Search\SearchRunner;
use Illuminate\Http\Request;
class SearchController extends Controller

View File

@ -1,12 +1,11 @@
<?php
namespace BookStack\Entities\Tools;
namespace BookStack\Search;
use BookStack\Actions\Tag;
use BookStack\Entities\EntityProvider;
use BookStack\Entities\Models\Entity;
use BookStack\Entities\Models\Page;
use BookStack\Entities\Models\SearchTerm;
use DOMDocument;
use DOMNode;
use Illuminate\Database\Eloquent\Builder;

View File

@ -1,30 +1,15 @@
<?php
namespace BookStack\Entities\Tools;
namespace BookStack\Search;
use Illuminate\Http\Request;
class SearchOptions
{
/**
* @var array
*/
public $searches = [];
/**
* @var array
*/
public $exacts = [];
/**
* @var array
*/
public $tags = [];
/**
* @var array
*/
public $filters = [];
public array $searches = [];
public array $exacts = [];
public array $tags = [];
public array $filters = [];
/**
* Create a new instance from a search string.

View File

@ -1,6 +1,6 @@
<?php
namespace BookStack\Entities\Tools;
namespace BookStack\Search;
use BookStack\Actions\Tag;
use BookStack\Entities\Models\Entity;

View File

@ -1,6 +1,6 @@
<?php
namespace BookStack\Entities\Tools;
namespace BookStack\Search;
use BookStack\Auth\Permissions\PermissionApplicator;
use BookStack\Auth\User;
@ -8,7 +8,6 @@ use BookStack\Entities\EntityProvider;
use BookStack\Entities\Models\BookChild;
use BookStack\Entities\Models\Entity;
use BookStack\Entities\Models\Page;
use BookStack\Entities\Models\SearchTerm;
use Illuminate\Database\Connection;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
@ -29,7 +28,7 @@ class SearchRunner
*
* @var string[]
*/
protected $queryOperators = ['<=', '>=', '=', '<', '>', 'like', '!='];
protected array $queryOperators = ['<=', '>=', '=', '<', '>', 'like', '!='];
/**
* Retain a cache of score adjusted terms for specific search options.

View File

@ -1,6 +1,6 @@
<?php
namespace BookStack\Entities\Models;
namespace BookStack\Search;
use BookStack\Model;

View File

@ -10,7 +10,7 @@ use BookStack\Auth\User;
use BookStack\Entities\Models\Bookshelf;
use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Page;
use BookStack\Entities\Tools\SearchIndex;
use BookStack\Search\SearchIndex;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

View File

@ -8,7 +8,7 @@ use BookStack\Auth\User;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Page;
use BookStack\Entities\Tools\SearchIndex;
use BookStack\Search\SearchIndex;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;

View File

@ -2,7 +2,7 @@
namespace Tests\Entity;
use BookStack\Entities\Tools\SearchOptions;
use BookStack\Search\SearchOptions;
use Tests\TestCase;
class SearchOptionsTest extends TestCase

View File

@ -1,4 +1,6 @@
<?php namespace Tests;
<?php
namespace Tests;
use BookStack\Actions\Favourite;
use BookStack\Auth\User;