Arangodb AQL:字符串数组中的部分匹配
我有一张这样的桌子:Arangodb AQL:字符串数组中的部分匹配,arangodb,aql,Arangodb,Aql,我有一张这样的桌子: {"_key": "1", "name": "George Washington", "cars": ["Ford Focus"]} {"_key": "2", "name": "John Adams", "cars": ["Pontiac Firebird", "Toyota Corolla"]} {"_key": "3", "name": "Thomas Jefferson", "cars": ["Toyota Corolla"]} {"_key": "4", "nam
{"_key": "1", "name": "George Washington", "cars": ["Ford Focus"]}
{"_key": "2", "name": "John Adams", "cars": ["Pontiac Firebird", "Toyota Corolla"]}
{"_key": "3", "name": "Thomas Jefferson", "cars": ["Toyota Corolla"]}
{"_key": "4", "name": "James Madison", "cars": ["Ford Mustang", "Porsche 911"]}
FOR doc IN documents
LET matchingCars = (
FOR car IN doc.cars
FILTER LOWER(car) LIKE('ford%')
LIMIT 1
RETURN 1
)
FILTER LENGTH(matchingCars) > 0
RETURN doc.name
现在,我想找出所有拥有福特汽车的人的名字(例如,[“乔治·华盛顿”,“詹姆斯·麦迪逊])。
当然
FOR doc IN documents
FILTER ("Ford Focus" IN doc.cars OR "Ford Mustang" IN doc.cars)
RETURN doc.name
工作,但假设我不知道什么类型的福特存在。如何在数组中搜索字符串的一部分?一种方法是这样做:
{"_key": "1", "name": "George Washington", "cars": ["Ford Focus"]}
{"_key": "2", "name": "John Adams", "cars": ["Pontiac Firebird", "Toyota Corolla"]}
{"_key": "3", "name": "Thomas Jefferson", "cars": ["Toyota Corolla"]}
{"_key": "4", "name": "James Madison", "cars": ["Ford Mustang", "Porsche 911"]}
FOR doc IN documents
LET matchingCars = (
FOR car IN doc.cars
FILTER LOWER(car) LIKE('ford%')
LIMIT 1
RETURN 1
)
FILTER LENGTH(matchingCars) > 0
RETURN doc.name
注意:查询也可以在没有LIMIT
的情况下进行,但是使用LIMIT
将停止在文档中搜索匹配的车辆。查询使用类似的
函数进行字符串匹配,但您当然可以使用。最后,在比较car
属性之前,我将其值小写,因为比较可能不区分大小写。
请适应你的需要