在过去的几天里,我在尝试使用Neo4j嵌入式数据库进行DEMO测试,并对原生Java API的索引,lucene查询甚至设法做模糊搜索。然后我决定将这个POC用Spring Data Neo4j 4.0生成,但遇到了Cypher查询和模糊搜索的问题。Neo4j:Spring Data Neo4j中的Native Java API(或等效的密码查询)
我的域类 “团队” 看起来是这样的:
@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发现:
- 洛杉矶湖人 阿纳海姆的
- 洛杉矶快船阿纳海姆的
- 金州勇士
- 洛杉矶轻手轻脚
- 洛杉矶拖鞋阿纳海姆的
随着SDN4全文添加被推迟:http://docs.spring.io/spring-data/neo4j/docs/4.0.0.RC1/reference/html/#_full_text_indexes。但Neo4j 2.3将添加更多的字符串查找功能,以便大多数应该可以开箱即用。 –
cypher @Query(“start team = node:teamName({0})RETURN team”)的搜索teamrepository.findByTeamName(“洛杉矶将在黄金状态下播放”)引发NPE org.apache。 lucene.util.SimpleStringInterner.intern(SimpleStringInterner.java:54)。我发现了类似的线程:http://forum.spring.io/forum/spring-projects/data/nosql/112078-repository-derived-query-not-working-with-strings-that-have-spaces。另外如果teamName没有被索引,我得到一个错误,指出索引'teamName'不存在 – codebin