简体   繁体   English

如何在所有字段中搜索每个单词-Doctrine2

[英]How to search for each word in all fields - Doctrine2

I have a table called Friends are its fields are name, phone, address, skype, birthday and notes. 我有一个名为“ Friends的表,其字段为姓名,电话,地址,Skype,生日和便笺。 There is also a search filed. 还有一个搜索字段。 How to search in all fields? 如何在所有字段中搜索? Will something of this kind work for search word "Ana" and is there a better way? 这样的东西对搜索词"Ana"吗,还有更好的方法吗?

$qb->select('f')
   ->from('Friends', 'f')
   ->where('f.name = :name')
   ->orWhere('f.phone = :phone')->orWhere('f.address = :address')-> ... 
   ->setParameters( array(
     'name' => 'Ana',
     'phone' => 'Ana', ...  ));

And I would also like to ask how to search for each word (something like fulltext search)? 我还想问一下如何搜索每个单词(类似于全文搜索)? I mean if the user writes "Ana Ivan peter@domain.com" to receive all the row, which have in theirs fields (no matter in which field) Ana, Ivan and peter@domain.com. 我的意思是,如果用户写“ Ana Ivan peter@domain.com”来接收所有行,这些行都在其字段中(无论在哪个字段中)Ana,Ivan和peter@domain.com。

For example if Ana and Ivan are the names of two of the friends, but the note for a friend, called John says "A friend of Ivan", and Peter is the name of a friend with email peter@domain.com, the user should receive four rows - Ana, Ivan, John and Peter. 例如,如果安娜和伊万是两个朋友的名字,但说明了一个朋友,叫约翰说:“伊万的朋友”,和彼得是与电子邮件的朋友peter@domain.com,用户名应该会收到四行-安娜,伊万,约翰和彼得。

I'm not sure about this, but I think this may work 我不确定,但是我认为这可能有效

$search_string = '%".$_POST['search']."%';
$qb-> "select 'f' from 'Friends' where f.name LIKE ':search_string' or f.phone  LIKE ':search_string' or ...";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM