Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

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; ...@@ -9,7 +9,7 @@ use Doctrine\ORM\Mapping\Index;
/** /**
* @ORM\Table(name="lexicon_root", indexes={ * @ORM\Table(name="lexicon_root", indexes={
* @Index(columns={"value"}, flags={"fulltext"}), * @Index(columns={"value"}, name="fulltext"),
* @Index(name="language", columns={"language_id"}), * @Index(name="language", columns={"language_id"}),
* }) * })
* @ORM\Entity(repositoryClass="LexiconBundle\Repository\RootRepository") * @ORM\Entity(repositoryClass="LexiconBundle\Repository\RootRepository")
......
...@@ -27,17 +27,18 @@ class RootManager ...@@ -27,17 +27,18 @@ class RootManager
public function findOrCreate(Language $language, $value, &$roots) public function findOrCreate(Language $language, $value, &$roots)
{ {
if (!isset($roots[$value])) { if (!isset($roots[$value])) {
$rootId = $this->em->getRepository(Root::class)->search($value, $language->getId()); $root = $this->em->getRepository(Root::class)->findOneBy([
if (empty($rootId)) { "value" => $value,
"language" => $language
]);
if (!$root) {
$root = new Root; $root = new Root;
$root->setLanguage($language); $root->setLanguage($language);
$root->setValue($value); $root->setValue($value);
$this->em->persist($root); $this->em->persist($root);
$roots[$value] = $root; $roots[$value] = $root;
} else {
$rootId = $rootId[0]["id"];
$root = $this->em->getRepository(Root::class)->find($rootId);
} }
return $root; return $root;
......
...@@ -37,15 +37,4 @@ class RootRepository extends \Doctrine\ORM\EntityRepository ...@@ -37,15 +37,4 @@ class RootRepository extends \Doctrine\ORM\EntityRepository
return $query->getResult(); 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