Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Saller <bcsaller@objectrealms.net>2007-05-23 20:10:50 (GMT)
committer Benjamin Saller <bcsaller@objectrealms.net>2007-05-23 20:10:50 (GMT)
commitaad8dcabbdf1a262742325f3bdbddbf77589ba5c (patch)
treefb40277cd047eb484f746ac29e9ccdfea9b88250
parent50abd7b5a34d8107abb49fe1635c719b2f80b010 (diff)
more modular internal/external indexing support
renamed file= in kwargs to filelike sometimes this is a file, StringIO or a filename
-rw-r--r--src/olpc/datastore/query.py24
-rw-r--r--tests/query.txt12
2 files changed, 20 insertions, 16 deletions
diff --git a/src/olpc/datastore/query.py b/src/olpc/datastore/query.py
index f5f6d93..e9beede 100644
--- a/src/olpc/datastore/query.py
+++ b/src/olpc/datastore/query.py
@@ -29,7 +29,7 @@ class QueryManager(object):
def __init__(self, metadata_uri,
language='en',
fulltext_repo='fulltext',
- async_index=False,
+ sync_index=True,
use_fulltext=True):
"""
The metadata_uri is a sqlalchemy connection string used to
@@ -40,9 +40,12 @@ class QueryManager(object):
additional control will be provided.
This will check keywords for:
- 'async_index' which determines if we use an internal
+ 'sync_index' which determines if we use an internal
sync index impl or an out of process one
- via DBus.
+ via DBus. If the async process is to be
+ used it must be properly configured and
+ available for DBus to spawn.
+
'fulltext_repo' the full filepath to which the fulltext
index data will be stored
'use_fulltext' when true indexing will be performed
@@ -52,10 +55,9 @@ class QueryManager(object):
self.language = language
self.content_ext = None
- self.use_fulltext = use_fulltext
self.fulltext_repo = fulltext_repo
- self.async_index = async_index
- self.sync_index = use_fulltext and async_index
+ self.use_fulltext = use_fulltext
+ self.sync_index = use_fulltext and sync_index
def prepare(self, datastore, backingstore):
"""This is called by the datastore with its backingstore and
@@ -77,7 +79,8 @@ class QueryManager(object):
self.prepare_db()
self.connect_model()
- self.connect_fulltext(self.fulltext_repo, self.language)
+ self.connect_fulltext(self.fulltext_repo, self.language,
+ read_only=not self.sync_index)
return True
def stop(self):
@@ -113,7 +116,7 @@ class QueryManager(object):
s.flush()
if self.sync_index and filelike:
- self.index.fulltext_index(c.id, filelike)
+ self.fulltext_index(c.id, filelike)
return c
def update(self, content_or_uid, props=None, filelike=None):
@@ -123,7 +126,7 @@ class QueryManager(object):
self._bindProperties(content, props, creating=False)
self.model.session.flush()
if self.sync_index and filelike:
- self.index.fulltext_index(content.id, filelike)
+ self.fulltext_index(content.id, filelike)
def _automaticProperties(self):
now = datetime.now()
@@ -208,7 +211,7 @@ class QueryManager(object):
s.delete(c)
s.flush()
if self.sync_index:
- self.index.fulltext_unindex(c.id)
+ self.fulltext_unindex(c.id)
def find(self, query=None, **kwargs):
@@ -467,6 +470,7 @@ class XapianFulltext(object):
if not os.path.exists(repo) and read_only is True:
# create the store
index = DocumentStore(repo, language, read_only=False)
+ index.close()
# and abandon it
self.index = DocumentStore(repo, language, read_only=read_only)
self.index.registerFlattener(unicode, flatten_unicode)
diff --git a/tests/query.txt b/tests/query.txt
index 6a86c8f..ff65455 100644
--- a/tests/query.txt
+++ b/tests/query.txt
@@ -180,7 +180,7 @@ manager provided the mime_type Property of the Content is one
understood by the index.
>>> from StringIO import StringIO
->>> qm.fulltext_index(a, StringIO("this is my content, hear it roar"))
+>>> qm.update(a, {}, StringIO("this is my content, hear it roar"))
>>> qm.find(fulltext="roar") == ([a], 1)
True
@@ -196,7 +196,7 @@ Calls to update() and create() both take an optional file argument
which will update the fulltext indexed content with the new value of
file.
->>> qm.update(a, file=StringIO("different text"))
+>>> qm.update(a, filelike=StringIO("different text"))
The new content will be found
>>> qm.find(fulltext="different", author="Benjamin") == ([a], 1)
@@ -209,7 +209,7 @@ And the old content is not.
Passing a filename for file works as well. Files can be in a variety
of binary formats include PDF.
->>> qm.update(a, file="test.doc")
+>>> qm.update(a, filelike="test.doc")
>>> qm.find(fulltext="roar", author="Benjamin")
([], 0)
>>> qm.find(fulltext="amazed", author="Benjamin") == ([a], 1)
@@ -217,16 +217,16 @@ True
We have converters for DOC, PDF and ODT by default
->>> qm.update(a, file="test.pdf")
+>>> qm.update(a, filelike="test.pdf")
>>> qm.find(fulltext="peek", author="Benjamin") == ([a], 1)
True
->>> qm.update(a, file="test.odt")
+>>> qm.update(a, filelike="test.odt")
>>> qm.find(fulltext="amazed", author="Benjamin") == ([a], 1)
True
->>> qm.update(a, file="test.doc")
+>>> qm.update(a, filelike="test.doc")
>>> qm.find(fulltext="amazed", author="Benjamin") == ([a], 1)
True