2012-07-27 34 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