简体   繁体   English

NEO4j:搜索密码查询的优化

[英]NEO4j:Optimization of search cypher queries

We are using neo4j cypher queries for searching in our website. 我们正在使用neo4j密码查询在我们的网站中进行搜索。 So, long everythng is going fine except the optimization of queries. 因此,除了查询优化之外,一切都很好。 We are getting search results but not exactly what we are expecting may be lack of experience and full knowledge about cypher queries. 我们正在获取搜索结果,但可能并非完全缺乏我们期望的,因为可能缺乏经验和对密码查询的全面了解。

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. v然后是一个类似的字符串,直到我们进入空格,它将把它视为一个字符串,并相应地显示结果,但是问题是,当我们进入空格并开始写字母,然后再次形成字符串时,结果波动严重。

EXAMPLE: 例:

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

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

ISSUE:- Since I am showing you the search through full string not by separated letters, still as it can be visible in the images that vartika jain which we expect to come as first result move to 2 which should not be the case. 问题:-由于我正在向您显示不使用分隔字母的完整字符串搜索,因此仍然可以在图像中看到,我们希望第一个结果出现的vartika jain移到2,情况并非如此。

As, when we work for key up handler then search result vartika jain goes to last position which is not we wanted. 因此,当我们为钥匙搬运工工作时,搜索结果vartika jain会到达我们不希望的最后位置。

QUERY2结果

QUESTION:- SO, is there any way to optimize the result, so that we can get the best results as we get in google search. 问题:-因此,有什么方法可以优化结果,以便我们在Google搜索中获得最佳结果。

It seems like you should count the number of matches and order by that. 看来您应该以此来计算比赛的次数和顺序。

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

I removed the [:userinteresttag] relationship and tag node since you aren't using it in your query. 我删除了[:userinteresttag]关系和tag节点,因为您没有在查询中使用它。

Example from the movie graph: 电影图中的示例:

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      │
└────────────┴───────┘

But really you should store their first and last name in separate properties, index them, and use STARTS WITH on those indexed properties. 但是实际上,您应该将它们的名字和姓氏存储在单独的属性中,对其进行索引,并对这些索引属性使用STARTS WITH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM