Pure Python HyperEstraier
This project is moved to http://www.liris.org/trac/wiki/PyHyperEstraier .
Overview
This is HyperEstrraier pure python implementation.
From version 0.10.0, Twisted based non blocking APIs are supported. See example 2 for more detail.
ChangeLog
- 0.10.4
- fix backward compatibility with python 2.4
- 0.10.3
- cgi parameter escape bug fix
- 0.10.2
- typo
- 0.10.1
- raise exeception if error
- 0.10.0
- Twisted Non blocking api support.
- unicode support.
- patched by jun-g for doc_num, get_doc
View Source
view source code from here.
Example
node = hyperestraier.Node()
node.set_url("http://localhost:1978/node/test")
node.set_auth("admin", "admin")
doc = hyperestraier.Document()
doc.add_attr("@uri", "http://localhost/example.txt")
doc.add_attr("@title", "Over the rainbow")
doc.add_text("There's a land that I heard of once in a lullaby.")
doc.add_text("Somewhere over the rainbow. Way up high.")
node.put_doc(doc)
cond = hyperestraier.Condition()
cond.set_phrase("rainbow AND lullaby")
nres = node.search(cond, 0)
if nres:
for rdoc in nres.docs:
print "#" * 20
v = rdoc.attr("@uri")
print "URI: " + v
v = rdoc.attr("@title")
print "TITLE: " + v
print rdoc.snippet
Example 2 Non Blocking API
From version 0.10.0, Twsited non blocking APIs are suuported. If you want to use it, you specify the AsynTransport for hyperestraier's Node constructor.
non blocking api always return Deferred object. and callback it when you got the result.
callback function always need one argument. the argmen value is always the same as the blocking api return value.
import hyperestraier
@defer.deferredGenerator
def testUpdateAndSearch()
doc = hyperestraier.Document()
doc.add_attr("@uri", "http://localhost/example.txt")
doc.add_attr("@title", "Over the rainbow")
doc.add_text("There's a land that I heard of once in a lullaby.")
doc.add_text("Somewhere over the rainbow. Way up high.")
wfd = defer.waitForDeferred(node.put_doc(doc))
yield wfd
print wfd.getResult()
cond = hyperestraier.Condition()
cond.set_phrase("rainbow AND lullaby")
wfd = defer.waitForDeferred(node.search(cond, 0))
yield wfd
nres = wfd.getResult()
if nres:
for rdoc in nres.docs:
print "#" * 20
v = rdoc.attr("@uri")
print "URI: " + v
v = rdoc.attr("@title")
print "TITLE: " + v
print rdoc.snippet
node = hyperestraier.Node(hyperestraier.AysnTransport())
node.set_url("http://localhost:1978/node/test")
node.set_auth("admin", "admin")
testUpdateAndSearch()
reactor.run()