ObjectifyGeocellQueryEngine

187 views
Skip to first unread message

kc

unread,
Dec 19, 2011, 10:11:53 AM12/19/11
to javageomodel-discuss
Hi all,

I've created an Objectify implementation of GeocellQueryEngine for my
project. It uses GeocellQuery.baseQuery to specify comma separated
filter conditions and GeocellQuery.parameters as filter values.

Alex, I clicked on "reply to author" for the message
http://groups.google.com/group/javageomodel-discuss/browse_thread/thread/9d85a167e2163e38
just now thinking it was reply to that thread, sorry! :-)

Tested to be working in my own project, so feel free to use it or add
it to this project.

/**
* Objectify implementation for GeocellQueryEngine.
* <p>
* Example:
* <pre>
* // paramList contains values for each filter() condition
* List&lt;Object&gt; paramList = new ArrayList&lt;Object&gt;();
* paramList.add(q);
* paramList.add(q + "\uFFFD");
*
* // comma separated filter() conditions
* GeocellQuery baseQuery = new GeocellQuery("title &gt;=, title
&lt;", paramList);
* GeocellQueryEngine queryEngine = new
ObjectifyGeocellQueryEngine(ofy());
*
* // perform search
* GeocellManager.proximitySearch(
* new Point(lat, lng), maxResults, maxDistance,
* MyEntity.class,
* baseQuery, queryEngine,
GeocellManager.MAX_GEOCELL_RESOLUTION);
* </pre>
*/
public class ObjectifyGeocellQueryEngine implements GeocellQueryEngine
{
private String geocellsProperty;
private Objectify ofy;

public static final String DEFAULT_GEOCELLS_PROPERTY = "geocells";

public ObjectifyGeocellQueryEngine(Objectify ofy) {
this(ofy, DEFAULT_GEOCELLS_PROPERTY);
}

public ObjectifyGeocellQueryEngine(Objectify ofy, String
geocellsProperty) {
this.ofy = ofy;
this.geocellsProperty = geocellsProperty;
}

@Override
public <T> List<T> query(GeocellQuery baseQuery, List<String>
geocells, Class<T> entityClass) {
StringTokenizer st;
int tokenNo = 0;

Query<T> query = ofy.query(entityClass);

if (baseQuery != null) {
st = new StringTokenizer(baseQuery.getBaseQuery(), ",");
while (st.hasMoreTokens()) {
query.filter(st.nextToken(),
baseQuery.getParameters().get(tokenNo++));
}
}

return query.filter(geocellsProperty + " IN",
geocells).list();
}
}

Jordi P.S.

unread,
Jul 14, 2012, 7:55:42 AM7/14/12
to javageomod...@googlegroups.com
Hello,

I'm trying to use this class and I have some problems: specially with the Query class. Is this done for ofy3 or ofy4 ?
Do you mind to post the includes?

Thanks,
Jordi

Jeff Schnitzer

unread,
Jul 14, 2012, 3:11:22 PM7/14/12
to javageomod...@googlegroups.com
If you want to do proximity searches (as opposed to bounding boxes),
why not use the geo query feature built into the new search API?

I'm tempted to migrate although we do strict bounding-box queries right now.

Jeff

Tang Kin Chuen

unread,
Jul 15, 2012, 1:39:25 AM7/15/12
to javageomod...@googlegroups.com

It was developed for ofy3. I would also recommend looking at GAE's new features to see how this can be implemented more effectively if you're starting a new project.

Jordi P.S.

unread,
Jul 16, 2012, 4:19:20 AM7/16/12
to javageomod...@googlegroups.com
I adapted the code to ofy4, it was straightforward.

By now we are strictly doing bounding-boxes queries but we might do proximity ones in a future.

Do you think is worth using the new geo-search in the serach API ? 

By taking a deeper look to the serach API it looks like the bounding box searches could be approximated as a proximity search with radius equals to: sqrt(s1^2,s2^2)/2 being s1 and s2 the sizes of the sides of the bounding box. Then in the business layer the Markers out of the square box could be removed.

Anyone doing so already ?
Reply all
Reply to author
Forward
0 new messages