我正在构建一个web应用程序,并且在这个应用程序(Codeigniter和MongoDB)中,我让人们通过标签搜索文件。例如,如果他们进入标签房屋和猫,他们会得到与其匹配的所有文件。标签被收集在一个数组中($ tags)。
这是我查找查询的方式:
select ($select) -> where_in_all ('tags', $tags) -> get ('uploaded_files');上述查询工作正常,但我真的需要让用户搜索部分标签。像“侯”而不是“房子”。我知道如何做一个类似的查询,但一次只能为一个标签。我怎样才能使in_array搜索工作?
我正在使用vesparny的优秀MongoDB包装器。这是用于正常in_array搜索的包装中的代码:
public function where_in_all($field = "", $in = array()){
$this->_where_init($field);
$this->wheres[$field]['$all'] = $in;
return ($this);
}这是我修改它不起作用的尝试:
public function where_in_all_like($field = "", $in = array()){
$this->_where_init($field);
$this->wheres[$field]['$all'] = new MongoRegex('/'.$in.'/i');
return ($this);
}我究竟做错了什么?
包装可以在这里找到:
https://github.com/vesparny/cimongo-codeigniter-mongodb-library感谢所有帮助!
更新
这似乎工作,但只在我的本地服务器上......不在生产服务器上。
public function where_in_all_like($field = "", $in = array()){
$newarray = array ();
foreach ($in as $value) {
array_push ($newarray, new MongoRegex('/'.$value.'/i'));
}
$this->_where_init($field);
$this->wheres[$field]['$all'] = $newarray;
return ($this);
}更新2
我将我的服务器上的MongoDB更新到2.0.4,现在工作正常。