Search code examples
google-app-enginegeospatialgoogle-search-api

Is it possible to use a document field as radius with distance function in Google search API?


I have stored circular approximations of trajectory data as documents via the Google Search API. That means I am calculating the circumcircle around an arbitrary trajectory and storing the middle point as geo point field with longitude and latitude into the document. In addition to that I save the radius of the circle as number field.

Now I want to query my documents in the following way:

"distance(middlePoint, geopoint(35.2, 40.5)) <= radius"

I want to use the distance function with a fixed location in longitude and latitude and the field where I stored the circle middle. So far, so good. The problem seems to be that I cannot use a field (in my case the circle radius) as comparative value for the distance.

However, I do not get any exceptions when I am trying to execute the query. It's just seems that the radius field does not get interpreted and I never receive any results from the query.

I've been googling a lot now and also studied the documentation carefully but I did not find any hint that my kind of query really is impossible.

The background of my query is that I kinda want to invert the usual query of the form "Find all points that are in a specific radius from a given point" to a query like "Find all circles that contain a given point in their circumference".

Has anyone ever tried something like this or can provide some information why the query is not working? I am also open for alternative solutions for my query.


Solution

  • The search API does not support queries on the form fieldname = other_fieldname. Everything on the right side of the relational operator is interpreted as a constant to search for.

    How big is the maximum possible radius compared to the smallest possible one? If the difference isn't unreasonably big, perhaps one viable implementation would be do your query with the maximum possible radius and then do a second filtering pass in your own code to get down to the desired radius. Perhaps also use a Sort Expression to sort the results by the distance between middlePoint and the input point. Might help failing faster.