Regex mongodb数据库搜索正则表达式
每个文档由“名称、城市和分支机构”组成,然后它们还包含“关键字”,这是“名称、城市和分支机构”的组合版本 我现在需要一个正则表达式,这是我得到的:Regex mongodb数据库搜索正则表达式,regex,mongodb,Regex,Mongodb,每个文档由“名称、城市和分支机构”组成,然后它们还包含“关键字”,这是“名称、城市和分支机构”的组合版本 我现在需要一个正则表达式,这是我得到的: public function searchLocation($keyword){ $result = $this->locations->find(array('keywords' => new MongoRegex('/^' . strtolower($keyword) . '/')));
public function searchLocation($keyword){
$result = $this->locations->find(array('keywords' => new MongoRegex('/^' . strtolower($keyword) . '/')));
if($result){
return $result;
}
return false;
}
问题是,当用户输入“grandcaffee london”时,它不会搜索每个单词,或者当用户插入“Cinema New York”时
谢谢你的阅读 您可以这样做(匹配“格兰德卡菲”或“伦敦”)
或者这个(将文档与“grandcaffee”和“london”匹配)
db.locations.find({keywords: {$in: [/grandcaffee/, /london/]}});
db.locations.find({keywords: {$all: [/grandcaffee/, /london/]}});