diff --git a/bin/generate_db.php b/bin/generate_db.php index ed9e293..94237e3 100644 --- a/bin/generate_db.php +++ b/bin/generate_db.php @@ -31,8 +31,10 @@ $classes = $metadatas; // ); // $tool->getCreateDatabaseSQL(); -$queries = $tool->getCreateSchemaSQL($classes); -// $queries = $tool->getUpdateSchemaSql($classes); +// $queries = $tool->getCreateSchemaSQL($classes); +$queries = $tool->getUpdateSchemaSql($classes); +var_dump($queries); +die() foreach($queries as $sql){ echo "$sql;\n"; } // updateSchema $tool->updateSchema($classes); diff --git a/src/Models/Hit.php b/src/Models/Hit.php index c2a70bb..ca42c82 100644 --- a/src/Models/Hit.php +++ b/src/Models/Hit.php @@ -9,7 +9,15 @@ use Doctrine\Common\Collections\ArrayCollection; /** * Hit of a target and the facial parameters at the moment of the hit * - * @ORM\Table(name="hits") + * @ORM\Table(name="hits", indexes={ + * @Index(name="imgAnger", columns={"hasImage", "anger"}), + * @Index(name="imgContempt", columns={"hasImage", "contempt"}), + * @Index(name="imgDisgust", columns={"hasImage", "disgust"}), + * @Index(name="imgFear", columns={"hasImage", "fear"}), + * @Index(name="imgJoy", columns={"hasImage", "joy"}), + * @Index(name="imgSadness", columns={"hasImage", "sadness"}), + * @Index(name="imgSurprise", columns={"hasImage", "surprise"}), + * }) * @ORM\Entity * @ORM\Entity(repositoryClass="EmotionHero\Models\HitRepository") */ diff --git a/src/Models/HitRepository.php b/src/Models/HitRepository.php index 3452264..4dc9ad4 100644 --- a/src/Models/HitRepository.php +++ b/src/Models/HitRepository.php @@ -39,7 +39,8 @@ class HitRepository extends EntityRepository } $query = $this->_em->createQuery( - "SELECT h, ABS(:score - h.emotions.$emotionField) as HIDDEN distance, RAND() AS HIDDEN lala FROM ".Hit::class." h WHERE h.hasImage = :has ORDER BY distance ASC, lala" + // add BETWEEN so we can use _some_ keying to improve performance. + "SELECT h, ABS(:score - h.emotions.$emotionField) as HIDDEN distance, RAND() AS HIDDEN lala FROM ".Hit::class." h WHERE h.hasImage = :has AND h.emotions.$emotionField BETWEEN :score - 5 AND :score + 5 ORDER BY distance ASC, lala" ) ->setParameters([ 'score' => $score,