6

I want to build a auto complete feature for a tags field like in SO on App Engine ... any idea how I should go about the process?

Server Side Algo? - What logic should be there for auto-complete?

App Engine implementation? - What should be the Datastore schema for this?

Paulo Scardine
  • 60,096
  • 9
  • 116
  • 138
Jumbo
  • 513
  • 3
  • 8
  • 14

3 Answers3

8

Hey. I came around this question a few days ago. The datastore schema doesn't really matter as long as you have a StringProperty field that you'd like to search on. Since App Engine does not support full text searching yet, you'll have to go with some sort of a "starts with" search, which is not 100% but quite okay for looking up tags.

There's a discussion on how to implement basic search on GAE on the Google Code blog which was done for Google I/O 2010. The code is written in Java but the principles are the same: http://googlecode.blogspot.com/2010/05/google-app-engine-basic-text-search.html

As to the logic, well this is totally up to you. I saw systems that use "starts with" queries on every key press, others use LIKE queries. But the limitations of GAE don't allow LIKE queries. More discussions in this thread: Google App Engine: Is it possible to do a Gql LIKE query?

Community
  • 1
  • 1
kovshenin
  • 28,348
  • 4
  • 32
  • 43
6

Your question is more about javascript (client side) than GAE (server side).

You should start from something like jQuery AutoComplete. If the number of tags is small you can just embed the data in the html, otherwise look at the examples using AJAX calls.

If you go AJAX then you need something at the server side - all you have to do is put up some URL that accepts a query and returns JSON formated data. I like to use Django on GAE, it has nice serializers for this.

Paulo Scardine
  • 60,096
  • 9
  • 116
  • 138
  • Hi Paulo, I asked a similar question given the context of my code. If you could give it a look, I would appreciate it so much: http://stackoverflow.com/questions/25979567/jquery-autocomplete-with-remote-json-source-google-app-engine-python – hyang123 Oct 04 '14 at 19:00
1

Just posted 2 part series on implementing autocomplete with GAE: server-side service with Python and continuation using YUI3 AutoComplete plugin.

In particular, using autocomplete for tags similar to SO YUI3 AutoComplete plugin offers option queryDelimiter which lets you define separator before selecting string to match. Thus, if it is set to space then plugin matches every new word typed in the textbox:

YUI().use('autocomplete', function (Y) {

      Y.one('body').addClass('yui3-skin-sam');

      // AutoComplete on search input field
      Y.one('#search_field').plug(Y.Plugin.AutoComplete, {
        queryDelimiter: ' ',
        source: '/rpc.xhr?action=ac_keywords&arg0={query}'
      }); 
});

The action ac_keywords (defined in GAE) looks up list tags that begin with typed string.

topchef
  • 17,019
  • 8
  • 58
  • 98