GAE简单搜索+自动完成

编程入门 行业动态 更新时间:2024-10-25 20:22:34
本文介绍了GAE简单搜索+自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

该网站的其中一个问题是很难找到特定的游戏您需要,因为用户必须到字母列表中去找到他们想要的。

它使用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简单搜索+自动完成

本文发布于:2023-11-30 00:34:17,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自动完成   简单   GAE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!