ajmorenodelarosa / mongosearch
该包允许您使用mongo 2.4的文本搜索功能
dev-master
2014-02-10 17:09 UTC
This package is not auto-updated.
Last update: 2024-09-24 05:40:20 UTC
README
安装
您实际上如何下载此包完全取决于您。最简单的方法是从packagist.org获取。
https://packagist.org.cn/packages/ajmorenodelarosa/mongosearch
使用示例
首先,您必须在您的文档定义中使用"text"索引
* @MongoDB\Index(keys={"field"="text"})
最基本的搜索会是
$db = $this->get('doctrine_mongodb')->getManager(); $finder = $this->get('mongosearch.finder')->finder('UserManagementBundle:User',$db); $finder->find("test");
我们将使用我们的服务中的finder方法创建一个查找对象,这将允许我们使用任何字符串在我们的集合中进行查找。您还可以执行分页搜索,例如
$limit = 10; $offset = $current_page*$limit; $db = $this->get('doctrine_mongodb')->getManager(); $finder = $this->get('mongosearch.finder')->finder('UserManagementBundle:User',$db); $finder->find("test", $limit, $offset);
我们可以添加筛选条件来执行查询
$db = $this->get('doctrine_mongodb')->getManager(); $finder = $this->get('mongosearch.finder')->finder('UserManagementBundle:User',$db); $finder->find("test", $limit, $offset, array("role"=>"ROLE_ADMIN"));
许可证
Copyright (c) 2014, Antonio José Moreno de la Rosa
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.