RethinkDB和PHP-RQL如何同时过滤+匹配

时间:2016-03-27 14:53:56

标签: php rethinkdb database nosql

我是PHP-RQL的新手,无法弄清楚如何进行像这样的简单SQL查询(旧方法/数据库):

方法1 (默认视图)

$mysql1 = 'SELECT 'html1' FROM  `paging` WHERE `agency` IN ("USER1", "USER2", "USER3") AND `alias` != \'\' ORDER BY  `id` DESC LIMIT 1000';

方法2 如果存在$_GET['search'];(用户搜索)

$mysql2 = " SELECT "html1" FROM  `paging` WHERE  `private` !=  '1' AND  `alias` LIKE  '%". $search . "%' ORDER BY `id` DESC LIMIT 2000"; 

现在这些是我试图从我们当前使用的MySQL中捕获的确切元素,但我们希望切换到RethinkDB。

有人可以向我解释如何在PHP-RQL客户端中获得多个WHERE IN子句吗?与RethinkDB在Java中使用文档的方式有很大不同。 我已阅读以下内容:

RethinkDB版本到目前为止我已经聚在一起了(根本不起作用,我需要一些帮助来理解过滤器和匹配)。

    $agency = "USER1|USER2|USER3";
    $search = (isset($_GET['search']) ? $_GET['search'] : "..");

    require_once("include/rdb/rdb.php");
    $conn = r\connect('127.0.0.1', 28015, "birms");
        $result = r\table('paging')->filter(array(
    'agency' => match->$agency,
    'alias' => match->$search,
    'private' => 'false'))->run($conn);

    foreach ($result as $doc) {
        print_r($doc[$html_src]);
    }

   /* I toyed around with single returns, also didnt work....
    return $doc('agency')->match($agency);
    return $doc('search')->match($search);
    return $doc('private')->match('false');

    This does work; stock standard with no care for the above SQL
    $result = r\table("paging")->orderBy(array('index' => r\desc('js_unique')))->limit(1000)->filter(array('private' => 'false'))->pluck($html_src)->run($conn);
   */

三江源。

1 个答案:

答案 0 :(得分:0)

所以,使用->rAnd我能够解决我的问题。这是代码。希望有些人能够理解这一点。

$agency = "USER1|USER2|USER3";
$search = (isset($_GET['search']) ? $_GET['search'] : "..");

require_once("include/rdb/rdb.php");
$conn = r\connect('127.0.0.1', 28015, "database");

$result = r\table("paging")->filter(function($doc){
global $agency;
global $search;
return $doc('agency')->match($agency)
->rAnd($doc('private')->ne('true'))
->rAnd($doc('alias')->match("(?i){$search}"));
})->orderBy(r\desc('js_unique'))->limit(1000)->pluck($html_src)->run($conn);
    foreach ($result as $doc) {
    print_r($doc[$html_src]);
    }