该网站的其中一个问题是很难找到特定的游戏您需要,因为用户必须到字母列表中去找到他们想要的。
它使用webapp框架以Python编写的Google App Engine运行。
>至少我需要一种简单的方法通过名字搜索游戏。从外观来看,使用Javascript进行搜索可能更容易。我更喜欢自动完成功能。我试图找出如何去做这件事,似乎唯一的办法是创建一个巨大的索引,每个名称分解成不同的输入阶段(S,Sh,Sho.. 购物车英雄)。
有没有办法简单容易地做到这一点?我开始认为我必须在PHP + MySql服务器上创建一个Web服务并使用它进行搜索。 解决方案
我写了下面的代码来处理这个问题。基本上,我将所有可能的单词开始保存在列表中而不是整个句子中。这就是这个网站的jquery自动完成功能。
import unicodedata import re splitter = repile(r'[\s | \- | \)| \\ \\(| /] +') $ b $ def def remove_accents(text): nkfd_form = unicodedata.normalize('NFKD',unicode(text)) return u。 join([c for c in nkfd_form if not unicodedatabining(c)]) $ b $ def get_words(text): return [s.lower()for s in splitter.split如果s!=''] def get_unique_words(text): word_set = set(get_words(text)) return word_set $ remove_accents(text) b $ b def get_starts(text): word_set = get_unique_words(text) starts = set() for word_set: for i in range(len(word) ): starts.add(word [:i + 1])$ b $ b return sorted(starts)
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.
解决方案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 unicodedata import re splitter = repile(r'[\s|\-|\)|\(|/]+') def remove_accents(text): nkfd_form = unicodedata.normalize('NFKD', unicode(text)) return u"".join([c for c in nkfd_form if not unicodedatabining(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)
更多推荐
GAE简单搜索+自动完成
发布评论