* looking for arch@arch.thinkmo.de--2003-archives/moin--main--1.3--patch-616 to compare with
* comparing to arch@arch.thinkmo.de--2003-archives/moin--main--1.3--patch-616
-- MoinMoin/search.py
M  MoinMoin/search.py
M  MoinMoin/theme/__init__.py
M  MoinMoin/Page.py

* file metadata changed

    ./MoinMoin/search.py
        --permissions 644
        => --permissions 744

* modified files

--- orig/MoinMoin/Page.py
+++ mod/MoinMoin/Page.py
@@ -1070,26 +1070,12 @@
 
             # send the page header
             if self.default_formatter:
-
-                def quote_whitespace(x):
-                    if x.find(" ")!=-1:
-                        return "'%s'" % x
-                    else:
-                        return x
-                page_needle = quote_whitespace(self.page_name)
-                if config.allow_subpages and page_needle.count('/'):
-                    #parts = page_needle.split('/')
-                    #for level in range(1, len(parts)):
-                    #    page_needle += (" !" + quote_whitespace(
-                    #        "/".join(parts[:level])) + " " +
-                    #                    quote_whitespace(
-                    #        "/" + "/".join(parts[level:])))   
-                    page_needle = '/' + page_needle.split('/')[-1]
-                    
-                link = '%s/%s?action=fullsearch&amp;value=%s&amp;literal=1&amp;case=1&amp;context=180' % (
+                full_text_query = 'linkto:"%s"' % self.page_name
+                link = '%s/%s?action=fullsearch&amp;value=%s&amp;context=180' % (
                     request.getScriptname(),
                     wikiutil.quoteWikinameURL(self.page_name),
-                    urllib.quote_plus(page_needle.encode(config.charset), ''))
+                    urllib.quote_plus(full_text_query.encode(config.charset)))
+
                 title = self.split_title(request)
                 if self.rev:
                     msg = "<strong>%s</strong><br>%s" % (


--- orig/MoinMoin/search.py
+++ mod/MoinMoin/search.py
@@ -1,7 +1,9 @@
 """
     MoinMoin search engine
     
-    @copyright: Florian Festi TODO: email
+    @copyright: MoinMoin:FlorianFesti
+                MoinMoin:NirSoffer
+                MoinMoin:AlexanderSchremmer
     @license: GNU GPL, see COPYING for details
 """
 
@@ -329,6 +331,77 @@
         return self
 
     
+class LinkSearch(BaseExpression):
+    """ Search the term in the pagelinks """
+
+    def __init__(self, pattern, use_re=False, case=True):
+        """ Init a title search
+
+        @param pattern: pattern to search for, ascii string or unicode
+        @param use_re: treat pattern as re of plain text, bool
+        @param case: do case sensitive search, bool 
+        """
+        # used for search in links
+        self._pattern = pattern
+        # used for search in text
+        self._textpattern = '(' + self._pattern.replace('/', '|') + ')'
+        self.negated = 0
+        self.textsearch = TextSearch(self._textpattern, use_re=1, case=case)
+        self._build_re(unicode(pattern), use_re=use_re, case=case)
+
+    def _build_re(self, pattern, use_re=False, case=False):
+        """ Make a regular expression out of a text pattern """
+        flags = (re.U | re.I, re.U)[case]
+
+        try:
+            if not use_re:
+                raise re.error
+            self.search_re = re.compile(pattern, flags)
+        except re.error:
+            pattern = re.escape(pattern) + '$'
+            self.pattern = pattern
+            self.search_re = re.compile(pattern, flags)
+        
+    def costs(self):
+        return 5000 # cheaper than a TextSearch
+
+    def __unicode__(self):
+        return u'%s!"%s"' % (('', '-')[self.negated], unicode(self._pattern))
+
+    def highlight_re(self):
+        return u"(%s)" % self._textpattern    
+
+    def pageFilter(self):
+        """ Page filter function for single text search """
+        return None
+
+    def search(self, page):
+        # Get matches in page name
+        matches = []
+        page_links = '\n'.join(page.getPageLinks(page.request))
+        if self.search_re.search(page_links) is not None:
+            # Search in page text
+            results = self.textsearch.search(page)
+            if results:
+                matches.extend(results)
+            else: #This happens e.g. for pages that use navigation macros
+                matches.append(TextMatch(0,0))
+
+        # Decide what to do with the results.
+        if ((self.negated and matches) or
+            (not self.negated and not matches)):
+            return None
+        elif matches:
+            return matches
+        else:
+            # XXX why not return None or empty list?
+            return [Match()]
+
+    def indexed_query(self):
+        return self
+
+    
+
 class IndexedQuery:
     """unused and experimental"""
     def __init__(self, queryobject):
@@ -396,7 +469,6 @@
     # before pages that their title does not match.
     _weight = 100.0
 
-
 class FoundPage:
     """ Represents a page in a search result """
 
@@ -577,6 +649,7 @@
         title_search = self.titlesearch
         regex = self.regex
         case = self.case
+        linkto = 0
 
         for m in modifiers:
             if "title".startswith(m):
@@ -585,8 +658,12 @@
                 regex = True
             elif "case".startswith(m):
                 case = True
+            elif "linkto".startswith(m):
+                linkto = True
 
-        if title_search:
+        if linkto:
+            obj = LinkSearch(text, use_re=regex, case=case)
+        elif title_search:
             obj = TitleSearch(text, use_re=regex, case=case)
         else:
             obj = TextSearch(text, use_re=regex, case=case)


--- orig/MoinMoin/theme/__init__.py
+++ mod/MoinMoin/theme/__init__.py
@@ -154,14 +154,23 @@
         @return: title html
         """
         _ = self.request.getText
+
         if d['title_link']:
-            content = ('<a title="%(title)s" href="%(href)s">%(text)s</a>') % {
+            content = curpage = ''
+            segments = d['title_text'].split('/')
+            for s in segments[:-1]:
+                curpage += s
+                content = "%s%s/" % (content, Page(self.request, curpage).link_to(self.request, s))
+                curpage += '/' 
+
+            content += ('<a class="backlink" title="%(title)s" href="%(href)s">%(text)s</a>') % {
                 'title': _('Click to do a full-text search for this title'),
                 'href': d['title_link'],
-                'text': wikiutil.escape(d['title_text']),
+                'text': wikiutil.escape(segments[-1]),
                 }
         else:
             content = wikiutil.escape(d['title_text'])
+
         html = '''
 <h1 id="title">%s</h1>
 ''' % content



