Commit 86f5a600 authored by Michal Čihař's avatar Michal Čihař

Use FileStorage wrapper class

parent d1712462
...@@ -25,6 +25,7 @@ Whoosh based full text search. ...@@ -25,6 +25,7 @@ Whoosh based full text search.
import whoosh import whoosh
import os import os
from whoosh.fields import Schema, TEXT, ID from whoosh.fields import Schema, TEXT, ID
from whoosh.filedb.filestore import FileStorage
from django.db.models.signals import post_syncdb from django.db.models.signals import post_syncdb
from weblate import appsettings from weblate import appsettings
from whoosh.index import create_in, open_dir from whoosh.index import create_in, open_dir
...@@ -127,15 +128,21 @@ class Index(object): ...@@ -127,15 +128,21 @@ class Index(object):
_source = None _source = None
_target = {} _target = {}
def __init__(self):
'''
Creates searcher object.
'''
self.storage = FileStorage(appsettings.WHOOSH_INDEX)
def source(self): def source(self):
''' '''
Returns source index. Returns source index.
''' '''
if self._source is None: if self._source is None:
try: try:
self._source = open_dir( self._source = self.storage.open_index(
appsettings.WHOOSH_INDEX, indexname='source',
indexname='source' schema=SOURCE_SCHEMA,
) )
except (whoosh.index.EmptyIndexError, IOError): except (whoosh.index.EmptyIndexError, IOError):
# eg. path or index does not exist # eg. path or index does not exist
...@@ -148,9 +155,9 @@ class Index(object): ...@@ -148,9 +155,9 @@ class Index(object):
''' '''
if not lang in self._target: if not lang in self._target:
try: try:
self._target[lang] = open_dir( self._target[lang] = self.storage.open_index(
appsettings.WHOOSH_INDEX, indexname='target-%s' % lang,
indexname='target-%s' % lang schema=TARGET_SCHEMA,
) )
except (whoosh.index.EmptyIndexError, IOError): except (whoosh.index.EmptyIndexError, IOError):
self._target[lang] = create_target_index(lang) self._target[lang] = create_target_index(lang)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment