Commits

Marcin Kuzminski  committed 4c239e0

fixes issue #454 Search results under Windows include preceeding backslash

  • Participants
  • Parent commits 058e274

Comments (0)

Files changed (2)

File rhodecode/controllers/search.py

 
 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
 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__)
 
                     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,

File rhodecode/lib/indexers/__init__.py

                           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):
 
     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,