本文整理汇总了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