Freebase MQL过滤器的值!= null?

时间:2009-03-24 17:30:58

标签: freebase mql

我正在尝试编写一个过滤掉空值的MQL查询。

我现在的查询(可以使用MQL Query Editor执行):

[
  {
    "/common/topic/image" : [
      {
        "id" : null
      }
    ],
    "article" : [
      {
        "content" : null
      }
    ],
    "name" : "bill gates",
    "type" : "/common/topic"
  }
]

我得到的结果:

[
  {
    "/common/topic/image" : [
      {
        "id" : "/guid/9202a8c04000641f8000000004fb4c01"
      },
      {
        "id" : "/wikipedia/images/commons_id/4486276"
      }
    ],
    "article" : [
      {
        "content" : null
      },
      {
        "content" : "/guid/9202a8c04000641f800000000903535d"
      }
    ],
    "name" : "Bill Gates",
    "type" : "/common/topic"
  }
]

我正在试图弄清楚如何在查询时过滤掉“article”数组中的“content”:null匹配。我查看了MQL文档,但我没有看到明确的方法。

1 个答案:

答案 0 :(得分:10)

要过滤掉没有分配任何内容的文章,您必须展开内容ID属性并将可选指令设置为false。

[
  {
    "/common/topic/image" : [
      {
        "id" : null
      }
    ],
    "article" : [
      {
        "content" : {
          "id" : null,
          "optional" : false
        }
      }
    ],
    "name" : "bill gates",
    "type" : "/common/topic"
  }
]

这会给你以下结果:

[
  {
    "/common/topic/image" : [
      {
        "id" : "/guid/9202a8c04000641f8000000004fb4c01"
      },
      {
        "id" : "/wikipedia/images/commons_id/4486276"
      }
    ],
    "article" : [
      {
        "content" : {
          "id" : "/guid/9202a8c04000641f800000000903535d"
        }
      }
    ],
    "name" : "Bill Gates",
    "type" : "/common/topic"
  }
]

有关使用可选指令的更多信息,请参阅文档here