changeset 2319:4c239e0dcbb7 beta

fixes issue #454 Search results under Windows include preceeding backslash
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 20 May 2012 16:38:00 +0200
parents 058e2743e7b7
children 48d93ea1e245
files rhodecode/controllers/search.py rhodecode/lib/indexers/__init__.py
diffstat 2 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/search.py	Sun May 20 14:41:03 2012 +0200
+++ b/rhodecode/controllers/search.py	Sun May 20 16:38:00 2012 +0200
@@ -30,7 +30,7 @@
 
 from rhodecode.lib.auth import LoginRequired
 from rhodecode.lib.base import BaseController, render
-from rhodecode.lib.indexers import SCHEMA, IDX_NAME, ResultWrapper
+from rhodecode.lib.indexers import SCHEMA, IDX_NAME, WhooshResultWrapper
 
 from webhelpers.paginate import Page
 from webhelpers.util import update_params
@@ -38,6 +38,7 @@
 from whoosh.index import open_dir, EmptyIndexError
 from whoosh.qparser import QueryParser, QueryParserError
 from whoosh.query import Phrase, Wildcard, Term, Prefix
+from rhodecode.model.repo import RepoModel
 
 log = logging.getLogger(__name__)
 
@@ -99,10 +100,10 @@
                     def url_generator(**kw):
                         return update_params("?q=%s&type=%s" \
                                            % (c.cur_query, c.cur_search), **kw)
-
+                    repo_location = RepoModel().repos_path
                     c.formated_results = Page(
-                        ResultWrapper(search_type, searcher, matcher,
-                                      highlight_items),
+                        WhooshResultWrapper(search_type, searcher, matcher,
+                                            highlight_items, repo_location),
                         page=p,
                         item_count=res_ln,
                         items_per_page=10,
--- a/rhodecode/lib/indexers/__init__.py	Sun May 20 14:41:03 2012 +0200
+++ b/rhodecode/lib/indexers/__init__.py	Sun May 20 16:38:00 2012 +0200
@@ -129,13 +129,15 @@
                           default=False)
 
 
-class ResultWrapper(object):
-    def __init__(self, search_type, searcher, matcher, highlight_items):
+class WhooshResultWrapper(object):
+    def __init__(self, search_type, searcher, matcher, highlight_items,
+                 repo_location):
         self.search_type = search_type
         self.searcher = searcher
         self.matcher = matcher
         self.highlight_items = highlight_items
         self.fragment_size = 200
+        self.repo_location = repo_location
 
     @LazyProperty
     def doc_ids(self):
@@ -178,8 +180,9 @@
 
     def get_full_content(self, docid):
         res = self.searcher.stored_fields(docid[0])
-        f_path = res['path'][res['path'].find(res['repository']) \
-                             + len(res['repository']):].lstrip('/')
+        full_repo_path = jn(self.repo_location, res['repository'])
+        f_path = res['path'].split(full_repo_path)[-1]
+        f_path = f_path.lstrip(os.sep)
 
         content_short = self.get_short_content(res, docid[1])
         res.update({'content_short': content_short,