【问题标题】:Full Text Search in OrientDB JSON DataOrientDB JSON 数据中的全文搜索
【发布时间】:2021-09-21 01:39:41
【问题描述】:

我在 OrientDB 3.0.27 中有以下数据,其中一些值在 JSON 数组中,一些是字符串

{
    "@type": "d",
    "@rid": "#57:0",
    "@version": 2,
    "@class": "abc_class",
    "user_name": [
        "7/1 LIBOR Product"
    ],
    "user_Accountability": [],
    "user_Rollout_32_date": [],
    "user_Brands": [
        "AppNet"
    ],
    "user_lastModificationTime": [
        "2019-11-27 06:40:35"
    ],
    "user_columnPercentage": [
        "0.00"
    ],
    "user_systemId": [
        "06114a87-a099-0c30c60b49c4"
    ],
    "user_lastModificationUser": [
        "system"
    ],
    "system_type": "Product",
    "user_createDate": [
        "2017-10-27 09:58:42"
    ],
    "system_modelId": "bian_model",
    "user_parent": [
        "a12a41bd-af6f-0ca028af480d"
    ],
    "user_Strategic_32_value": [],
    "system_oeId": "06114a87-a099-0c30c60b49c4",
    "user_description": [],
    "@fieldTypes": "user_name=e,user_Accountability=e,user_Rollout_32_date=e,user_Brands=e,user_lastModificationTime=e,user_columnPercentage=e,user_systemId=e,user_lastModificationUser=e,user_createDate=e,user_parent=e,user_Strategic_32_value=e,user_description=e"
}

我尝试了以下查询:

select * from `abc_class ` where any() = ["AppNet"]  limit 2;
select * from `abc_class ` where any() like '%a099%'  limit 2;

上述两个查询都有效,因为它们尊重字段的数据类型。

我想运行包含查询,它将在任何数据类型(如字符串、数字、JSON 数组等)的任何字段中进行搜索,更像是 - 全文搜索

select * from `abc_class ` where any() like '%AppNet%'  limit 2;

上述查询不起作用,因为实际值在 JSON 数组中。尝试了filtering section documentation的几乎所有东西

如何利用现有数据实现全文搜索之类的功能?

编辑#1

现在做更多研究后,我至少可以将数组值转换为字符串,然后在其上运行 like 运算符,如下所示;

select * from `abc_class` where user_name.asString() like '%LIBOR%'

但是,使用 any().asString() 不会产生任何结果

select * from `abc_class` where any().asString() like '%LIBOR%'

如果上面的查询可以通过某种方式增强以将任何列查询为字符串,那么问题就可以解决了。

【问题讨论】:

    标签: database where-clause orientdb document-database


    【解决方案1】:

    如果需要搜索所有列值,那么我们可以创建一个全行数据的 JSON 对象并将其转换为字符串。

    然后用like关键字查询字符串,如下:

    select * from `abc_class` where @this.toJSON().asString() like '%LIBOR%'
    

    如果我们将直接转换为@this.asString(),那么我们将获得数组元素的计数,而不是数组元素中的真实数据,如下所示:

    abc_class#57:4{system_modelId:model,system_oeId:14f4b593-a57d-4d37ad070a10,system_type:Product,user_lastModificationUser:[1],user_name:[1],user_description:[0],user_Accountability:[0],user_lastModificationTime:[1],user_Rollout_32_date:[0],user_Strategic_32_value:[0],user_createDate:[1],user_Brands:[0],user_parent:[1],user_systemId:[1],user_columnCompletenessPercentage:[1]} v2
    

    因此,我们需要先转成JSON再转成String才能使用@this.toJSON().asString()查询全记录

    参考资料:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-13
      • 1970-01-01
      • 2021-01-28
      • 1970-01-01
      • 2010-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多