我在使用带有术语节点标记的内容节点的图表上工作。我试图让查询工作,返回(匹配的)与其他(搜索)术语节点连接到相同内容节点的术语节点。
(matched:term)--(contentNode:content)--(search:term)
我遇到的问题是返回匹配的术语节点,这些节点连接到所有连接到它的搜索词的内容,而不是任何
。以下是我当前查询的简化版本:
query = [
'MATCH (matched:term)<-[:TAGGED_WITH]-(contentNode:content)-[:TAGGED_WITH]->(searchTerms:term) ',
'WHERE searchTerms.UUID IN {searchTerms} ',
'RETURN DISTINCT matched.name AS name, matched.UUID AS UUID, matched.contentConnections AS connections ',
'ORDER BY connections DESC LIMIT 10'
].join('\n');
以下是实践中的一个示例 - 顶级字词组是我的查询匹配的字词,底部是用于搜索的字词:
术语&#39;天文学&#39;不应该退回,但这是因为某些内容标有&#39; image&#39;也被标记为天文学&#39;。
结果的图表表示:
请注意,只有一个内容(灰色节点)与两个术语匹配(很难说明,因为节点ID是显示的内容)。所期望的是仅返回与已标记为&#34;图像&#34;的内容相关联的术语。和&#34;器官&#34;
另一个例子:
此搜索不应产生任何条款,因为没有任何内容标记为&#39; organ&#39;然而,它是返回标记为任何一个的术语。
图表表示:
我希望我的问题清楚明了。我曾尝试与count()
合作对结果进行分组,但却努力让它发挥作用。
任何帮助都将不胜感激。
编辑:
查询:
query = [
'MATCH (contentNode:content)-[:TAGGED_WITH]->(searchTerms:term) ',
'WITH contentNode, COUNT(contentNode) as countContent, searchTerms ',
'WHERE searchTerms.UUID IN {searchTerms} AND countContent = {searchTermsCount} ',
'MATCH (typeNode:termType)<-[:IS_TYPE]-(matched:term)<-[:TAGGED_WITH]-contentNode, ',
'matched-[:HAS_LANGUAGE {languageCode: {language} }]-(termMeta:termMeta) ',
'WHERE NOT matched.UUID IN {ignoreTerms}',
'RETURN DISTINCT termMeta.name AS name, matched.UUID AS UUID, matched.contentConnections AS connections ',
'ORDER BY connections DESC LIMIT 10'
].join('\n');
如果选择了以下两个字词,则该查询应返回标记为任何这些内容的字词(&#39; evolution&#39;,&#39; ant&#39;等),但是,使用上述查询,不会返回任何条款。
答案 0 :(得分:1)
您可以尝试将查询拆分为两个:
MATCH (contentNode:content)-[:TAGGED_WITH]->(searchTerms:term)
WHERE searchTerms.UUID IN {searchTerms}
WITH contentNode, COUNT(*) as cnt
WHERE cnt = {_searchTerms_size_}
MATCH (matched:term)<-[:TAGGED_WITH]-contentNode
RETURN DISTINCT matched.name AS name, matched.UUID AS UUID, matched.contentConnections AS connections
ORDER BY connections DESC LIMIT 10