help with google app engine search api

63 views
Skip to first unread message

Sourabh Kumar

unread,
Aug 4, 2015, 2:06:04 AM8/4/15
to Google App Engine
Hey, 

i am new to gaepython, I have been trying to find nearby areas to a given location.. I found search api could do this, what i couldn't figure out is that what will be config.STORE_INDEX_NAME. When is used this exact code it says " NameError: name 'config' is not defined"


from google.appengine.api import search

query = "distance(geopoint(35.2, 40.5), geopoint(35.2, 40.5)) < 100"
index = search.Index(config.STORE_INDEX_NAME)
search_results = index.search(query)

Thanks in advance

Mihail Russu

unread,
Aug 4, 2015, 4:37:05 AM8/4/15
to Google App Engine
The only required parameter of the `search.Index` function is `name` which is normally a string, so it's safe to assume that `config.STORE_INDEX_NAME` simply stores the name of the index where you will be performing your search so you could've had something like `search.Index(name='my_index')` instead. Note that if you haven't previously added anything to that index  - the search will not return anything.

It looks like you're following the "More Complex Search API Queries" tutorial which assumes you already have some basic familliarity with the Search API but if you don't, you should start with the "Search API Basics" tutorial first which will explain you how to index your data first and then query it.

Thanks,
Mihail.

Sourabh Kumar

unread,
Aug 4, 2015, 5:20:09 AM8/4/15
to Google App Engine
Thanks Mihail Russu

Sourabh Kumar

unread,
Aug 4, 2015, 11:05:38 AM8/4/15
to Google App Engine
survey_marker = ndb.GeoPt("35.2, 40.5")
query = "distance(survey_marker , geopoint(35.2, 40.5)) < 10000"
index = search.Index(name="myIndex")
search_results = index.search(query)
print search_results
for doc in search_results:
    print doc

I tried this but it always gives this result on exectuing : 
search.SearchResults(number_found=0L)

Also read an thread on this at stackoverflow which says it doesnt works on local machine.. so I deployed a test application but the result is no different. 
Plz help me with this.

Mihail Russu

unread,
Aug 4, 2015, 11:09:13 AM8/4/15
to Google App Engine
Did you add anything into your index before querying it? Can you see your data on the admin page (i.e. http://127.0.0.1:8000/search/index )? Can you show how you're indexing things?

Thanks,
Mihail.

Sourabh Kumar

unread,
Aug 4, 2015, 11:30:45 AM8/4/15
to Google App Engine
survey_marker= ndb.GeoPt("35.1, 40.0")
d = search.Document(fields=survey_marker)
search.Index(name="locate_this").put(d)
query_obj= "distance(survey_marker , geopoint(35.2, 40.5)) < 10000"
results = search.Index(name=locate_this).search(query=query_obj)
print results
for doc in results:
    print doc

I wasnt indexing earlier. but as i have indexed now(hopefully it is right ) it returns TypeError: 'GeoPt' object is not iterable. btw I m doing this on interactive console

Mihail Russu

unread,
Aug 4, 2015, 11:45:11 AM8/4/15
to Google App Engine
Your ndb.GeoPt part should probably look something like:

survey_marker = ndb.GeoPt(lat=35.1, lon=40.0)

Testing things in interactive console is perfectly normal.

Also, note that your index name needs to be persistent between your examples (it was "myIndex" in your previous message, "locate_this" in this one and as a variable locate_this (not a string)).

As per the tutorial I mentioned in my first response, the "fields" parameter of "search.Document" accepts a list of named fields, not just a field. Again, try going over the tutorial as it has answers to all of the issues you've had here so far.

Thanks,
Mihail.
Reply all
Reply to author
Forward
0 new messages