简体   繁体   English

使用Google App Engine和Search API进行邻近搜索

[英]Proximity Search with Google App Engine and Search API

I am using Python2.7, Google App Engine 1.9.* and Search API. 我正在使用Python2.7,Google App Engine 1.9。*和Search API。 I store location-enabled points of interest. 我存储启用位置的兴趣点。 Now I want to implement GET that returns all points of interest within certain proximity from a given location. 现在,我想实现GET,该GET返回给定位置在一定距离内的所有兴趣点。

Examples that I found in Google Search API Basics online document refer to sorting of the query results. 我在Google Search API Basics联机文档中找到的示例涉及查询结果的排序 This same example can be found as complete source package at github repo appengine-search-python-java . 可以在github repo appengine-search-python-java上找到作为同一源代码包的同一示例。 Whatever the query string is, the found points of interest (Stores in the example) are listed in the proximity order, nearest first. 无论查询字符串是什么,找到的兴趣点(在示例中为商店)都以接近顺序列出,最接近的是第一。

There are also examples as to how to limit returned values by certain number of items. 还有一些示例,说明如何通过一定数量的项目限制返回值。 More Complex Search API Queries tutorial, section Query Options “更复杂的搜索API查询”教程的“查询选项”部分

search_query = search.Query(
query_string=query.strip(),
options=search.QueryOptions(
    limit=doc_limit,
...

However my use case requires cut-off to be a distance, not a hard number of items. 但是,我的用例要求截断距离一定,而不是很多项目。 Does anyone have an example of that? 有人有这样的例子吗?

Oops, did not read closely enough, the answer is in the same place Location-Based Queries (Geosearch) 糟糕,阅读不够仔细,答案在同一位置基于位置的查询(Geosearch)

# a query string like this comes from the client
query = "distance(store_location, geopoint(-33.857, 151.215)) < 45000"
try:
  index = search.Index(config.STORE_INDEX_NAME)
  search_results = index.search(query)
 for doc in search_results:
    # process doc ...
except search.Error:
  # ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM