Added:
- manga import - read from cbz - save cbz from scrapping - menu interactions
This commit is contained in:
@@ -49,6 +49,49 @@ class MangaRepository extends ServiceEntityRepository
|
||||
->getResult();
|
||||
}
|
||||
|
||||
public function findBySlug(string $slug): array
|
||||
{
|
||||
$this->getEntityManager()->getConnection()->executeStatement('CREATE EXTENSION IF NOT EXISTS fuzzystrmatch');
|
||||
|
||||
$conn = $this->getEntityManager()->getConnection();
|
||||
|
||||
$sql = '
|
||||
SELECT m.*, levenshtein(LOWER(m.slug), LOWER(:slug)) as distance
|
||||
FROM manga m
|
||||
WHERE levenshtein(LOWER(m.slug), LOWER(:slug)) <= :max_distance
|
||||
ORDER BY distance
|
||||
LIMIT 10
|
||||
';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$resultSet = $stmt->executeQuery([
|
||||
'slug' => $slug,
|
||||
'max_distance' => strlen($slug) / 3
|
||||
]);
|
||||
|
||||
$results = $resultSet->fetchAllAssociative();
|
||||
|
||||
$ids = array_column($results, 'id');
|
||||
$entities = $this->findBy(['id' => $ids]);
|
||||
|
||||
$sortedEntities = [];
|
||||
foreach ($results as $result) {
|
||||
foreach ($entities as $entity) {
|
||||
if ($entity->getId() == $result['id']) {
|
||||
$sortedEntities[] = $entity;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $sortedEntities;
|
||||
}
|
||||
|
||||
private function normalizeSlug(string $slug): string
|
||||
{
|
||||
return strtolower(preg_replace('/[^a-z0-9]+/i', '', $slug));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NonUniqueResultException
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user