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.text('q',c.cur_query,class_="small")}
+
+
-
- ${h.text('q',c.cur_query,class_="small")} -
- -
-
${c.runtime}
-
+
${c.runtime}
+ +
+
+ +
+
+ ${h.select('type',c.cur_type,[('content',_('Source codes')), + ##('commit',_('Commit messages')), + ('path',_('File names')), + ##('repository',_('Repository names')), + ])} +
+
+
${h.end_form()} - %for cnt,sr in enumerate(c.formated_results): - %if h.HasRepoPermissionAny('repository.write','repository.read','repository.admin')(sr['repository'],'search results check'): -
-
-
-
${h.link_to(h.literal('%s » %s' % (sr['repository'],sr['f_path'])), - h.url('files_home',repo_name=sr['repository'],revision='tip',f_path=sr['f_path']))}
-
-
-
${h.literal(sr['content_short_hl'])}
-
-
-
- %else: - %if cnt == 0: -
-
-
${_('Permission denied')}
-
-
- %endif - - %endif - %endfor - %if c.cur_query: -
- ${c.formated_results.pager('$link_previous ~2~ $link_next')} -
- %endif + %if c.cur_search == 'content': + <%include file='search_content.html'/> + %elif c.cur_search == 'path': + <%include file='search_path.html'/> + %elif c.cur_search == 'commit': + <%include file='search_commit.html'/> + %elif c.cur_search == 'repository': + <%include file='search_repository.html'/> + %endif
diff --git a/rhodecode/templates/search/search_commit.html b/rhodecode/templates/search/search_commit.html new file mode 100644 diff --git a/rhodecode/templates/search/search_content.html b/rhodecode/templates/search/search_content.html new file mode 100644 --- /dev/null +++ b/rhodecode/templates/search/search_content.html @@ -0,0 +1,31 @@ +##content highligthing + +%for cnt,sr in enumerate(c.formated_results): + %if h.HasRepoPermissionAny('repository.write','repository.read','repository.admin')(sr['repository'],'search results check'): +
+
+
+
${h.link_to(h.literal('%s » %s' % (sr['repository'],sr['f_path'])), + h.url('files_home',repo_name=sr['repository'],revision='tip',f_path=sr['f_path']))}
+
+
+
${h.literal(sr['content_short_hl'])}
+
+
+
+ %else: + %if cnt == 0: +
+
+
${_('Permission denied')}
+
+
+ %endif + + %endif +%endfor +%if c.cur_query and c.formated_results: +
+ ${c.formated_results.pager('$link_previous ~2~ $link_next')} +
+%endif \ No newline at end of file diff --git a/rhodecode/templates/search/search_path.html b/rhodecode/templates/search/search_path.html new file mode 100644 --- /dev/null +++ b/rhodecode/templates/search/search_path.html @@ -0,0 +1,27 @@ +##path search + \ No newline at end of file diff --git a/rhodecode/templates/search/search_repository.html b/rhodecode/templates/search/search_repository.html new file mode 100644