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