当前位置: 首页>>代码示例>>Python>>正文


Python Engine.writer方法代码示例

本文整理汇总了Python中engine.Engine.writer方法的典型用法代码示例。如果您正苦于以下问题:Python Engine.writer方法的具体用法?Python Engine.writer怎么用?Python Engine.writer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在engine.Engine的用法示例。


在下文中一共展示了Engine.writer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: IndexerThread

# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import writer [as 别名]
class IndexerThread(threading.Thread):

    def __init__(self, queue, index_directory, log_rate):

        self.search_engine = Engine(index_directory)
        self.buffered_writer = self.search_engine.writer(120, 5000 , 512)
        self.queue = queue
        self.log_count = 0
        self.log_rate = log_rate
        threading.Thread.__init__(self) # needed for thread to be instantiated

    """
    # The old run:
    def run(self):

        while True:

            job_list = []
            while not self.queue.empty():
                job = self.queue.get()
                job_list.append(job)
            for j in job_list:
                path, add_or_delete = j
                time_taken, successful = self.add_or_remove(path, add_or_delete)

                if self.log_count % 1000 == 0:
                    if successful: 
                        if add_or_delete:
                            print "time taken to index path: ", [time_taken, path, str(datetime.now())]
                        else:
                            print "time taken to un-index path: ", [time_taken, path, str(datetime.now())]

                    else:
                        print "index/ un-index of path was unsuccessful: ", [path, str(datetime.now())]

                self.log_count += 1

            time.sleep(self.sleep_time)
    """
    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:
                            print "time taken to index path: ", [time_taken, path, str(datetime.now())]
                        else:
                            print "time taken to un-index path: ", [time_taken, path, str(datetime.now())]
                else:
                    print "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]
开发者ID:theshop,项目名称:file-mi,代码行数:87,代码来源:fileMonitorQueue.py

示例2: Engine

# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import writer [as 别名]
- Using monitored_directory and index_directory2
"""


parser = argparse.ArgumentParser(description="the index directory")
parser.add_argument("index_directory", help="the index_directory to refresh")
parser.add_argument("monitored_directory", help="the monitored_directory to load into queue")



args = parser.parse_args()
index_directory = args.index_directory
monitored_directory = args.monitored_directory
search_engine = Engine(index_directory)
buffered_writer = search_engine.writer(120, 1000, 512)

queue = Queue.Queue()
path = monitored_directory

def recursive_put(path, queue):

	if os.path.isfile(path):
		queue.put(path)

	elif os.path.isdir(path):
		ls = os.listdir(path)
		for l in ls:
			recursive_put(os.path.join(path, l), queue)
	else: 
		pass
开发者ID:theshop,项目名称:file-mi,代码行数:32,代码来源:indexing_test.py


注:本文中的engine.Engine.writer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。