简体   繁体   中英

How to use OR operator in Freebase?

Case:

So, I'm using the OR operator or ONE OF as to get people from any of 2 countries. The query looks like:

[{
  "id":    null,
  "type":  "/people/person",
  "/people/person/nationality": {
    "name|=": [
      "Jordan",
      "Ottoman Empire"
    ]
  },
  "name":  null,
  "limit": 30
}]

The query works fine, but it won't work if you increase the limit to be 40 for example. The error returned is "Unique query may have at most one result. Got 2". This means that there exist a person for both nationalities "Jordan" and "Ottoman Empire".

Question:

It makes sense for a "ONE OF" operator, but not for "OR" operator. Is there any operator in Freebase that can query "ANY OF" or true "OR" to cover these cases?

You're getting the error because you used object notation ({}) which expects a single result in a place where you're returning two results and would those need an array ([]).

Having said that, I think what you really need to do is hoist your |= operator up a level to /people/person/nationality . Note also that you need array notation even if just asking for nationality results for a person, because it's multi-valued (eg Sirhan Sirhan has both Jordan and Mandatory Palestine as his nationality).

Here's a query that will do what you want (although you should really use IDs for the countries rather than their English labels):

[{
  "id": null,
  "name": null,
  "nationality": [],
  "type": "/people/person",
  "nationality|=": [
    "Jordan",
    "Ottoman Empire"
  ]
}]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM