本站首页    管理页面    写新日志    退出


«October 2025»
1234
567891011
12131415161718
19202122232425
262728293031


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7627095
建立时间:2006年5月29日




[Django]Merquery Summer of Code Results
软件技术

lhwork 发表于 2007/2/1 11:52:44

http://blog.case.edu/bmb12/2006/08/merquery_summer_of_code_resultsThis morning I commited a working version of Merquery to the Django Subversion repository.svn co http://code.djangoproject....My code in particular lives in branches/search-api/django/contrib/search.The Lucene adapter is fully functional (but needs some more convenience functions), and the Xapian and Hyper Estraier adapters need a little more work.Here's an example of using the Lucene adapter, using a similar model to my old Merquery post:from django.db import modelsfrom django.contrib.search.backends import LuceneIndexerclass Person(models.Model):   first_name = models.CharField(maxlength=30)   last_name = models.CharField(maxlength=30)   biography = models.TextField()indexer = LuceneIndexer('/tmp/person-index', Person,                       fields=['Person.biography'],                       attributes={'first': 'Person.first_name',                                   'last': 'Person.last_name'})As you can see, you specify an index location (database locations should be supported in the future), which model should be considered the document (hit results), and which fields to index.It also allows shorthand for the fields:indexer = LuceneIndexer('/tmp/person-index', Person, 'Person.biography',                       first='Person.first_name', last='Person.last_name')Okay, let's insert some people...b = Person(first_name='Brian', last_name='Beck', biography='Python advocate')g = Person(first_name='Guido', last_name='van Rossum', biography='Python creator')s = Person(first_name='Spiros', last_name='Eliopoulos', biography='Loves Haskell')And force all the Person objects to be indexed...indexer.update()You can also send update a list of Person objects to update (beware of Lucene's update inserting duplicates for now).Finally, Lucene's sweet query syntax is available for your database:>>> for hit in indexer.search('python'):...     print hit, hit.instance >>> for hit in indexer.search('python creator'):...     print hit, hit.instance >>> for hit in indexer.search('last:Beck OR first:Spiros'):...     print hit, hit.instance There are some things that should be changed before Merquery is production-ready, and some things that would be nice in the long-term.One is that the indexer knows how to follow ForeignKey fields (maybe 'Person.address.street_name', for example), but there needs to be a couple changes to get them to work—this is a result of a Field instance seemingly not having an attribute linking back to the Model it is bound to. Support for ManyToMany joins also needs to be thought out.Another is the way you pass Model instances to specify as the document return type (the type returned by hit.instance). Documents should be able to aggregate many Model instances and not have to consider any particular Model the document type. So a Document class will probably be introduced that acts like the Model metaclass, letting you 'build' a Document prototype and telling the indexer how all of its attributes should be retrieved and treated.Automatically knowing when to update the index would also be very nice.There are a few main long-term goals...One is to make a universal Merquery query language that will automatically translate queries into the backend's query syntax. This would especially good for Hyper Estraier, which has whacked-out attribute-search syntax:@first STRINC BrianAnother is to make some Models to keep track of indexing status and query statistics, and offer nice admin views of these.Finally, storing all index data in a database (especially a Model-compatible one) instead of on the filesystem would be great.Since I have a week before classes start, I'm going to continue making the necessary changes to make Merquery production-ready.


阅读全文(2057) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.055 second(s), page refreshed 144794695 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号