0

由于地理定位在定义的半径距离内,我们需要定位一组对象。

我们尝试使用 Neo4 J 空间库,使用 SpatialRepository 类来实现方法“findWithinDistance”</p>

下面使用索引类型 POINT 来存储对象的经度和纬度的实现代码:

@NodeEntity
@TypeAlias(value="MyObject")
public class MyObject{


    @GraphId Long nodeId;
    private String label;
    private String description;
    private Double lat;
    private Double lon;

    @Indexed(indexType = IndexType.POINT, indexName = "locations")
    String wkt;

    public void setLocation(float longitude, float latitude) {
          this.wkt = String.format("POINT( %.2f %.2f )",longitude,longitude);
    } 

1)第一次运行我们在neo4j数据库中创建对象没有任何问题(我们可以在neo4j中看到具有正确数据的对象)第二次运行或创建一个新对象我们说:索引存在同名但不同的配置!

java.lang.IllegalArgumentException: Index with the same name but different config exists!
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectRepositoryImpl': Injection of autowired dependencies failed; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Could not autowire field: org.springframework.data.neo4j.support.Neo4jTemplate fr.spart.is.neo4j.repository.ObjectRepositoryImpl.template;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'neo4jTemplate'
defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed;
nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.Neo4jTemplate org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jTemplate() 
throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jMappingContext' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration:
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Index with the same name but different config exists!
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)

我必须实现 findWithinDistance 的方法的另一点:我们应该使用模板方法或 Neo4j Cypher 查询来搜索对象?

谢谢您的帮助,

如果您需要精度,请不要犹豫

4

1 回答 1

0

你怎么运行这个?

您是否可能首先运行了一个“纯查询”变体,导致索引被创建为 lucene 索引而不是空间索引?

您还可以使用 neo4j-template 删除索引(您可能必须注释掉该修复程序才能运行的注释)

于 2014-11-01T04:55:04.440 回答