【问题标题】:Laravel 'like' query with MongoDB connection使用 MongoDB 连接的 Laravel 'like' 查询
【发布时间】:2016-01-05 00:37:54
【问题描述】:

我在 laravel 'like' 查询中遇到问题。我在 laravel 上有一个带有 MongoDb 数据库的 MIS。现在我的数据库有一个名为kw 的表,其中包含cars%20in%20London 等urlencoded 关键字,现在我的查询给出了carscars%20in%20London 的准确结果,但是当我搜索cars%20in 时,我得到0 个结果!这就是 laravel 'like' 在查询中的使用方式,但 Mongo 使用 /.m./ 形式,我怎样才能使它工作。这是我的模型函数


public static function selectKeywordIncomplete($keyword) {   
    $search_volume_incomplete = searchVolume::where('kw','like','%'.$keyword.'%')->orwhere('kw','=',$keyword)->where('status','=',1)->paginate(20);
    return $search_volume_incomplete; 
}

【问题讨论】:

  • 你试过像$search_volume_incomplete = searchVolume::where('kw','regex', new MongoRegex("/^$keyword/i"))->orwhere('kw','=',$keyword)->where('status','=',1)->paginate(20);这样的正则表达式吗?
  • 不知道它是否有效,但未找到 Class 'App\Models\MongoRegex',这是错误来了,已经包括了 jessengers,我正在寻找这个问题,但如果你知道的话让我知道,谢谢。

标签: php mongodb laravel-5 eloquent


【解决方案1】:

在 mongoDb 中没有“喜欢”之类的东西,我寻找了 Mongodb 正则表达式,但是 mongoDB 的 laravel 正则表达式很有魅力, 这是有效的查询。 http://jenssegers.be/projects/laravel-mongodb

$search_volume_unprocessed = searchVolume::where('kw','=',$keyword)->orwhere('kw','regexp',"/.*$keyword/i")->where('status','=', 1)->分页(20);

【讨论】:

    猜你喜欢
    • 2010-12-28
    • 1970-01-01
    • 2015-06-18
    • 1970-01-01
    • 2011-03-19
    • 1970-01-01
    • 2015-08-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多