diff options
author | Marcin Kuzminski <marcin@python-works.com> | 2010-10-07 17:32:24 +0200 |
---|---|---|
committer | Marcin Kuzminski <marcin@python-works.com> | 2010-10-07 17:32:24 +0200 |
commit | 00e40870eb30de94871c5cc45efd6177aa01e903 (patch) | |
tree | 4963d90856f0705a4ebc35e604b32526cb089e54 /rhodecode | |
parent | 60cf4447c4c2b66280b523d81b1ac708172fcff8 (diff) |
Added searching for file names within the repository in rhodecode
Diffstat (limited to 'rhodecode')
-rw-r--r-- | rhodecode/controllers/search.py | 21 | ||||
-rw-r--r-- | rhodecode/lib/indexers/__init__.py | 9 | ||||
-rw-r--r-- | rhodecode/public/css/style.css | 36 | ||||
-rw-r--r-- | rhodecode/templates/search/search.html | 71 | ||||
-rw-r--r-- | rhodecode/templates/search/search_commit.html | 0 | ||||
-rw-r--r-- | rhodecode/templates/search/search_content.html | 31 | ||||
-rw-r--r-- | rhodecode/templates/search/search_path.html | 27 | ||||
-rw-r--r-- | rhodecode/templates/search/search_repository.html | 0 |
8 files changed, 147 insertions, 48 deletions
diff --git a/rhodecode/controllers/search.py b/rhodecode/controllers/search.py index 6537f2bc..e316cd72 100644 --- 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 index 38022644..58dd6b62 100644 --- a/rhodecode/lib/indexers/__init__.py +++ b/rhodecode/lib/indexers/__init__.py @@ -38,7 +38,7 @@ ANALYZER = RegexTokenizer(expression=r"\w+") | LowercaseFilter() #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', between='\n<span class="break">...</span>\n') 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 index 4b475967..b639f7de 100644 --- 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 index bbdb2975..5ec07c98 100644 --- a/rhodecode/templates/search/search.html +++ b/rhodecode/templates/search/search.html @@ -36,52 +36,43 @@ %endif <div class="form"> <div class="fields"> - - <div class="field "> - <div class="label"> - <label for="q">${_('Search')}:</label> - </div> - <div class="input"> - ${h.text('q',c.cur_query,class_="small")} - <div class="button highlight"> - <input type="submit" value="${_('Search')}" class="ui-button ui-widget ui-state-default ui-corner-all"/> - </div> - <div style="font-weight: bold;clear:both;padding: 5px">${c.runtime}</div> + <div class="field field-first field-noborder"> + <div class="label"> + <label for="q">${_('Search term')}</label> + </div> + <div class="input">${h.text('q',c.cur_query,class_="small")}</div> + <div class="button highlight"> + <input type="submit" value="${_('Search')}" class="ui-button ui-widget ui-state-default ui-corner-all"/> </div> + <div style="font-weight: bold;clear:Both;margin-left:200px">${c.runtime}</div> </div> + + <div class="field"> + <div class="label"> + <label for="type">${_('Search in')}</label> + </div> + <div class="select"> + ${h.select('type',c.cur_type,[('content',_('Source codes')), + ##('commit',_('Commit messages')), + ('path',_('File names')), + ##('repository',_('Repository names')), + ])} + </div> + </div> + </div> </div> ${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'): - <div class="table"> - <div id="body${cnt}" class="codeblock"> - <div class="code-header"> - <div class="revision">${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']))}</div> - </div> - <div class="code-body"> - <pre>${h.literal(sr['content_short_hl'])}</pre> - </div> - </div> - </div> - %else: - %if cnt == 0: - <div class="table"> - <div id="body${cnt}" class="codeblock"> - <div class="error">${_('Permission denied')}</div> - </div> - </div> - %endif - - %endif - %endfor - %if c.cur_query: - <div class="pagination-wh pagination-left"> - ${c.formated_results.pager('$link_previous ~2~ $link_next')} - </div> - %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 </div> </%def> diff --git a/rhodecode/templates/search/search_commit.html b/rhodecode/templates/search/search_commit.html new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/rhodecode/templates/search/search_commit.html diff --git a/rhodecode/templates/search/search_content.html b/rhodecode/templates/search/search_content.html new file mode 100644 index 00000000..09628dd6 --- /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'): + <div class="table"> + <div id="body${cnt}" class="codeblock"> + <div class="code-header"> + <div class="revision">${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']))}</div> + </div> + <div class="code-body"> + <pre>${h.literal(sr['content_short_hl'])}</pre> + </div> + </div> + </div> + %else: + %if cnt == 0: + <div class="table"> + <div id="body${cnt}" class="codeblock"> + <div class="error">${_('Permission denied')}</div> + </div> + </div> + %endif + + %endif +%endfor +%if c.cur_query and c.formated_results: +<div class="pagination-wh pagination-left"> + ${c.formated_results.pager('$link_previous ~2~ $link_next')} +</div> +%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 index 00000000..9e5b736f --- /dev/null +++ b/rhodecode/templates/search/search_path.html @@ -0,0 +1,27 @@ +##path search +<div class="search"> + %for cnt,sr in enumerate(c.formated_results): + %if h.HasRepoPermissionAny('repository.write','repository.read','repository.admin')(sr['repository'],'search results check'): + <div class="search_path"> + <div class="link"> + ${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']))} + </div> + </div> + %else: + %if cnt == 0: + <div class="error"> + <div class="link"> + ${_('Permission denied')} + </div> + </div> + %endif + + %endif + %endfor + %if c.cur_query and c.formated_results: + <div class="pagination-wh pagination-left"> + ${c.formated_results.pager('$link_previous ~2~ $link_next')} + </div> + %endif +</div>
\ 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 index 00000000..e69de29b --- /dev/null +++ b/rhodecode/templates/search/search_repository.html |