Java Hibernate search 5.0 spatial返回无结果

Java Hibernate search 5.0 spatial返回无结果,java,spring,hibernate,lucene,hibernate-search,Java,Spring,Hibernate,Lucene,Hibernate Search,我正在创建一个功能,使用户可以搜索附近的停车场,该停车场距离用户当前位置10公里 我正在使用SpringHibernate和MySQL5Innodbdial。我试图通过遵循本教程,在HibernateSearch5.0.0.Final库中实现此功能 但是,在我触发查询后,没有返回任何结果。我正在使用hibernate core 4.3.7 休眠设置 注意:文件系统提供程序=文件系统,索引数据库=lucene/ <!-- Hibernate SessionFactory --> <

我正在创建一个功能,使用户可以搜索附近的停车场,该停车场距离用户当前位置10公里

我正在使用SpringHibernate和MySQL5Innodbdial。我试图通过遵循本教程,在HibernateSearch5.0.0.Final库中实现此功能

但是,在我触发查询后,没有返回任何结果。我正在使用hibernate core 4.3.7

休眠设置

注意:文件系统提供程序=文件系统,索引数据库=lucene/

<!-- Hibernate SessionFactory -->
<beans:bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <beans:property name="dataSource" ref="dataSource" />
    <beans:property name="packagesToScan" value="com.jinheng.fyp.bean" />
<!--  Naming strategy  -->
    <beans:property name="namingStrategy" ref="myNaming" />
    <beans:property name="hibernateProperties">
        <beans:props>
            <beans:prop key="hibernate.dialect">${hibernate.dialect}</beans:prop>
            <beans:prop key="hibernate.show_sql">${hibernate.show_sql}</beans:prop>
            <beans:prop key="hibernate.format_sql">${hibernate.show_sql}</beans:prop>
            <beans:prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</beans:prop>
            <beans:prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</beans:prop>
            <beans:prop key="cache.provider_class">org.hibernate.cache.NoCacheProvider</beans:prop>
            <beans:prop key="hibernate.default_batch_fetch_size">15</beans:prop>
            <beans:prop key="hibernate.use_sql_comments">true</beans:prop>
            <beans:prop key="hibernate.default-lazy">true</beans:prop>
            <beans:prop key="hibernate.order_updates">true</beans:prop>
            <beans:prop key="hibernate.connection.CharSet">utf8</beans:prop>
            <beans:prop key="hibernate.connection.characterEncoding">utf8</beans:prop>
            <beans:prop key="hibernate.connection.useUnicode">true</beans:prop>
            <beans:prop key="hibernate.query.substitutions">true 1, false 0, yes 'Y', no 'N'</beans:prop>
            <beans:prop key="hibernate.hbm2ddl.import_files_sql_extractor">org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor</beans:prop>
            <beans:prop key="hibernate.jdbc.use_streams_for_binary">false</beans:prop>
            <beans:prop key="hibernate.connection.isolation">4096</beans:prop>
            <beans:prop key="hibernate.search.default.directory_provider">${hibernate.search.default.directory_provider}</beans:prop>
            <beans:prop key="hibernate.search.default.indexBase">${hibernate.search.default.indexBase}</beans:prop>
            <beans:prop key="hibernate.search.lucene_version">4.1.0</beans:prop>
        </beans:props>
    </beans:property>
</beans:bean>
查询DAO类

@Repository
@Transactional
public class MapDAOImpl extends GenericDAO implements MapDAO {

@SuppressWarnings("unchecked")
@Override
public List<Lot> getNearbyLot(Double latitude, Double longitude, Integer radius) {
    FullTextSession fullTextSession = Search.getFullTextSession(getSessionFactory());
    QueryBuilder builder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Lot.class).get();

    org.apache.lucene.search.Query luceneQuery = builder.spatial().within(radius, Unit.KM).ofLatitude(latitude).andLongitude(longitude).createQuery();

    org.hibernate.Query hibernateQuery = fullTextSession.createFullTextQuery(luceneQuery, Lot.class);
     //this code works
    // org.hibernate.Query hibernateQuery = getSessionFactory().createSQLQuery("SELECT * FROM LOT").addEntity(Lot.class);
    List<Lot> result = hibernateQuery.list();
    return result;
}
}
@存储库
@交易的
公共类MapDAOImpl扩展GenericDAO实现MapDAO{
@抑制警告(“未选中”)
@凌驾
公共列表getNearbyLot(双纬度、双经度、整数半径){
FullTextSession FullTextSession=Search.getFullTextSession(getSessionFactory());
QueryBuilder builder=fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Lot.class.get();
org.apache.lucene.search.Query luceneQuery=builder.spatial()。在纬度(radius,Unit.KM.)和经度(longitude.createQuery()的范围内;
org.hibernate.Query hibernateQuery=fullTextSession.createFullTextQuery(luceneQuery,Lot.class);
//此代码有效
//org.hibernate.Query hibernateQuery=getSessionFactory().createSQLQuery(“从批次中选择*).addEntity(LOT.class);
列表结果=hibernateQuery.List();
返回结果;
}
}

它隐藏在文档中

SpatialContext.onField():基本上,如果不提供onField(),它将不起作用,它将无法为您找到要搜索的字段的名称。 这是一种方法:

org.apache.lucene.search.Query luceneQuery = spatialContext.onField("physical").within(100, Unit.KM).ofLatitude(centerLatitude).andLongitude(centerLongitude).createQuery();
“physical”这里是添加到@spatical@纬度和@Longitude的属性“name”的值(如中所示)

我的例子是:

@javax.persistence.Entity @Indexed  @Spatial(name="physical")
public class Tutorial implements IBusiness {

@Latitude(of="physical") @Column
private Double latitude;
@Longitude(of="physical")  @Column
private Double longitude;
[... cut ...]
它对我有用,我希望它能帮助未来的读者。Lucene是一个很棒的API,Hibernate也是,但是它们太广泛了。。。现在可能是重构文档的时候了

@javax.persistence.Entity @Indexed  @Spatial(name="physical")
public class Tutorial implements IBusiness {

@Latitude(of="physical") @Column
private Double latitude;
@Longitude(of="physical")  @Column
private Double longitude;
[... cut ...]