Mercurial > kallithea
comparison rhodecode/lib/indexers/daemon.py @ 1995:b6c902d88472 beta
bumbed whoosh to 2.3.X series
- fixed some html issues on search results
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 16 Feb 2012 05:41:58 +0200 |
parents | 89efedac4e6c |
children | 324ac367a4da |
comparison
equal
deleted
inserted
replaced
1993:4d3179d2adfe | 1995:b6c902d88472 |
---|---|
47 NodeDoesNotExistError | 47 NodeDoesNotExistError |
48 | 48 |
49 from whoosh.index import create_in, open_dir | 49 from whoosh.index import create_in, open_dir |
50 | 50 |
51 | 51 |
52 | |
53 log = logging.getLogger('whooshIndexer') | 52 log = logging.getLogger('whooshIndexer') |
54 # create logger | 53 # create logger |
55 log.setLevel(logging.DEBUG) | 54 log.setLevel(logging.DEBUG) |
56 log.propagate = False | 55 log.propagate = False |
57 # create console handler and set level to debug | 56 # create console handler and set level to debug |
66 ch.setFormatter(formatter) | 65 ch.setFormatter(formatter) |
67 | 66 |
68 # add ch to logger | 67 # add ch to logger |
69 log.addHandler(ch) | 68 log.addHandler(ch) |
70 | 69 |
70 | |
71 class WhooshIndexingDaemon(object): | 71 class WhooshIndexingDaemon(object): |
72 """ | 72 """ |
73 Daemon for atomic jobs | 73 Daemon for atomic jobs |
74 """ | 74 """ |
75 | 75 |
76 def __init__(self, indexname='HG_INDEX', index_location=None, | 76 def __init__(self, indexname=IDX_NAME, index_location=None, |
77 repo_location=None, sa=None, repo_list=None): | 77 repo_location=None, sa=None, repo_list=None): |
78 self.indexname = indexname | 78 self.indexname = indexname |
79 | 79 |
80 self.index_location = index_location | 80 self.index_location = index_location |
81 if not index_location: | 81 if not index_location: |
92 for repo_name, repo in self.repo_paths.items(): | 92 for repo_name, repo in self.repo_paths.items(): |
93 if repo_name in repo_list: | 93 if repo_name in repo_list: |
94 filtered_repo_paths[repo_name] = repo | 94 filtered_repo_paths[repo_name] = repo |
95 | 95 |
96 self.repo_paths = filtered_repo_paths | 96 self.repo_paths = filtered_repo_paths |
97 | |
98 | 97 |
99 self.initial = False | 98 self.initial = False |
100 if not os.path.isdir(self.index_location): | 99 if not os.path.isdir(self.index_location): |
101 os.makedirs(self.index_location) | 100 os.makedirs(self.index_location) |
102 log.info('Cannot run incremental index since it does not' | 101 log.info('Cannot run incremental index since it does not' |
153 path=safe_unicode(path), | 152 path=safe_unicode(path), |
154 content=u_content, | 153 content=u_content, |
155 modtime=self.get_node_mtime(node), | 154 modtime=self.get_node_mtime(node), |
156 extension=node.extension) | 155 extension=node.extension) |
157 | 156 |
158 | |
159 def build_index(self): | 157 def build_index(self): |
160 if os.path.exists(self.index_location): | 158 if os.path.exists(self.index_location): |
161 log.debug('removing previous index') | 159 log.debug('removing previous index') |
162 rmtree(self.index_location) | 160 rmtree(self.index_location) |
163 | 161 |
174 self.add_doc(writer, idx_path, repo, repo_name) | 172 self.add_doc(writer, idx_path, repo, repo_name) |
175 | 173 |
176 log.debug('>> COMMITING CHANGES <<') | 174 log.debug('>> COMMITING CHANGES <<') |
177 writer.commit(merge=True) | 175 writer.commit(merge=True) |
178 log.debug('>>> FINISHED BUILDING INDEX <<<') | 176 log.debug('>>> FINISHED BUILDING INDEX <<<') |
179 | |
180 | 177 |
181 def update_index(self): | 178 def update_index(self): |
182 log.debug('STARTING INCREMENTAL INDEXING UPDATE') | 179 log.debug('STARTING INCREMENTAL INDEXING UPDATE') |
183 | 180 |
184 idx = open_dir(self.index_location, indexname=self.indexname) | 181 idx = open_dir(self.index_location, indexname=self.indexname) |