PyHyperEstraier

HyperEstraier client API implemented with pure Python. It works with synchronous manner. Since version 0.10, it also works with asyn manner based on Twisted library.

Bug List

If you have any issues, please mail to me( liris.pp [at] gmail.com ).

Download

0.10.x

Source Code

ChangeLog

  • 0.10.10
    • use 'replace' flag when decoding string.
  • 0.10.9
    • fix the parse error in search result for the snippet which contains empty line.
  • 0.10.8
    • If the max size or skip size is set, the search result was None. fix it.

Example

Synchronous Mode

Example code using Blocking API.

# -*- coding: utf-8 -*-
import hyperestraier

node = hyperestraier.Node()
node.set_url("http://localhost:1978/node/test")
node.set_auth("admin", "admin")


doc = hyperestraier.Document()
doc.add_attr("@uri", u"http://localhost/example10.txt")
doc.add_attr("@title", u"Over the rainbowテスト")
doc.add_text(u"テストThere's a land that I heard of once in a lullaby.")
doc.add_text(u"ストテSomewhere over the rainbow.  Way up high.")
node.put_doc(doc)

cond = hyperestraier.Condition()
cond.set_phrase(u"ストテ")
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

Asyn(Twisted-enabled) Mode

Twisted non-blocking API are supported. If you want to use, please specify AsynTransport for Node costructor of hyperestraier.

Non-blocking API always return deferred(twisted.internet.defer.Deferred) object. When we get result, the callback function will be called. The callback will be called with one argument. The argument is the same as blocking API return value.

import twisted.internet import reactor, defer
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()