Mercurial > kallithea
comparison rhodecode/controllers/search.py @ 1212:50e41777675d beta
pep8ify
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 05 Apr 2011 13:12:38 +0200 |
parents | a671db5bdd58 |
children | 9773b46e239f |
comparison
equal
deleted
inserted
replaced
1211:a7e7c0fab9db | 1212:50e41777675d |
---|---|
39 from whoosh.qparser import QueryParser, QueryParserError | 39 from whoosh.qparser import QueryParser, QueryParserError |
40 from whoosh.query import Phrase | 40 from whoosh.query import Phrase |
41 | 41 |
42 log = logging.getLogger(__name__) | 42 log = logging.getLogger(__name__) |
43 | 43 |
44 | |
44 class SearchController(BaseController): | 45 class SearchController(BaseController): |
45 | 46 |
46 @LoginRequired() | 47 @LoginRequired() |
47 def __before__(self): | 48 def __before__(self): |
48 super(SearchController, self).__before__() | 49 super(SearchController, self).__before__() |
51 c.repo_name = search_repo | 52 c.repo_name = search_repo |
52 c.formated_results = [] | 53 c.formated_results = [] |
53 c.runtime = '' | 54 c.runtime = '' |
54 c.cur_query = request.GET.get('q', None) | 55 c.cur_query = request.GET.get('q', None) |
55 c.cur_type = request.GET.get('type', 'source') | 56 c.cur_type = request.GET.get('type', 'source') |
56 c.cur_search = search_type = {'content':'content', | 57 c.cur_search = search_type = {'content': 'content', |
57 'commit':'content', | 58 'commit': 'content', |
58 'path':'path', | 59 'path': 'path', |
59 'repository':'repository'}\ | 60 'repository': 'repository'}\ |
60 .get(c.cur_type, 'content') | 61 .get(c.cur_type, 'content') |
61 | |
62 | 62 |
63 if c.cur_query: | 63 if c.cur_query: |
64 cur_query = c.cur_query.lower() | 64 cur_query = c.cur_query.lower() |
65 | 65 |
66 if c.cur_query: | 66 if c.cur_query: |
67 p = int(request.params.get('page', 1)) | 67 p = int(request.params.get('page', 1)) |
68 highlight_items = set() | 68 highlight_items = set() |
69 try: | 69 try: |
70 idx = open_dir(config['app_conf']['index_dir'] | 70 idx = open_dir(config['app_conf']['index_dir'], |
71 , indexname=IDX_NAME) | 71 indexname=IDX_NAME) |
72 searcher = idx.searcher() | 72 searcher = idx.searcher() |
73 | 73 |
74 qp = QueryParser(search_type, schema=SCHEMA) | 74 qp = QueryParser(search_type, schema=SCHEMA) |
75 if c.repo_name: | 75 if c.repo_name: |
76 cur_query = u'repository:%s %s' % (c.repo_name, cur_query) | 76 cur_query = u'repository:%s %s' % (c.repo_name, cur_query) |
101 ResultWrapper(search_type, searcher, matcher, | 101 ResultWrapper(search_type, searcher, matcher, |
102 highlight_items), | 102 highlight_items), |
103 page=p, item_count=res_ln, | 103 page=p, item_count=res_ln, |
104 items_per_page=10, url=url_generator) | 104 items_per_page=10, url=url_generator) |
105 | 105 |
106 | |
107 except QueryParserError: | 106 except QueryParserError: |
108 c.runtime = _('Invalid search query. Try quoting it.') | 107 c.runtime = _('Invalid search query. Try quoting it.') |
109 searcher.close() | 108 searcher.close() |
110 except (EmptyIndexError, IOError): | 109 except (EmptyIndexError, IOError): |
111 log.error(traceback.format_exc()) | 110 log.error(traceback.format_exc()) |