Azure Cosmos DB Graph Wildcard search

后端 未结 2 1079
失恋的感觉
失恋的感觉 2021-02-05 18:33

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 thei

2条回答
  •  猫巷女王i
    2021-02-05 18:44

    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.

提交回复
热议问题