Commit 6ed0b643 authored by Arnaud Bey's avatar Arnaud Bey
Browse files

root index

parent 83b758f1
......@@ -9,7 +9,7 @@ use Doctrine\ORM\Mapping\Index;
/**
* @ORM\Table(name="lexicon_root", indexes={
* @Index(columns={"value"}, flags={"fulltext"}),
* @Index(columns={"value"}, name="fulltext"),
* @Index(name="language", columns={"language_id"}),
* })
* @ORM\Entity(repositoryClass="LexiconBundle\Repository\RootRepository")
......
......@@ -27,17 +27,18 @@ class RootManager
public function findOrCreate(Language $language, $value, &$roots)
{
if (!isset($roots[$value])) {
$rootId = $this->em->getRepository(Root::class)->search($value, $language->getId());
if (empty($rootId)) {
$root = $this->em->getRepository(Root::class)->findOneBy([
"value" => $value,
"language" => $language
]);
if (!$root) {
$root = new Root;
$root->setLanguage($language);
$root->setValue($value);
$this->em->persist($root);
$roots[$value] = $root;
} else {
$rootId = $rootId[0]["id"];
$root = $this->em->getRepository(Root::class)->find($rootId);
}
return $root;
......
......@@ -37,15 +37,4 @@ class RootRepository extends \Doctrine\ORM\EntityRepository
return $query->getResult();
}
public function search($value, $languageId)
{
$sql = "SELECT id FROM lexicon_root WHERE MATCH(value) AGAINST ('".addslashes($value)."' IN NATURAL LANGUAGE MODE) AND language_id = ".$languageId." LIMIT 1";
$em = $this->_em;
$stmt = $em->getConnection()->prepare($sql);
$stmt->execute();
return $stmt->fetchAll();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment