2012-07-27 33 views
0

我對數據庫中的索引不太瞭解,所以我的問題可能很愚蠢,但... 我有人(姓名,組織,工作等)的參數, M在prePersist()方法,東西創建索引串是這樣的:通過分解字符串「」按指數與原則搜索

$this->search_index = $this->name.' '.$this->surname.' '.$this->orgnaization; 

與進一步的搜索,並且比較使用LIKE與search_index每個部分。

但是這看起來很瘋狂。最佳做法是什麼? p.s.我的示例代碼:

$queryBuilder = $this->createQueryBuilder('s'); 
foreach(explode(" ", $query) as $key=>$part){ 
    $queryBuilder->orWhere('s.searchindex LIKE:name'.$key) 
      ->setParameter('name'.$key, $part); 
} 

回答

0

如果我明白你正確的,我猜,則看到的是這樣的:

$collection = Doctrine::getTable('User')->createQuery('u'); 
    ->where('column_name LIKE ?', $this->name) 
    ->orWhere('column_surname LIKE ?', $this->surname) 
    ->orWhere('column_organization LIKE ?', $this->organization) 
    ->execute(); 
+0

這樣的問題,即用戶可以像這樣進入了一句:「約翰工程師史蒂文森「 – user1081056 2012-07-27 11:21:45