Browse Source

Evolution #745: Optimisation recherche de tags

Sevajol Bastien 11 years ago
parent
commit
28a9f7a147

+ 1 - 1
src/Muzich/AdminBundle/Resources/config/Admin_tag-generator.yml View File

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

+ 6 - 0
src/Muzich/CoreBundle/DataFixtures/ORM/LoadTagData.php View File

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

+ 16 - 0
src/Muzich/CoreBundle/Entity/Tag.php View File

105
   protected $arguments;
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
   public function __construct()
116
   public function __construct()
260
     $this->arguments = $arguments;
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 View File

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
    * Test de l'ordre dans lequel les tags sont retourné
87
    * Test de l'ordre dans lequel les tags sont retourné
65
    */
88
    */

+ 3 - 2
src/Muzich/CoreBundle/Util/TagLike.php View File

157
     {
157
     {
158
       if ($where == '')
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
       else
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
       $params['str'.$i] = '%'.$word.'%';
167
       $params['str'.$i] = '%'.$word.'%';
168
+      $params['strlike'.$i] = '%'.$word.'%';
168
     }
169
     }
169
 
170
 
170
     $private_tags_sql = '';
171
     $private_tags_sql = '';