Azure Cosmos DB Graph通配符搜索 [英] Azure Cosmos DB Graph Wildcard search
问题描述
是否可以在Azure Cosmos Graph DB中使用包含来搜索Vertex属性?
Is it possible to search Vertex properties with a contains in Azure Cosmos Graph DB?
例如,我想查找姓名中有'Jr'
的所有人?
For example, I would like to find all persons which have 'Jr'
in their name?
g.V().hasLabel('person').has('name',within('Jr')).values('name')
似乎像 within('')
函数一样,仅过滤与'Jr'
完全相等的值.我正在寻找一个包含.理想情况下,不区分大小写.
Seems like the within('')
function only filters values that are exactly equal to 'Jr'
. I am looking for a contains. Ideally case insensitive.
推荐答案
CosmosDB目前没有任何文本匹配功能.但是,我能够通过使用使用Javascript match()函数的UDF(用户定义函数)来实现通配符搜索功能:
None of the text matching functions are available for CosmosDB at this time. However, I was able to implement a wildcard search functionality by using a UDF (User Defined Function) which uses the Javascript match() function:
function userDefinedFunction(input, pattern) { return input.match(pattern) !== null; };
然后,您必须将查询编写为SQL并使用您定义的UDF(以下示例假定您调用了"REGEX"函数
Then you'd have to write your query as SQL and use the UDF that you defined (the example below assumes you called you function 'REGEX'
SELECT * FROM c where(udf.REGEX(c.name[0]._value, '.*Jr.*') and c.label='person')
性能将远非理想,因此您需要根据延迟和成本方面的观点来确定解决方案是否可以接受.
The performance will be far from ideal so you need to decide if the solution is acceptable or not based on your latency and cost perspectives.
这篇关于Azure Cosmos DB Graph通配符搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!