Parcourir la source

Evolution #745: Optimisation recherche de tags

Sevajol Bastien il y a 11 ans
Parent
révision
28a9f7a147

+ 1 - 1
src/Muzich/AdminBundle/Resources/config/Admin_tag-generator.yml Voir le fichier

@@ -33,7 +33,7 @@ builders:
33 33
     params:
34 34
       title: "You're editing element \"%object%\"|{ %object%: Tag.name }|"
35 35
       display:
36
-        "General" : [ name ]
36
+        "General" : [ name, like_string ]
37 37
       actions:
38 38
         save: ~
39 39
         list: ~

+ 6 - 0
src/Muzich/CoreBundle/DataFixtures/ORM/LoadTagData.php Voir le fichier

@@ -32,6 +32,12 @@ class LoadTagData  extends AbstractFixture implements OrderedFixtureInterface, C
32 32
   {
33 33
     $tag = new Tag();
34 34
     $tag->setName(ucfirst($name));
35
+    
36
+    if ($name == 'Reggae')
37
+    {
38
+      $tag->setLikeString('reggea regea regae rege regge');
39
+    }
40
+    
35 41
     $this->entity_manager->persist($tag);
36 42
     $this->addReference('tag_'.strtolower(str_replace(' ', '-', $name)), $tag);
37 43
   }

+ 16 - 0
src/Muzich/CoreBundle/Entity/Tag.php Voir le fichier

@@ -105,6 +105,12 @@ class Tag
105 105
   protected $arguments;
106 106
   
107 107
   /**
108
+   * @ORM\Column(type="text", nullable=true)
109
+   * @var type string
110
+   */
111
+  protected $like_string;
112
+  
113
+  /**
108 114
    * 
109 115
    */
110 116
   public function __construct()
@@ -260,4 +266,14 @@ class Tag
260 266
     $this->arguments = $arguments;
261 267
   }
262 268
   
269
+  public function setLikeString($like_string)
270
+  {
271
+    $this->like_string = $like_string;
272
+  }
273
+  
274
+  public function getLikeString()
275
+  {
276
+    return $this->like_string;
277
+  }
278
+  
263 279
 }

+ 23 - 0
src/Muzich/CoreBundle/Tests/Tag/TagReadTest.php Voir le fichier

@@ -60,6 +60,29 @@ class TagReadTest extends UnitTest
60 60
     }
61 61
   }
62 62
   
63
+  
64
+  /**
65
+   * Simple test des tags retournés
66
+   */
67
+  public function testSearchTagLike()
68
+  {
69
+    $bux = $this->getUser('bux');
70
+    
71
+    $cresults = array(
72
+      'Reggae'
73
+    );
74
+    
75
+    $TagLike = new TagLike($this->getDoctrine()->getEntityManager());
76
+    $response = $TagLike->getSimilarTags('reggea', $bux->getId());
77
+    
78
+    $this->assertEquals(count($cresults), count($response['tags']));
79
+    
80
+    foreach ($response['tags'] as $tag)
81
+    {
82
+      $this->assertTrue(in_array($tag['name'], $cresults));
83
+    }
84
+  }
85
+  
63 86
   /**
64 87
    * Test de l'ordre dans lequel les tags sont retourné
65 88
    */

+ 3 - 2
src/Muzich/CoreBundle/Util/TagLike.php Voir le fichier

@@ -157,14 +157,15 @@ class TagLike
157 157
     {
158 158
       if ($where == '')
159 159
       {
160
-        $where .= 'WHERE UPPER(t.slug) LIKE :str'.$i;
160
+        $where .= 'WHERE UPPER(t.slug) LIKE :str'.$i.' OR UPPER(t.like_string) LIKE :strlike'.$i;
161 161
       }
162 162
       else
163 163
       {
164
-        $where .= ' OR UPPER(t.slug) LIKE :str'.$i;
164
+        $where .= ' OR UPPER(t.slug) LIKE :str'.$i.' OR UPPER(t.like_string) LIKE :strlike'.$i;
165 165
       }
166 166
 
167 167
       $params['str'.$i] = '%'.$word.'%';
168
+      $params['strlike'.$i] = '%'.$word.'%';
168 169
     }
169 170
 
170 171
     $private_tags_sql = '';