/usr/local/Hypy
annotate examples/search.py @ 139:d0a738aea316
Added tag 0.8.4.1 for changeset bbc3e3a3c4fb
| author | Cory Dodt <corymercurial@spam.goonmill.org> |
|---|---|
| date | Fri Oct 09 10:32:45 2009 -0700 (2009-10-09) |
| parents | 3b0b571962aa |
| children |
| rev | line source |
|---|---|
| corydodt+mercurial_spams@56 | 1 # hypy version of the estraiernative gather/search example |
| corymercurial@2 | 2 |
| corymercurial@2 | 3 from hypy import HDatabase, HCondition |
| corymercurial@2 | 4 |
| corymercurial@2 | 5 # open the database, read-only |
| corymercurial@2 | 6 db = HDatabase() |
| corymercurial@2 | 7 db.open('casket', 'r') |
| corymercurial@2 | 8 |
| corymercurial@2 | 9 # create a search condition object |
| corymercurial@2 | 10 cond = HCondition(u'lull*') |
| corymercurial@2 | 11 |
| corymercurial@2 | 12 # get the result of search |
| corymercurial@2 | 13 result = db.search(cond) |
| corymercurial@2 | 14 |
| corymercurial@2 | 15 # iterate the result |
| corymercurial@2 | 16 for doc in result: |
| corymercurial@2 | 17 # display attributes |
| corymercurial@2 | 18 print 'URI: %s' % (doc[u'@uri'].encode('utf-8'),) |
| corymercurial@2 | 19 print "Title: %s" % (doc[u'@title'].encode('utf-8'),) |
| corymercurial@2 | 20 |
| corymercurial@2 | 21 # display the body text |
| corymercurial@2 | 22 for t in doc.getTexts(): |
| corymercurial@2 | 23 print t.encode('utf-8') |
| corymercurial@2 | 24 |
| corymercurial@2 | 25 # close the database |
| corymercurial@2 | 26 db.close() |
