romain (3) [Avatar] Offline
#1
Hi guys,

I'm integrating hibernate search in a local search project. Is there a way to index and query spatial objects.

We have a database of geo-located places and it would be really great to perform hibernate search + spatial queries.

We need to migrate (from standard EJB/QL to using hibernate search queries) this query for exemple :

String qBuf = "select poi " +
"from POI as poi " +
"where LOWER(poi.nameBase) LIKE :poiName " +
" AND poi.revisionState = :revState " +
" AND spatial.X(poi.location) < smilieMax " +
" AND spatial.X(poi.location) > smilieMin " +
" AND spatial.Y(poi.location) < :yMax " +
" AND spatial.Y(poi.location) > :yMin " +
"order by poi.nbBookmark DESC " +
" , poi.nbReview DESC " +
" , poi.nameBase ASC";
Query q = em.createQuery(qBuf);
q.setParameter("poiName", "%" + poiName.toLowerCase() + "%");
q.setParameter("revState", RevisionState.ACT);
q.setParameter("xMax", northEastLng);
q.setParameter("xMin", southWestLng);
q.setParameter("yMax", northEastLat);
q.setParameter("yMin", southWestLat);
q.setFirstResult(offset);
q.setMaxResults(maxResult);

return (List<POI>smilie q.getResultList();

Data are stored in a postgresql database + postgis. We use the original library from Norman Barker to map and query the spatial columns with JPA and EJB3 (it has been taken over by http://www.hibernatespatial.org now I guess).

I asked the same question to Norman Barker. Here is his answer :

-----------------------------------------------------
Romain,

your site looks very good. The EJB3 code in PostGIS has been used by
several companies, and it works, however I think it has been taken
over by http://www.hibernatespatial.org now, but the code is still in
SVN for reference and I prefer it since it is very simple.

I have not seriously looked into hooking up hibernate search and
postgis, though I think it would be possible. A good first start
would be hook to up the OpenSearch interface with perhaps the
geographic extensions? Hibernate search just returns the primary keys
of the entity matching the input search terms so I think hooking the
two together would be very simple.

Good luck with your site!

Norman
------------------------------------------------

Did someone already investigate this ?

Thanks for your help.