我是用Neo4j的嵌入式数据库实验在过去数天为一个DEMO,是与本地的Java API的索引,Lucene的查询,甚至设法做模糊搜索,彻底折服。 然后,我决定采取这一POC生产与Spring数据的Neo4j 4.0,但遇到了与Cypher支架查询和模糊查询的问题。
我的域类“团队”看起来是这样的:
@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;
}
}
我填充我的数据库,如下所示:
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界面看起来是这样的:
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查询不返回任何东西。
我希望能够做一个本地的Java API类型的查询在春天像下面的一个,并得到以下结果。(teamIndex为我创造了一个完整的文本搜索索引的队名)
IndexHits<Node> found = teamIndex.query("Team-Names",queryString+"~0.5");
。
本地Java API发现:
- 洛杉矶湖人队
- 阿纳海姆的洛杉矶快船
- 金州勇士
- 洛杉矶安那罕轻手轻脚
- 洛杉矶安那罕拖鞋