本文整理匯總了Python中whoosh.index.EmptyIndexError方法的典型用法代碼示例。如果您正苦於以下問題:Python index.EmptyIndexError方法的具體用法?Python index.EmptyIndexError怎麽用?Python index.EmptyIndexError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類whoosh.index
的用法示例。
在下文中一共展示了index.EmptyIndexError方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from whoosh import index [as 別名]
# 或者: from whoosh.index import EmptyIndexError [as 別名]
def __init__(self, config, api):
self.config = config
self.api = api
self.cache_dir = user_cache_dir('fac', appauthor=False)
self.storage = FileStorage(os.path.join(self.cache_dir, 'index'))
self.schema = Schema(
name=TEXT(sortable=True, phrase=True, field_boost=3,
analyzer=intraword),
owner=TEXT(sortable=True, field_boost=2.5,
analyzer=intraword),
title=TEXT(field_boost=2.0, phrase=False),
summary=TEXT(phrase=True),
downloads=NUMERIC(sortable=True),
sort_name=SortColumn(),
name_id=ID(stored=True),
)
try:
self.index = self.storage.open_index()
except EmptyIndexError:
self.index = None
self.db = JSONFile(os.path.join(self.cache_dir, 'mods.json'))
示例2: setup
# 需要導入模塊: from whoosh import index [as 別名]
# 或者: from whoosh.index import EmptyIndexError [as 別名]
def setup(self):
"""
Defers loading until needed.
"""
from haystack import connections
new_index = False
# Make sure the index is there.
if self.use_file_storage and not os.path.exists(self.path):
os.makedirs(self.path)
new_index = True
if self.use_file_storage and not os.access(self.path, os.W_OK):
raise IOError("The path to your Whoosh index '%s' is not writable for the current user/group." % self.path)
if self.use_file_storage:
self.storage = FileStorage(self.path)
else:
global LOCALS
if LOCALS.RAM_STORE is None:
LOCALS.RAM_STORE = RamStorage()
self.storage = LOCALS.RAM_STORE
self.content_field_name, self.schema = self.build_schema(connections[self.connection_alias].get_unified_index().all_searchfields())
self.parser = QueryParser(self.content_field_name, schema=self.schema)
if new_index is True:
self.index = self.storage.create_index(self.schema)
else:
try:
self.index = self.storage.open_index(schema=self.schema)
except index.EmptyIndexError:
self.index = self.storage.create_index(self.schema)
self.setup_complete = True
示例3: setup
# 需要導入模塊: from whoosh import index [as 別名]
# 或者: from whoosh.index import EmptyIndexError [as 別名]
def setup(self):
"""
Defers loading until needed.
"""
from haystack import connections
new_index = False
# Make sure the index is there.
if self.use_file_storage and not os.path.exists(self.path):
os.makedirs(self.path)
new_index = True
if self.use_file_storage and not os.access(self.path, os.W_OK):
raise IOError("The path to your Whoosh index '%s' is not writable for the current user/group." % self.path)
if self.use_file_storage:
self.storage = FileStorage(self.path)
else:
global LOCALS
if getattr(LOCALS, 'RAM_STORE', None) is None:
LOCALS.RAM_STORE = RamStorage()
self.storage = LOCALS.RAM_STORE
self.content_field_name, self.schema = self.build_schema(
connections[self.connection_alias].get_unified_index().all_searchfields())
self.parser = QueryParser(self.content_field_name, schema=self.schema)
if new_index is True:
self.index = self.storage.create_index(self.schema)
else:
try:
self.index = self.storage.open_index(schema=self.schema)
except index.EmptyIndexError:
self.index = self.storage.create_index(self.schema)
self.setup_complete = True
示例4: setup
# 需要導入模塊: from whoosh import index [as 別名]
# 或者: from whoosh.index import EmptyIndexError [as 別名]
def setup(self):
"""
Defers loading until needed.
"""
from haystack import connections
new_index = False
# Make sure the index is there.
if self.use_file_storage and not os.path.exists(self.path):
os.makedirs(self.path)
new_index = True
if self.use_file_storage and not os.access(self.path, os.W_OK):
raise IOError("The path to your Whoosh index '%s' is not writable for the current user/group." % self.path)
if self.use_file_storage:
self.storage = FileStorage(self.path)
else:
global LOCALS
if getattr(LOCALS, 'RAM_STORE', None) is None:
LOCALS.RAM_STORE = RamStorage()
self.storage = LOCALS.RAM_STORE
self.content_field_name, self.schema = self.build_schema(connections[self.connection_alias].get_unified_index().all_searchfields())
self.parser = QueryParser(self.content_field_name, schema=self.schema)
if new_index is True:
self.index = self.storage.create_index(self.schema)
else:
try:
self.index = self.storage.open_index(schema=self.schema)
except index.EmptyIndexError:
self.index = self.storage.create_index(self.schema)
self.setup_complete = True