Neo4j:Spring Data Neo4j中的本机Java API(或等效密码查询) [英] Neo4j: Native Java API(or equivalent cypher query) in Spring Data Neo4j
问题描述
过去几天,我正在尝试使用Neo4j Embedded-db进行DEMO,并且对Native Java API的索引,Lucene查询甚至是模糊搜索的印象深刻.然后,我决定将这个POC与Spring Data Neo4j 4.0一起投入生产,但是遇到了Cypher查询和模糊搜索的问题.
I was experimenting with Neo4j embedded-db in the past few days for a DEMO and was thoroughly impressed with the Native Java API's for indexing, lucene queries and even managed to do fuzzy search. I then decided to take this POC to production with Spring Data Neo4j 4.0 but ran into issues with Cypher queries and fuzzy search.
我的域类"Team"看起来像这样:
My domain class "Team" looks like this:
@NodeEntity public class Team {
@GraphId Long nodeId;
/** The team name. */
@Indexed(indexType = IndexType.FULLTEXT,indexName = "teamName")
private String teamName;
public Team(){};
public Team(String name){
this.teamName = name;
}
public void setTeamName(String name){
this.teamName = name;
}
public String getTeamName(){
return this.teamName;
}
}
我正在如下填充数据库:
I am populating my database as follows:
Team lakers = new Team("Los Angeles Lakers");
Team clippers = new Team("Los Angeles Clippers of Anaheim");
Team warriors = new Team("Golden State Warriors");
Team slappers = new Team("Los Angeles Slappers of Anaheim");
Team slippers = new Team("Los Angeles Slippers of Anaheim");
Transaction tx = graphDatabase.beginTx();
try{
teamRepository.save(lakers);
teamRepository.save(clippers);
teamRepository.save(warriors);
teamRepository.save(slappers);
teamRepository.save(slippers);
}
我的TeamRepository界面如下:
My TeamRepository interface looks like this:
public interface TeamRepository extends CrudRepository<Team, String>
{
@Query("MATCH (team:Team) WHERE team.teamName=~{0} RETURN team")
List<Team> findByTeamName(String query);
}
我的查询如下:
List<Team> teams = teamRepository.findByTeamName("The Los Angeles Will be Playing in a state of Golden");
上面的CYPHER查询不返回任何内容.
The above CYPHER query DOES NOT return anything.
我希望能够像下面的那样在Spring中进行本机Java API类型查询并获得以下结果.(teamIndex是我在团队名称上创建的全文本搜索索引)
I'd like to be able to do a Native Java API type query in Spring like the one below and get the following result.(teamIndex was a full text search index I had created on team names)
IndexHits<Node> found = teamIndex.query("Team-Names",queryString+"~0.5");
.
找到了本机JAVA API:
Native JAVA API found:
- 洛杉矶湖人队
- 阿纳海姆洛杉矶快船队
- 金州勇士
- 阿纳海姆的洛杉矶拍手
- 阿纳海姆的洛杉矶拖鞋
推荐答案
您正在寻找的是SDN3
What you are looking for is in SDN3
SDN4不支持@Indexed.
SDN4 doesn't support @Indexed.
有一个带有一些其他查询方法的IndexRepository,但您也可以像这样使用cypher:
There is an IndexRepository with some additional query methods but you can also use cypher like this:
public interface TeamRepository extends GraphRepository<Team>
{
@Query("start team=node:teamName({0}) RETURN team")
List<Team> findByTeamName(String query);
}
哪个会将索引查询发送给Lucene.
Which will send the index-query to Lucene.
这篇关于Neo4j:Spring Data Neo4j中的本机Java API(或等效密码查询)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!