diff --git a/rhodecode/controllers/search.py b/rhodecode/controllers/search.py --- a/rhodecode/controllers/search.py +++ b/rhodecode/controllers/search.py @@ -49,6 +49,14 @@ class SearchController(BaseController): c.formated_results = [] c.runtime = '' c.cur_query = request.GET.get('q', None) + c.cur_type = request.GET.get('type', 'source') + c.cur_search = search_type = {'content':'content', + 'commit':'content', + 'path':'path', + 'repository':'repository'}\ + .get(c.cur_type, 'content') + + if c.cur_query: cur_query = c.cur_query.lower() @@ -59,7 +67,7 @@ class SearchController(BaseController): idx = open_dir(IDX_LOCATION, indexname=IDX_NAME) searcher = idx.searcher() - qp = QueryParser("content", schema=SCHEMA) + qp = QueryParser(search_type, schema=SCHEMA) if c.repo_name: cur_query = u'repository:%s %s' % (c.repo_name, cur_query) try: @@ -79,16 +87,19 @@ class SearchController(BaseController): results = searcher.search(query) res_ln = len(results) c.runtime = '%s results (%.3f seconds)' \ - % (res_ln, results.runtime) + % (res_ln, results.runtime) def url_generator(**kw): - return update_params("?q=%s" % c.cur_query, **kw) + return update_params("?q=%s&type=%s" \ + % (c.cur_query, c.cur_search), **kw) c.formated_results = Page( - ResultWrapper(searcher, matcher, highlight_items), + ResultWrapper(search_type, searcher, matcher, + highlight_items), page=p, item_count=res_ln, items_per_page=10, url=url_generator) - + + except QueryParserError: c.runtime = _('Invalid search query. Try quoting it.') searcher.close() diff --git a/rhodecode/lib/indexers/__init__.py b/rhodecode/lib/indexers/__init__.py --- a/rhodecode/lib/indexers/__init__.py +++ b/rhodecode/lib/indexers/__init__.py @@ -38,7 +38,7 @@ ANALYZER = RegexTokenizer(expression=r"\ #INDEX SCHEMA DEFINITION SCHEMA = Schema(owner=TEXT(), repository=TEXT(stored=True), - path=ID(stored=True, unique=True), + path=TEXT(stored=True), content=FieldType(format=Characters(ANALYZER), scorable=True, stored=True), modtime=STORED(), extension=TEXT(stored=True)) @@ -49,7 +49,8 @@ FORMATTER = HtmlFormatter('span', betwee FRAGMENTER = SimpleFragmenter(200) class ResultWrapper(object): - def __init__(self, searcher, matcher, highlight_items): + def __init__(self, search_type, searcher, matcher, highlight_items): + self.search_type = search_type self.searcher = searcher self.matcher = matcher self.highlight_items = highlight_items @@ -113,7 +114,7 @@ class ResultWrapper(object): """ Smart function that implements chunking the content but not overlap chunks so it doesn't highlight the same - close occurences twice. + close occurrences twice. @param matcher: @param size: """ @@ -130,6 +131,8 @@ class ResultWrapper(object): yield (start_offseted, end_offseted,) def highlight(self, content, top=5): + if self.search_type != 'content': + return '' hl = highlight(escape(content), self.highlight_items, analyzer=ANALYZER, diff --git a/rhodecode/public/css/style.css b/rhodecode/public/css/style.css --- a/rhodecode/public/css/style.css +++ b/rhodecode/public/css/style.css @@ -1318,6 +1318,12 @@ div.options a:hover padding: 0 0 10px 0; } +#content div.box div.form div.fields div.field-noborder +{ + border-bottom: 0px !important; +} + + #content div.box div.form div.fields div.field span.error-message { margin: 8px 0 0 0; @@ -3311,6 +3317,36 @@ table.code-browser .browser-dir { } /* ----------------------------------------------------------- + SEARCH +----------------------------------------------------------- */ + +.box .search { + clear:both; + margin:0; + overflow:hidden; + padding:0 20px 10px; +} +.box .search div.search_path{ + background:none repeat scroll 0 0 #EEEEEE; + border:1px solid #CCCCCC; + + color:blue; + padding:10px 0; + margin-bottom:10px; +} +.box .search div.search_path div.link{ + font-weight:bold; + margin-left:25px; +} +.box .search div.search_path div.link a{ + color:#0066CC; + cursor:pointer; + text-decoration:none; +} + + + +/* ----------------------------------------------------------- ADMIN - SETTINGS ----------------------------------------------------------- */ #path_unlock{ diff --git a/rhodecode/templates/search/search.html b/rhodecode/templates/search/search.html --- a/rhodecode/templates/search/search.html +++ b/rhodecode/templates/search/search.html @@ -36,52 +36,43 @@ %endif
${h.literal(sr['content_short_hl'])}-
${h.literal(sr['content_short_hl'])}+