本文整理汇总了Python中whoosh.filedb.filestore.FileStorage.open_index方法的典型用法代码示例。如果您正苦于以下问题:Python FileStorage.open_index方法的具体用法?Python FileStorage.open_index怎么用?Python FileStorage.open_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类whoosh.filedb.filestore.FileStorage
的用法示例。
在下文中一共展示了FileStorage.open_index方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_index
# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import open_index [as 别名]
def get_index():
try:
storage = FileStorage(settings.WHOOSH_INDEX)
return storage.open_index(indexname="search")
except IOError:
# No index? other error?
create_index()
storage = FileStorage(settings.WHOOSH_INDEX)
return storage.open_index(indexname="search")
示例2: update_index
# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import open_index [as 别名]
def update_index(sender, instance, created, **kwargs):
if int(os.environ.get('SKIP_SEARCH_INDEX', '0')):
return
try:
url = unicode(instance.get_absolute_url())
except Exception:
log.critical('Cant resolve url. Content %r not indexed' % instance)
return
content = getattr(instance, 'content', None)
if content is None:
content = unicode(instance)
elif callable(content):
content = content()
storage = FileStorage(settings.WHOOSH_INDEX)
ix = storage.open_index(indexname='memopol')
writer = ix.writer()
if created:
writer.add_document(title=unicode(instance), content=content,
type=unicode(instance.__class__.__name__.lower()),
url=url)
writer.commit()
else:
writer.update_document(title=unicode(instance), content=content,
type=unicode(instance.__class__.__name__.lower()),
url=url)
writer.commit()
示例3: update_index
# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import open_index [as 别名]
def update_index(sender, instance, created, **kwargs):
storage = FileStorage(settings.WHOOSH_INDEX)
ix = storage.open_index()
try:
writer = ix.writer()
except:
return
tags = []
for t in instance.tags.all():
try:
tags.append(unicode(t.name))
except:
pass
tags = u','.join(tags)
try:
if created:
writer.add_document(title=instance.title, content=instance.content,tags=tags,author=instance.author.get_profile().name+u"\n"+instance.author.username,
id=unicode(instance.pk))
writer.commit()
else:
writer.update_document(title=instance.title, content=instance.content,tags=tags,author=instance.author.get_profile().name+u"\n"+instance.author.username,
id=unicode(instance.pk))
writer.commit()
except:
pass
示例4: init_index
# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import open_index [as 别名]
def init_index(index=".index"):
indexZ=index
if not os.path.exists(indexZ):
os.mkdir(indexZ) # os.rmdir(index)
storage = FileStorage(indexZ)
schema = Schema(name=TEXT(stored=True),ext=KEYWORD,title=TEXT(stored=True),content=TEXT,path=ID (stored=True),tags=KEYWORD)
ix = storage.create_index(schema)
ix = storage.open_index()
return ix
示例5: handle_noargs
# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import open_index [as 别名]
def handle_noargs(self, **options):
# from settings import HAYSTACK_CONNECTIONS
# storage = FileStorage(HAYSTACK_CONNECTIONS['default']['PATH'])
storage = FileStorage('/dev/shm/whoosh/')
ix = storage.open_index('SPELL')
with ix.reader() as r:
for id in r.all_doc_ids():
print r.stored_fields(id)
示例6: get_index
# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import open_index [as 别名]
def get_index(index=".index"):
indexZ=index
if not os.path.exists(indexZ):
return "there is no index with this name %s!! use indexer to build the index" % index
sys.exit()
storage = FileStorage(indexZ)
ix = storage.open_index()
print "the index has %d docs" % ix.doc_count_all()
return ix
示例7: _open_indexes
# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import open_index [as 别名]
def _open_indexes(self):
"""open storage and open indexes"""
if not os.path.exists("index"):
os.mkdir("index")
storage = FileStorage("index")
# open or initialise index
if not storage.index_exists(indexname='MAIN'):
self.ix = storage.\
create_index(IndexerSchema, indexname='MAIN')
self.ix = storage.open_index(indexname='MAIN')
示例8: eval_get_ranked_set_baseline
# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import open_index [as 别名]
def eval_get_ranked_set_baseline(self, basefile):
# Step 1: Read the saved keyterms for a subset of articles
# (created by analyze_baseline_queries)
g = Graph()
g.parse(self.generic_path("keyterms", "analyzed", ".n3"), format="n3")
articles = {}
for (s, p, o) in g:
if not str(s) in articles:
articles[str(s)] = []
articles[str(s)].append(str(o))
# Step 2: Open the large whoosh index containing the text of
# all cases. Then, create a query for each article based on
# the keyterms.
connector = query.Or
indexdir = os.path.sep.join([self.config.datadir, 'ecj', 'index'])
storage = FileStorage(indexdir)
idx = storage.open_index()
searcher = idx.searcher(weighting=scoring.BM25F())
res = {}
# for article in sorted(articles.keys()):
for article in self._articles(basefile):
terms = articles[article]
rankedset = []
#parser = qparser.QueryParser("content", idx.schema)
#q = parser.parse(connector.join(terms))
q = query.And([
# query.Term("articles", article),
connector([query.Term("content", x) for x in terms])
])
# print q
# self.log.debug("Article %s: %s", article, " or ".join(terms))
results = searcher.search(q, limit=None)
resultidx = 0
# self.log.info("Keyterms for result: %r" % results.key_terms("content", docs=10, numterms=10))
for result in results:
reslbl = "%s (%s)" % (
result['basefile'], results.score(resultidx))
rankedset.append([result['basefile'], reslbl])
# self.log.debug(u"\t%s: %2.2d" % (result['title'], results.score(resultidx)))
resultidx += 1
self.log.info("Created baseline ranked set for %s: Top result %s (of %s)" %
(article.split("/")[-1], rankedset[0][0], len(rankedset)))
# return just a list of URIs, no scoring information. But the
# full URI isnt available in the whoosh db, so we recreate it.
res[article] = ["http://lagen.nu/ext/celex/%s" % x[
0] for x in rankedset]
return res
示例9: update_index
# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import open_index [as 别名]
def update_index(sender, instance, created, **kwargs):
storage = FileStorage(settings.WHOOSH_INDEX)
ix = storage.open_index(indexname="rarog")
writer = ix.writer()
if created:
writer.add_document(title=unicode(instance), body_html=instance.body_html,
url=unicode(instance.get_absolute_url()))
writer.commit()
else:
writer.update_document(title=unicode(instance), body_html=instance.body_html,
url=unicode(instance.get_absolute_url()))
writer.commit()
示例10: searchIndex
# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import open_index [as 别名]
def searchIndex():
'''
searchindex()
Performs the requested search through the index/schema
INPUTS: idx -- desired index to search
OUTPUTS: results -- results of the search
'''
# Navigate to the LM index directory
c = ''
while True:
print 'The current directory is ' + os.getcwd()
ques = 'Is the LM index (directory) in the current directory? [y/n]\t'
c = raw_input(ques).lower()
if c == 'y' or c == 'yes':
idxDir = os.getcwd()
break
elif c == 'n' or c == 'no':
while True:
idxDir = raw_input('Where is it?\t').lower()
try:
os.chdir(idxDir)
break
except WindowsError:
print 'Sorry, I couldn\'t navigate to that directory'
break
elif c == 'q' or c == 'quit':
print '\tReturning to the Main Menu'
return
else:
print 'I\'m sorry, I don\'t understand what you mean. Try again.'
# Open the index
idxDir = idxDir + '/LM_Storage'
storage = FileStorage(idxDir)
idx = storage.open_index(indexname = 'LM')
# Determine what the user wants to search for
c = ''
while True:
ques = 'What would you like to search? song/artist [s], lyrics [L]\t'
c = raw_input(ques).lower()
if c == 's' or c == 'song/artist' or c == 'song':
searchForSong(idx)
break
elif c == 'l' or c == 'lyrics':
searchForLyrics(idx)
break
elif c == 'q' or c == 'quit':
print '\tReturning to the Main Menu'
return
else:
print 'I\'m sorry, I don\'t understand what you mean. Try again.'
示例11: search_does_exist
# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import open_index [as 别名]
def search_does_exist(query):
#query = unicode(query, 'utf-8')
#query = unidecode(query)
storage = FileStorage("indexdir")
ix = storage.open_index(indexname="wiki")
from whoosh.qparser import QueryParser
with ix.searcher() as searcher:
query = QueryParser("title", ix.schema).parse(query)
whoosh_results = searcher.search(query, limit=1)
return len(whoosh_results) > 0
示例12: search
# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import open_index [as 别名]
def search(self,q):
from whoosh.filedb.filestore import FileStorage
from whoosh.qparser import MultifieldParser
storage = FileStorage(settings.WHOOSH_INDEX)
ix = storage.open_index()
q = q.replace('+', ' AND ').replace(' -', ' NOT ')
parser = MultifieldParser(["content","title","tags","author"], schema=ix.schema)
qry = parser.parse(q)
searcher = ix.searcher()
hits = searcher.search(qry)
return self.objects.filter(id__in=[h.fields()['id'] for h in hits]).filter(published=True)
示例13: run_search
# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import open_index [as 别名]
def run_search(query):
from settings import HAYSTACK_CONNECTIONS
storage = FileStorage(HAYSTACK_CONNECTIONS['default']['PATH'])
# storage = FileStorage('/dev/shm/whoosh/')
ix = storage.open_index('MAIN')
with ix.searcher() as s:
from whoosh.qparser import QueryParser
qp = QueryParser("text", schema=ix.schema)
q = qp.parse(query)
results = s.search(q)
for i, r in enumerate(results):
result = "%d: (%s) %s" % (i, r['id'], r['title']) # ignored
示例14: search
# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import open_index [as 别名]
def search(request):
storage = FileStorage(settings.WHOOSH_INDEX)
ix = storage.open_index(indexname="rarog")
hits = []
query = request.GET.get('q', None)
if query is not None and query != u"":
query = query.replace('+', ' AND ').replace(' -', ' NOT ')
parser = MultifieldParser(['title','body_html'], schema=ix.schema)
try:
qry = parser.parse(query)
except:
qry = None
if qry is not None:
searcher = ix.searcher()
hits = searcher.search(qry)
return query, hits
示例15: add_documents_to_index
# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import open_index [as 别名]
def add_documents_to_index(index_name, documents):
storage = FileStorage("indexdir")
ix = storage.open_index(indexname=index_name)
writer = ix.writer()
for i, document in enumerate(documents):
print "{}%".format(i/len(documents) * 100)
if index_name == "wiki":
writer.add_document(title=u"{}".format(sanitize_text(document.title)))
if index_name == "movie":
writer.add_document(title=u"{}".format(sanitize_text(document.title)))
writer.commit()