-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 
Author Message
 Post subject: Search result sort by Geo-location range.
PostPosted: Sun Jan 20, 2013 11:22 am 
Regular
Regular

Joined: Fri Feb 04, 2011 8:34 pm
Posts: 66
Hi, With hibernate lucene 3.5.0, my search result need to return all data within a selected geo-location range eg. 50km.
Each record in my my database table has 2 fields: lat varchar(50), and lon varchar(50).

Example output form database table:
| lat | lon |
+------------+------------+
| -33.770184 | 150.908501 |
+------------+------------+
1 row in set (0.00 sec)

Here is my entity class:

Code:
....
@Size(max = 50)
    @Column(name = "lat")
    private String lat;
    @Size(max = 50)
    @Column(name = "lon")
    private String lon;
...


Search function:

Code:

...
query = qb
                        .bool()
                            .must(qb.keyword().onFields("header", "aDesc").matching(termsStr).createQuery())
                            .must(qb.keyword().onField("state").matching(state).createQuery())
                            .must(qb.keyword().onField("postcode").matching(postcode).createQuery())
                        .createQuery();
...
// wrap Lucene query in a javax.persistence.Query
        javax.persistence.Query persistenceQuery = fullTextEntityManager.createFullTextQuery(query, MyisamProductArticle.class).setSort(sort);

        persistenceQuery.setFirstResult(start); //eg. start from the 15th element
        persistenceQuery.setMaxResults(size); //eg. return 10 elements
        // execute search
        List result = persistenceQuery.getResultList();
        //em.getTransaction().commit();
        //em.close();
        return result;


Is there a way to add a geo-location range comparator to "query" or "persistenceQuery" before applying pagination parameters to the persistenceQuery?
And how to implement a geo-location range comparator when searching from mysql database?

Any suggestion is highly appreciated.
Thanks
sam


Top
 Profile  
 
 Post subject: Re: Search result sort by Geo-location range.
PostPosted: Mon Jan 21, 2013 12:16 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
you're very lucky, we just released Hibernate Search 4.2.0.Final last week and the main new feature is exactly what you need.

Read more about the release on our blog:
http://in.relation.to/Bloggers/HibernateSearch42FinalIsOutSpatialQueryAndMore

Spatial documentation:
http://docs.jboss.org/hibernate/search/4.2/reference/en-US/html_single/#spatial

Quote:
Any suggestion is highly appreciated.

Upgrade! and make sure to follow our announcements ;)

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Search result sort by Geo-location range.
PostPosted: Mon Jan 21, 2013 8:36 am 
Regular
Regular

Joined: Fri Feb 04, 2011 8:34 pm
Posts: 66
Thank you very much for the suggestion.
I am looking forward to test it on tomorrow.
By the way, is String type of lat and lon acceptable?
eg.

Code:
   
   @Latitude
   String latitude;

  @Longitude
  String longitude;



If not, I will change that as well.

Thanks
sam


Top
 Profile  
 
 Post subject: Re: Search result sort by Geo-location range.
PostPosted: Mon Jan 21, 2013 8:42 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
No, it must use Long for the type, or long. String won't work.
You can either fix the database schema by changing the varchar to a numeric type, or convert the field in your entity with a little bit of Java code.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Search result sort by Geo-location range.
PostPosted: Mon Jan 21, 2013 9:36 am 
Regular
Regular

Joined: Fri Feb 04, 2011 8:34 pm
Posts: 66
when I deployed the ear file, jboss thrown the following error:

Quote:
00:31:01,546 FINE [com.sun.xml.bind.v2.ContextFactory] (MSC service thread 1-1) Property com.sun.xml.bind.XmlAccessorFactoryis not active. Using JAXB's implementation
00:31:01,557 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC00001: Failed to start service jboss.persistenceunit."ForestSurf-ear-1.0.ear/ForestSurf-ejb-1.0.jar#ForestSurfPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."ForestSurf-ear-1.0.ear/ForestSurf-ejb-1.0.jar#ForestSurfPU": Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885) [rt.jar:1.6.0_07]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907) [rt.jar:1.6.0_07]
at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_07]
Caused by: java.lang.NoSuchMethodError: org.apache.lucene.util.CharsRef.deepCopyOf(Lorg/apache/lucene/util/CharsRef;)Lorg/apache/lucene/util/CharsRef;
at org.apache.lucene.analysis.synonym.SynonymMap$Builder.add(SynonymMap.java:206)
at org.apache.lucene.analysis.synonym.SynonymMap$Builder.add(SynonymMap.java:239)
at org.apache.lucene.analysis.synonym.SolrSynonymParser.addInternal(SolrSynonymParser.java:127)
at org.apache.lucene.analysis.synonym.SolrSynonymParser.add(SolrSynonymParser.java:70)
at org.apache.solr.analysis.FSTSynonymFilterFactory.loadSolrSynonyms(FSTSynonymFilterFactory.java:122)
at org.apache.solr.analysis.FSTSynonymFilterFactory.inform(FSTSynonymFilterFactory.java:84)
at org.apache.solr.analysis.SynonymFilterFactory.inform(SynonymFilterFactory.java:67)
at org.hibernate.search.impl.SolrAnalyzerBuilder.injectResourceLoader(SolrAnalyzerBuilder.java:111)
at org.hibernate.search.impl.SolrAnalyzerBuilder.buildAnalyzer(SolrAnalyzerBuilder.java:87)
at org.hibernate.search.impl.ConfigContext.buildAnalyzer(ConfigContext.java:280)
at org.hibernate.search.impl.ConfigContext.initLazyAnalyzers(ConfigContext.java:248)
at org.hibernate.search.spi.SearchFactoryBuilder.initDocumentBuilders(SearchFactoryBuilder.java:437)
at org.hibernate.search.spi.SearchFactoryBuilder.buildNewSearchFactory(SearchFactoryBuilder.java:222)
at org.hibernate.search.spi.SearchFactoryBuilder.buildSearchFactory(SearchFactoryBuilder.java:146)
at org.hibernate.search.event.impl.FullTextIndexEventListener.initialize(FullTextIndexEventListener.java:130)
at org.hibernate.search.hcore.impl.HibernateSearchIntegrator.integrate(HibernateSearchIntegrator.java:83)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:294)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]


Any idea?
Thanks
Sam


Top
 Profile  
 
 Post subject: Re: Search result sort by Geo-location range.
PostPosted: Mon Jan 21, 2013 9:57 am 
Regular
Regular

Joined: Fri Feb 04, 2011 8:34 pm
Posts: 66
Further fix shown the following exception:

Quote:
lucene/analysis/TokenStream;
at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.6.0_07]
at java.lang.ClassLoader.defineClass(ClassLoader.java:620) [rt.jar:1.6.0_07]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) [rt.jar:1.6.0_07]
at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:327)
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:391)
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:243)
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:73)
at org.jboss.modules.Module.loadModuleClass(Module.java:517)
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:182)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) [rt.jar:1.6.0_07]
at org.hibernate.search.spi.SearchFactoryBuilder.initDocumentBuilders(SearchFactoryBuilder.java:365) [hibernate-search-engine-4.2.0.Final.jar:4.2.0.Final]
at org.hibernate.search.spi.SearchFactoryBuilder.buildNewSearchFactory(SearchFactoryBuilder.java:222) [hibernate-search-engine-4.2.0.Final.jar:4.2.0.Final]
at org.hibernate.search.spi.SearchFactoryBuilder.buildSearchFactory(SearchFactoryBuilder.java:146) [hibernate-search-engine-4.2.0.Final.jar:4.2.0.Final]
at org.hibernate.search.event.impl.FullTextIndexEventListener.initialize(FullTextIndexEventListener.java:130) [hibernate-search-orm-4.2.0.Final.jar:4.2.0.Final]
at org.hibernate.search.hcore.impl.HibernateSearchIntegrator.integrate(HibernateSearchIntegrator.java:83) [hibernate-search-orm-4.2.0.Final.jar:4.2.0.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:294) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885) [rt.jar:1.6.0_07]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907) [rt.jar:1.6.0_07]
at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_07]

00:53:11,081 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC00001: Failed to start service jboss.persistenceunit."ForestSurf-ear-1.0.ear/ForestSurf-ejb-1.0.jar#ForestSurfPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."ForestSurf-ear-1.0.ear/ForestSurf-ejb-1.0.jar#ForestSurfPU": Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885) [rt.jar:1.6.0_07]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907) [rt.jar:1.6.0_07]
at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_07]
Caused by: java.lang.NoClassDefFoundError: org/hibernate/search/util/impl/DelegateNamedAnalyzer
at org.hibernate.search.spi.SearchFactoryBuilder.initDocumentBuilders(SearchFactoryBuilder.java:365)
at org.hibernate.search.spi.SearchFactoryBuilder.buildNewSearchFactory(SearchFactoryBuilder.java:222)
at org.hibernate.search.spi.SearchFactoryBuilder.buildSearchFactory(SearchFactoryBuilder.java:146)
at org.hibernate.search.event.impl.FullTextIndexEventListener.initialize(FullTextIndexEventListener.java:130)
at org.hibernate.search.hcore.impl.HibernateSearchIntegrator.integrate(HibernateSearchIntegrator.java:83)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:294)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
... 3 more


Here is my pom.xml file:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
    <artifactId>ForestSurf</artifactId>
    <groupId>ForestSurf</groupId>
    <version>1.0</version>
  </parent>

    <groupId>ForestSurf</groupId>
    <artifactId>ForestSurf-ejb</artifactId>
    <version>1.0</version>
    <packaging>ejb</packaging>

    <name>ForestSurf-ejb</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <log4j.version>1.2.14</log4j.version>
        <hibernate.version>4.1.7.Final</hibernate.version>
        <org.springframework-version>3.0.7.RELEASE</org.springframework-version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.1.4.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.5.6-Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search</artifactId>
            <version>4.2.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-envers</artifactId>
            <version>${hibernate.version}</version>

            <exclusions>
                <exclusion>
                    <groupId>dom4j</groupId>
                    <artifactId>dom4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
       
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
            <type>jar</type>

        </dependency>
        <dependency>
                <groupId>org.apache.lucene</groupId>
                <artifactId>lucene-snowball</artifactId>
                <version>3.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-core</artifactId>
            <version>4.0.0</version>
        </dependency>
        <dependency>
                <groupId>org.apache.lucene</groupId>
                <artifactId>lucene-analyzers-common</artifactId>
                <version>4.0.0</version>
        </dependency>
<!--        <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-search-engine</artifactId>
                <version>4.1.1.Final</version>
        </dependency>-->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.8</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ejb-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <ejbVersion>3.1</ejbVersion>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>6.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>


Thanks
Sam


Top
 Profile  
 
 Post subject: Re: Search result sort by Geo-location range.
PostPosted: Mon Jan 21, 2013 10:14 am 
Regular
Regular

Joined: Fri Feb 04, 2011 8:34 pm
Posts: 66
I changed all packages in the pom.xml file to all latest version, but it still thrown the same exception. The pom.xml file is shown as below:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
    <artifactId>ForestSurf</artifactId>
    <groupId>ForestSurf</groupId>
    <version>1.0</version>
  </parent>

    <groupId>ForestSurf</groupId>
    <artifactId>ForestSurf-ejb</artifactId>
    <version>1.0</version>
    <packaging>ejb</packaging>

    <name>ForestSurf-ejb</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <log4j.version>1.2.14</log4j.version>
        <hibernate.version>4.1.7.Final</hibernate.version>
        <org.springframework-version>3.0.7.RELEASE</org.springframework-version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.1.9.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.5.6-Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search</artifactId>
            <version>4.2.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>3.2.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-envers</artifactId>
            <version>4.1.9.Final</version>

            <exclusions>
                <exclusion>
                    <groupId>dom4j</groupId>
                    <artifactId>dom4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
       
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.1.9.Final</version>
            <type>jar</type>

        </dependency>
        <dependency>
                <groupId>org.apache.lucene</groupId>
                <artifactId>lucene-snowball</artifactId>
                <version>3.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-core</artifactId>
            <version>4.0.0</version>
        </dependency>
        <dependency>
                <groupId>org.apache.lucene</groupId>
                <artifactId>lucene-analyzers-common</artifactId>
                <version>4.0.0</version>
        </dependency>
<!--        <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-search-engine</artifactId>
                <version>4.1.1.Final</version>
        </dependency>-->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.2</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ejb-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <ejbVersion>3.1</ejbVersion>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>6.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>


Top
 Profile  
 
 Post subject: Re: Search result sort by Geo-location range.
PostPosted: Wed Jan 23, 2013 9:23 am 
Regular
Regular

Joined: Fri Feb 04, 2011 8:34 pm
Posts: 66
Hi how to combine .spatial() with other queries?

eg. how to add spatial() to my current queries:

Code:
QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity( ProductArticle.class ).get();
        org.apache.lucene.search.Query query = null;

        if (StringUtils.isNotEmpty(state) && StringUtils.isNotEmpty(postcode)) {

            if (StringUtils.isNotEmpty(parentCategoryName)) {
                query = qb
                        .bool()
                            .must(qb.keyword().onFields("header", "aDesc").matching(termsStr).createQuery())
                            .must(qb.keyword().onField("state").matching(state).createQuery())
                            .must(qb.keyword().onField("postcode").matching(postcode).createQuery())
                            .must(qb.keyword().onField("parentCategoryName").matching(parentCategoryName).createQuery())
                           
                        .createQuery();


Thanks
Sam


Top
 Profile  
 
 Post subject: Re: Search result sort by Geo-location range.
PostPosted: Wed Jan 23, 2013 9:31 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Like you combine any other query. In your example you use bool() to create boolean queries out of multiple queries: each of the

qb.[....].createQuery()

can be either a keyword(), a phrase(), a spatial(), etc...

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Search result sort by Geo-location range.
PostPosted: Wed Jan 23, 2013 10:52 am 
Regular
Regular

Joined: Fri Feb 04, 2011 8:34 pm
Posts: 66
Thank you for your suggestion.
What about sorting?
In the example as shown below:

Code:
double centerLatitude = 24.0d;
double centerLongitude = 32.0d;

QueryBuilder builder = fullTextSession.getSearchFactory()
   .buildQueryBuilder().forEntity( POI.class ).get();
org.apache.lucene.search.Query luceneQuery = builder.spatial()
      .onCoordinates("location")
      .within(100, Unit.KM)
      .ofLatitude(centerLatitude)
      .andLongitude(centerLongitude)
   .createQuery();

FullTextQuery hibQuery = fullTextSession.createFullTextQuery(luceneQuery, POI.class);
Sort distanceSort = new Sort(
    new DistanceSortField(centerLatitude, centerLongitude, "location"));
hibQuery.setSort(distanceSort);

It is sorting on "location", but the example doesn't describe what this "location" is.
The example is only declare Latitude and Longitude in the entity.

Thanks
Sam


Top
 Profile  
 
 Post subject: Re: Search result sort by Geo-location range.
PostPosted: Wed Jan 23, 2013 12:22 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Thanks you're right that's not explained properly; opened: https://hibernate.onjira.com/browse/HSEARCH-1263

The "location" in that example is the name of the Spatial field you're using; usually you need a name to identify which pair of coordinates you're targeting.

See also http://docs.jboss.org/hibernate/search/4.2/reference/en-US/html_single/#spatial-multiplecoordinates

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Search result sort by Geo-location range.
PostPosted: Wed Jan 23, 2013 8:08 pm 
Regular
Regular

Joined: Fri Feb 04, 2011 8:34 pm
Posts: 66
Hi I got further exception when I deployed the ejb module:

Quote:
11:06:14,457 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC00001: Failed to start service jboss.deployment.subunit."ForestSurf-ear-1.1.ear"."ForestSurf-ejb-1.0.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."ForestSurf-ear-1.1.ear"."ForestSurf-ejb-1.0.jar".POST_MODULE: Failed to process phase POST_MODULE of subdeployment "ForestSurf-ejb-1.0.jar" of deployment "ForestSurf-ear-1.1.ear"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885) [rt.jar:1.6.0_07]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907) [rt.jar:1.6.0_07]
at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_07]
Caused by: java.lang.RuntimeException: Error getting reflective information for class ForestSurf.entity.facade.MyisamProductArticleFacade with ClassLoader ModuleClassLoader for Module "deployment.ForestSurf-ear-1.1.ear.ForestSurf-ejb-1.0.jar:main" from Service Module Loader
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:70) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:58)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.handleAnnotations(InterceptorAnnotationProcessor.java:85)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:70)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:55)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
... 5 more
Caused by: java.lang.NoClassDefFoundError: org/hibernate/search/spatial/impl/DistanceSortField
at java.lang.Class.getDeclaredFields0(Native Method) [rt.jar:1.6.0_07]
at java.lang.Class.privateGetDeclaredFields(Class.java:2291) [rt.jar:1.6.0_07]
at java.lang.Class.getDeclaredFields(Class.java:1743) [rt.jar:1.6.0_07]
at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:57) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
... 10 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.search.spatial.impl.DistanceSortField from [Module "deployment.ForestSurf-ear-1.1.ear.ForestSurf-ejb-1.0.jar:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) [rt.jar:1.6.0_07]


Here is the import statements:

Code:
import org.hibernate.search.jpa.FullTextEntityManager;
import org.hibernate.search.query.dsl.QueryBuilder;
import org.hibernate.search.query.dsl.Unit;
import org.hibernate.search.spatial.impl.DistanceSortField;

...

Sort distanceSort = new Sort(new DistanceSortField(lat, lon, "location"));

Thanks
Sam


Top
 Profile  
 
 Post subject: Re: Search result sort by Geo-location range.
PostPosted: Thu Jan 24, 2013 2:12 am 
Regular
Regular

Joined: Fri Feb 04, 2011 8:34 pm
Posts: 66
Code:
import org.hibernate.search.spatial.impl.DistanceSortField;


This import statement seem to be a bit odd.
should it be something like this:

Code:
import org.hibernate.search.spatial.DistanceSortField;


or

Code:
import org.hibernate.search.spatial.service.DistanceSortField;


Thanks
Sam


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.