Trying to filter an array of strings to return a single field which is a subset of the array with strings that contain a variable

huangapple go评论56阅读模式
英文:

Trying to filter an array of strings to return a single field which is a subset of the array with strings that contain a variable

问题

以下是您要翻译的内容:

"match (n:Node) return n.string" 返回按项目节点排序的字符串 ["abc,def,abcde"]

"match (n:Node) where any(string in n.string where string contains "abc") return n" 获取包含我寻找的内容的节点,但似乎找不到一种方式来获取匹配的节点并将它们作为字段返回

因此,如果一个节点具有字符串 ["abc","def","abcde"],那么当我搜索包含 "bc" 的字符串时,它应该获取该节点并只返回字符串 ["abc","abcde"]

英文:

The DB has items, and these items have a string parameter which is a comma separated string array. Im trying to pass in a search variable, and use that to return the item node, and the string array but with only the strings that match the search variable

match (n:Node) return n.string

returns the strings sorted by the item node as ["abc,def,abcde"]

match (n:Node)  where any(string in n.string where string contains "abc") return n

This gets me the nodes where one of the strings contains what I'm looking for, but I can't seem to find a way to get the ones which matched and return them as a field

So if a node has a string of ["abc","def","abcde"] then when I search for strings containing "bc" then it should get the node and return just the strings of ["abc","abcde"]

答案1

得分: 0

以下查询返回每个节点及其过滤字符串的列表。不含匹配字符串的节点将被忽略。$filter 是一个参数,用于指定所需的过滤器(例如,"abc")。

MATCH (n:Node)
UNWIND n.string AS s
WITH n, s
WHERE s CONTAINS $filter
RETURN n, COLLECT(s) AS filtered_strings

注意:如果 n.string 实际上是一个看起来像列表的字符串,请将 n.string 替换为 SPLIT(n.string, ',')

英文:

The following query returns each node and its list of filtered strings. Nodes without matching strings are ignored. $filter is a parameter with the desired filter (e.g., "abc").

MATCH (n:Node)
UNWIND n.string AS s
WITH n, s
WHERE s CONTAINS $filter
RETURN n, COLLECT(s) AS filtered_strings

NOTE: If n.string is actually a string that looks like a list, replace n.string with SPLIT(n.string, ',').

huangapple
  • 本文由 发表于 2023年7月6日 15:41:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76626552.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定