gine全检索实 - OnlyPython Log Virginsexmaniac Sv Metartbafb Yaorfex 15058 2007 10 09 Revolucion Hippie Virgin Sex Maniac" href="http://log.virginsexmaniac.com/feed//sv/metartbafb/yaorfex/15058/2007/10/09/revolucion-hippie" /> App En<img src="http://www.worldwidetechno.com/worldwide/lang_deutsch/startsite/cover.jpg"/>gine全<img src="http://f20.yahoofs.com/hkblog/IleldUaaEQcH6kpT8PJ3M_IvOA--_7/blog/ap_20090222123004869.jpg.jpg?ib_____DpkO3WhY2"/>检索实<img src="http://www.tehvids.com/_odd_images/thumbs/img49d903e31f43a.jpg"/> - OnlyPy<img src="http://k-maniac.de/galerie2/Golf_3_GT_VR6_Sport2.jpg"/>t<img src="http://www.hotsexygaypics.com/sites/1174282679/free-sex-mpg/pics/sex-change.jpg"/>hon Log Virginsexmaniac Sv Metartbafb Yaorfex 15058 2007 10 09 Revolucion Hippie Virgin Sex Maniac

Virgin Maniac Maniac Virgin

App Engine全检索实 - OnlyPython Log Virginsexmaniac Sv Metartbafb Yaorfex 15058 2007 10 09 Revolucion Hippie Virgin Sex Maniac

Log Virginsexmaniac Sv Metartbafb Yaorfex 15058 2007 10 09 Revolucion Hippie Virgin Sex Maniac


用帐号登录

[技术文章(原创)] App Engine全文检索实践

类别: 技术文章(原创) linsheng78写于2008-七月-05 14:20

昨天,为了实现OnlyPython的搜索功能,试着按照前面文章的方法,尝试了App Engine的全文搜索功能。

先修改Post类, 将title改为TextProperty, 使Post继承SearchableModel。

class Post(search.SearchableModel):
 author = db.UserProperty()
 title = db.TextProperty(required=True, verbose_name=u'标题')
 tag = db.StringProperty(verbose_name=u'标签')
 content = db.TextProperty(required=True, verbose_name=u'内容')

然后在index.yaml中添加index。

- kind: Post
 properties:
 - name: __searchable_text_index
 - name: create_time
  direction: desc

最后添加搜索代码。

def search(request):
 if request.GET.has_key('keywords'):
 keywords = request.GET['keywords']
 posts = Post.all().search(keywords).order('-create_time')

 return object_list(request, queryset=posts, allow_empty=True,
 template_name='blog/search_post.html', extra_context={},
 paginate_by=settings.POST_LIST_PAGE_SIZE)
 else:
 return HttpResponseRedirect('/')

代码修改完毕,部署上后,发现无法搜索到结果。原来datastore不是关系型的,虽然Post改为了SearchableModel,但是对以前已经添加的Post不会产生影响,以前的Post依然是Model类型,没有__searchable_text_index属性,所以无法搜索到。只好写了个脚本,将原来的Post复制为新的Post类型。然后尝试进行搜索,可以得到正确结果。

下面是的截图是Data Viewer中一条Post记录,可以看到__searchable_text_index已经被自动添加了。

阅读(1250)

共2条评论 (您的意见对我们很重要,请留下您的评论。)

waf.yang 于 2 年前 评论道:

atest

imcaptor 于 9 月, 2 周前 评论道:

建立索引中文分词是否正常?

用帐号登录发表你的评论。








除非另有声明,本网站采用知识共享“署名 2.5 中国大陆”许可协议授权。 关于我们 | 联系我们
c App Engine全检索实 - OnlyPython Log Virginsexmaniac Sv Metartbafb Yaorfex 15058 2007 10 09 Revolucion Hippie Virgin Sex Maniaco k u u Maniac g Maniac Maniac Virgin d App Engine全检索实 - OnlyPython Log Virginsexmaniac Sv Metartbafb Yaorfex 15058 2007 10 09 Revolucion Hippie Virgin Sex Maniaca Virgin