本文整理汇总了Python中engine.Engine.remove_document方法的典型用法代码示例。如果您正苦于以下问题:Python Engine.remove_document方法的具体用法?Python Engine.remove_document怎么用?Python Engine.remove_document使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类engine.Engine
的用法示例。
在下文中一共展示了Engine.remove_document方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: IndexerThread
# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import remove_document [as 别名]
class IndexerThread(threading.Thread):
def __init__(self, queue, index_directory, log_rate, log_file):
self.search_engine = Engine(index_directory)
self.buffered_writer = self.search_engine.new_buffered_writer(120, 100 , 512)
self.queue = queue
self.log_count = 0
self.log_rate = log_rate
self.log_file = log_file
threading.Thread.__init__(self) # needed for thread to be instantiated
def run(self):
while True:
while not self.queue.empty():
path, add_or_delete = self.queue.get_nowait()
time_taken, successful = self.add_or_remove(path, add_or_delete)
if successful:
if self.log_count % self.log_rate == 0:
if add_or_delete:
log(self.log_file, ("time taken to index path: ", [time_taken, path, str(datetime.now())]))
else:
log(self.log_file, ("time taken to un-index path: ", [time_taken, path, str(datetime.now())]))
else:
log(self.log_file,("index/ un-index of path was unsuccessful: ", [path, str(datetime.now())]))
self.log_count += 1
"""
This method indexes/ removes an index of 'path', and returns the time taken to do so.
params:
- path: the path to index/ remove from index
- add_or_delete: True for add/ False for delete
return:
- time_taken (0.0 if unsuccessful; i.e. directory, not file)
- boolean of successful or not (whether file or directory)
"""
def add_or_remove(self, path, add_or_delete):
if os.path.isdir(path):
return [0.0, False]
t0 = time.time()
if add_or_delete:
self.search_engine.add_document(path, self.buffered_writer)
else:
self.search_engine.remove_document(path, self.buffered_writer)
t1 = time.time()
time_taken = t1 - t0
return [time_taken, True]