Changeset - 65b2f150beb7
[Not reviewed]
default
0 4 4
Marcin Kuzminski - 15 years ago 2010-10-07 17:32:24
marcin@python-works.com
Added searching for file names within the repository in rhodecode
8 files changed with 147 insertions and 48 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/search.py
Show inline comments
 
@@ -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()
rhodecode/lib/indexers/__init__.py
Show inline comments
 
@@ -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,
rhodecode/public/css/style.css
Show inline comments
 
@@ -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{
rhodecode/templates/search/search.html
Show inline comments
 
@@ -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>    
rhodecode/templates/search/search_commit.html
Show inline comments
 
new file 100644
rhodecode/templates/search/search_content.html
Show inline comments
 
new file 100644
 
##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
rhodecode/templates/search/search_path.html
Show inline comments
 
new file 100644
 
##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
rhodecode/templates/search/search_repository.html
Show inline comments
 
new file 100644
0 comments (0 inline, 0 general)