views:

289

answers:

2

I'm looking to create a search function for my flash game website.

One of the problems with the site is that it is difficult to find a specific game you want, as users must go to the alphabetical list to find one they want.

It's run with Google App Engine written in python, using the webapp framework.

At the very least I need a simple way to search games by their name. It might be easier to do searching in Javascript from the looks of it. I would prefer an autocomplete functionality. I've tried to figure out how to go about this and it seems that the only way is to create a huge index with each name broken up into various stages of being typed ("S", "Sh", "Sho" ... "Shopping Cart Hero").

Is there anyway to do this simply and easily? I'm beginning to think I'll have to create a web service on a PHP+MySql server and search using it.

A: 

Have you looked at gae-search? I believe the Django + jQuery "autocomplete" feature is not part of the free version (it's just in the for-pay premium version), but maybe it's worth a little money to you.

Alex Martelli
+2  A: 

I have written the code below to handle this. Basically, I save all the possible word "starts" in a list instead of whole sentences. That's how the jquery autocomplete of this site works.

import unicodedta
import re

splitter = re.compile(r'[\s|\-|\)|\(|/]+')

def remove_accents(text):
    nkfd_form = unicodedata.normalize('NFKD', unicode(text))
    return u"".join([c for c in nkfd_form if not unicodedata.combining(c)])

def get_words(text):    
    return [s.lower() for s in splitter.split(remove_accents(text)) if s!= '']

def get_unique_words(text):
    word_set = set(get_words(text))
    return word_set

def get_starts(text):
    word_set = get_unique_words(text)
    starts = set()
    for word in word_set:
        for i in range(len(word)):
            starts.add(word[:i+1])
    return sorted(starts)
jbochi