FEATURE: add parent class for all search engines
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
<?php
|
||||
namespace App\Handlers\Search;
|
||||
|
||||
use App\Handlers\Contracts\SearchHandler;
|
||||
use App\Models\Content as ContentModel;
|
||||
|
||||
class Content implements SearchHandler
|
||||
class Content extends Search
|
||||
{
|
||||
/**
|
||||
* Search for given patttern/term
|
||||
@@ -15,14 +14,14 @@ class Content implements SearchHandler
|
||||
*/
|
||||
public function search($term)
|
||||
{
|
||||
$token = '%' . $term . '%';
|
||||
$token = $this->tokenize($term);
|
||||
|
||||
return ContentModel::where('content', 'LIKE', $token)
|
||||
->orWhere('meta_description', 'LIKE', $token)
|
||||
->orWhere('meta_keywords', 'LIKE', $token)
|
||||
->orWhere('title', 'LIKE', $token)
|
||||
->orWhere('url', 'LIKE', $token)
|
||||
->get();
|
||||
->orWhere('meta_description', 'LIKE', $token)
|
||||
->orWhere('meta_keywords', 'LIKE', $token)
|
||||
->orWhere('title', 'LIKE', $token)
|
||||
->orWhere('url', 'LIKE', $token)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getId()
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace App\Handlers\Search;
|
||||
|
||||
use App\Handlers\Contracts\SearchHandler;
|
||||
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
||||
|
||||
abstract class Search implements SearchHandler
|
||||
{
|
||||
/**
|
||||
* Tokenize string for usage in LIKE clausules
|
||||
*
|
||||
* @param $term
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function tokenize($term)
|
||||
{
|
||||
$term = trim($term);
|
||||
|
||||
if (empty($term)) {
|
||||
throw new InvalidArgumentException(trans('search.emptyString'));
|
||||
}
|
||||
|
||||
return '%' . str_replace(' ', '%', $term) . '%';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user