Azure Cosmos DB Graph Wildcard search

妖精的绣舞 提交于 2021-02-06 08:56:27

问题


Is it possible to search Vertex properties with a contains in Azure Cosmos Graph DB?

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')

Seems like the within('') function only filters values that are exactly equal to 'Jr'. I am looking for a contains. Ideally case insensitive.


回答1:


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; };

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.




回答2:


The Azure team has now implemented Tinkerpop predicates for String

The Azure team has "announced" this to a user here on their feedback website.

I haven't tested all of them, but containing works for me (it is case sensitive though)

g.V().hasLabel('doc').or(__.has('title', containing('truc')), __.has('tags', containing('truc')))

TextP.startingWith(string)

Does the incoming String start with the provided String?

TextP.endingWith(string)

Does the incoming String end with the provided String?

TextP.containing(string)

Does the incoming String contain the provided String?

TextP.notStartingWith(string)

Does the incoming String not start with the provided String?

TextP.notEndingWith(string)

Does the incoming String not end with the provided String?

TextP.notContaining(string)

Does the incoming String not contain the provided String?



来源:https://stackoverflow.com/questions/44864203/azure-cosmos-db-graph-wildcard-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!