changeset 2262:3542a17d9b05

Fix for issue #18, Global index is handled seperately.
author Ashutosh Singla <ashu1461@gmail.com>
date Wed, 11 Sep 2013 13:17:49 +0530
parents a90551dc4b75
children 6dd5af01d54d
files MoinMoin/apps/frontend/views.py MoinMoin/items/__init__.py
diffstat 2 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Wed Sep 11 11:03:36 2013 +0530
+++ b/MoinMoin/apps/frontend/views.py	Wed Sep 11 13:17:49 2013 +0530
@@ -821,7 +821,7 @@
 
     initials = item.name_initial(item.get_subitem_revs(), uppercase=True)
 
-    dirs, files = item.get_index(startswith, selected_groups)
+    dirs, files = item.get_index(startswith, selected_groups, isglobalindex=not item_name)
     # index = sorted(index, key=lambda e: e.relname.lower())
 
     item_names = item_name.split(u'/')
--- a/MoinMoin/items/__init__.py	Wed Sep 11 11:03:36 2013 +0530
+++ b/MoinMoin/items/__init__.py	Wed Sep 11 13:17:49 2013 +0530
@@ -611,7 +611,7 @@
         revs = flaskg.storage.search(query, sortedby=NAME_EXACT, limit=None)
         return revs
 
-    def make_flat_index(self, subitems):
+    def make_flat_index(self, subitems, isglobalindex=False):
         """
         Create two IndexEntry lists - ``dirs`` and ``files`` - from a list of
         subitems.
@@ -626,8 +626,10 @@
 
         When both a subitem itself and some of its subitems are in the subitems
         list, it appears in both ``files`` and ``dirs``.
+
+        :param isglobalindex: True if the query is for global indexes.
         """
-        prefixes = self.subitem_prefixes
+        prefixes = [u''] if isglobalindex else self.subitem_prefixes
         # IndexEntry instances of "file" subitems
         files = []
         # IndexEntry instances of "directory" subitems
@@ -656,8 +658,8 @@
                         files.append(IndexEntry(relname, fullname, rev.meta))
         return dirs, files
 
-    def build_index_query(self, startswith=None, selected_groups=None):
-        prefix = self.subitem_prefixes[0]
+    def build_index_query(self, startswith=None, selected_groups=None, isglobalindex=False):
+        prefix = u'' if isglobalindex else self.subitem_prefixes[0]
         if startswith:
             query = Prefix(NAME_EXACT, prefix + startswith) | Prefix(NAME_EXACT, prefix + startswith.swapcase())
         else:
@@ -675,10 +677,10 @@
 
         return query
 
-    def get_index(self, startswith=None, selected_groups=None):
-        query = Term(WIKINAME, app.cfg.interwikiname) & self.build_index_query(startswith, selected_groups)
+    def get_index(self, startswith=None, selected_groups=None, isglobalindex=False):
+        query = Term(WIKINAME, app.cfg.interwikiname) & self.build_index_query(startswith, selected_groups, isglobalindex)
         revs = flaskg.storage.search(query, sortedby=NAME_EXACT, limit=None)
-        return self.make_flat_index(revs)
+        return self.make_flat_index(revs, isglobalindex)
 
     def get_mixed_index(self):
         dirs, files = self.make_flat_index(self.get_subitem_revs())