NEO4j:Optimization 的搜索密码查询

NEO4j:Optimization of search cypher queries

我们正在使用 neo4j 密码查询在我们的网站中进行搜索。所以,除了查询优化之外,一切都很顺利。我们正在获取搜索结果,但并不完全符合我们的预期,这可能是因为我们缺乏有关密码查询的经验和全部知识。

In a textbox the search string is been send to the query on key up handler means on entering each letter its going to execute query. Like for eg. v then a like this and untill we enter space it will treat it as one string and the result will be shown accordingly, but the issue is as we enter space and start writing letters and then again will form a string the result fluctates badly.

EXAMPLE:

QUERY 1 : MATCH (n:user)<-[:userinteresttag]-(tag) where ANY(m in split(n.username," ") where m STARTS WITH 'vartika' ) RETURN distinct n.username

QUERY2:MATCH (n:user)<-[:userinteresttag]-(tag) where ANY(m in split(n.username," ") where m STARTS WITH 'vartika' or m STARTS WITH 'jain') RETURN distinct n.username order by n.username

问题:- 由于我向您展示了通过完整字符串进行搜索而不是通过分隔的字母进行搜索,因此在图像中仍然可以看到我们希望作为第一个结果出现的 vartika jain 移动到 2,但事实并非如此。

因为,当我们为 key up 处理程序工作时,搜索结果 vartika jain 会转到我们不想要的最后位置。

问题:- 那么,有什么方法可以优化结果,以便我们在 google 搜索中获得最佳结果。

看来你应该计算匹配的数量并以此为准。

MATCH (n:user)
WITH n, size([m in split(n.username, ' ') WHERE m STARTS WITH 'vartika' OR m STARTS WITH 'jain']) AS matches
RETURN n.username
ORDER BY matches DESC

我删除了 [:userinteresttag] 关系和 tag 节点,因为您没有在查询中使用它。

电影图表中的​​示例:

MATCH (p:Person)
WITH p, size([x IN split(p.name, ' ') WHERE x STARTS WITH 'Tom' OR x STARTS WITH 'Hanks']) AS matches
RETURN p.name, matches
ORDER BY matches DESC
LIMIT 5

╒════════════╤═══════╕
│p.name      │matches│
╞════════════╪═══════╡
│Tom Hanks   │2      │
├────────────┼───────┤
│Tom Cruise  │1      │
├────────────┼───────┤
│Tom Skerritt│1      │
├────────────┼───────┤
│Tom Tykwer  │1      │
├────────────┼───────┤
│Keanu Reeves│0      │
└────────────┴───────┘

但实际上您应该将他们的名字和姓氏存储在单独的属性中,为它们编制索引,然后在这些索引属性上使用 STARTS WITH