I want to use xapian as a full text search engine. However, when I
initialize it with the following method, I see no errors, but nothing
writes to the database. If I copy all of the code into view, it works.
However, this is not an option since I can only use a single connection for
writing to the database, so it needs to be shared amongst all threads. I
would like to initialize it in __init__.py, but I must be doing something
wrong.
I added this code to models.py:
import xapian
class XapianDB(object):
def __init__(self):
self.indexer = xapian.TermGenerator()
stemmer = xapian.Stem("english")
self.indexer.set_stemmer(stemmer)
def connect(self, xapdb_path):
self.xapdb = xapian.WritableDatabase(xapdb_path, xapian.
DB_CREATE_OR_OPEN)
def add_startup(self, startup):
doc = xapian.Document()
self.indexer.set_document(doc)
self.indexer.index_text(startup.name, 1, 'S')
self.indexer.index_text(startup.headquarters, 1, 'XH')
self.indexer.index_text(startup.name)
self.indexer.increase_termpos()
self.indexer.index_text(startup.headquarters)
doc.set_data("look at all of this data")
idterm = "Q" + str(startup.id)
doc.add_boolean_term(idterm)
self.xapdb.replace_document(idterm, doc)
xapp = XapianDB()
Then in __init__.py I added
from .models import xapp
def main(global_config, **settings):
#... other code
xapp.connect("/path/to/xapiandb")
And I make a silly view:
from .models import xapp
class ViewFrontpage(ViewWarlock):
def __init__(self, context, request):
ViewWarlock.__init__(self, context, request)
@view_config(route_name='test3', renderer='templates/test2.jinja2')
def test3(self):
startup.name = "a name"
startup.long_info = "we will always be there doing the best that we
can do for the people we care about"
startup.id = 100
startup.headquarters = "Gainesville, Georgia"
xapp.add_startup(startup)
return {'gibs': self.gibs,
}
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.