Fleshing out a bit further
This commit is contained in:
@@ -14,7 +14,14 @@ class SearchService
|
||||
{
|
||||
public function __construct(private EntityManagerInterface $em) {}
|
||||
|
||||
public function index($entity)
|
||||
/**
|
||||
* Given an $entity that implements SearchableInterface, this method
|
||||
* creates or updates a SearchIndex $entity
|
||||
*
|
||||
* @param SearchableInterface $entity
|
||||
* @return void
|
||||
*/
|
||||
public function index(SearchableInterface $entity)
|
||||
{
|
||||
$searchIndex = $this->createSearchResult($entity);
|
||||
|
||||
@@ -22,7 +29,14 @@ class SearchService
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
public function unIndex($entity)
|
||||
/**
|
||||
* Given an $entity that implements SearchableInterface, this method removes
|
||||
* the item from the search index
|
||||
*
|
||||
* @param SearchableInterface $entity
|
||||
* @return void
|
||||
*/
|
||||
public function unIndex(SearchableInterface $entity)
|
||||
{
|
||||
$class = get_class($entity);
|
||||
|
||||
@@ -37,6 +51,14 @@ class SearchService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an entity that implements SearchableInterface, this method first checks
|
||||
* if the relevant SearchIndex entity exists. If it doesn't, it's created. The
|
||||
* title and index data are set based on the methods in the $entity
|
||||
*
|
||||
* @param SearchableInterface $entity
|
||||
* @return SearchIndex
|
||||
*/
|
||||
public function createSearchResult(SearchableInterface $entity): SearchIndex
|
||||
{
|
||||
$values = [];
|
||||
@@ -76,7 +98,8 @@ class SearchService
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all searchable Doctrine entities.
|
||||
* Finds all searchable Doctrine entities the implement SearchableInterface
|
||||
* @return array
|
||||
*/
|
||||
public function getSearchableClasses(): array
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user