changeset 556:65b2f150beb7

Added searching for file names within the repository in rhodecode
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 07 Oct 2010 17:32:24 +0200
parents 03676d39dd0a
children 29ec9ddbe258
files rhodecode/controllers/search.py rhodecode/lib/indexers/__init__.py rhodecode/public/css/style.css rhodecode/templates/search/search.html rhodecode/templates/search/search_commit.html rhodecode/templates/search/search_content.html rhodecode/templates/search/search_path.html rhodecode/templates/search/search_repository.html
diffstat 6 files changed, 147 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/search.py	Wed Oct 06 18:26:59 2010 +0200
+++ b/rhodecode/controllers/search.py	Thu Oct 07 17:32:24 2010 +0200
@@ -49,6 +49,14 @@
         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 @@
                 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 @@
                     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()
--- a/rhodecode/lib/indexers/__init__.py	Wed Oct 06 18:26:59 2010 +0200
+++ b/rhodecode/lib/indexers/__init__.py	Thu Oct 07 17:32:24 2010 +0200
@@ -38,7 +38,7 @@
 #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 @@
 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 @@
         """
         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 @@
             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,
--- a/rhodecode/public/css/style.css	Wed Oct 06 18:26:59 2010 +0200
+++ b/rhodecode/public/css/style.css	Thu Oct 07 17:32:24 2010 +0200
@@ -1318,6 +1318,12 @@
 	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 @@
 }
 
 /* -----------------------------------------------------------
+    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{
--- a/rhodecode/templates/search/search.html	Wed Oct 06 18:26:59 2010 +0200
+++ b/rhodecode/templates/search/search.html	Thu Oct 07 17:32:24 2010 +0200
@@ -36,52 +36,43 @@
 	%endif
 	<div class="form">
 		<div class="fields">
-		
-			<div class="field ">
-				<div class="label">
-					<label for="q">${_('Search')}:</label>
+			<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 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>
+				<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 &raquo; %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>    
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rhodecode/templates/search/search_content.html	Thu Oct 07 17:32:24 2010 +0200
@@ -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 &raquo; %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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rhodecode/templates/search/search_path.html	Thu Oct 07 17:32:24 2010 +0200
@@ -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 &raquo; %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