Attachment 'a_farmfullsearch2.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - farmfullsearch action
   4 
   5     @copyright: 2006 by Oliver Siemoneit
   6     @license: GNU GPL, see COPYING for details.
   7 
   8     FarmFullSearch is heavily based on FullSearch
   9     @copyright: 2000-2004 by Jürgen Hermann <jh@web.de>
  10     @license: GNU GPL, see COPYING for details.
  11 """
  12 
  13 import time
  14 import xmlrpclib
  15 from MoinMoin.Page import Page
  16 from MoinMoin import wikiutil
  17 from MoinMoin.util import MoinMoinNoFooter
  18 
  19 
  20 def execute(pagename, request, fieldname='value', titlesearch=0):
  21     _ = request.getText
  22         
  23     # Get other form parameters
  24     needle = request.form.get(fieldname, [''])[0]
  25     
  26     # check for sensible search term
  27     striped = needle.strip()
  28     if len(striped) == 0:
  29         err = _('Please use a more selective search term instead '
  30                 'of {{{"%s"}}}') % needle
  31         # send http headers
  32         request.http_headers()
  33         Page(request, pagename).send_page(request, msg=err) 
  34         return
  35 
  36     # search the pages
  37     results = searchfarm(request, needle)
  38         
  39     # send http headers
  40     request.http_headers()
  41 
  42     # This action generate data using the user language
  43     request.setContentLanguage(request.lang)
  44     title = _('Fulll Text Search: "%s"')
  45     wikiutil.send_title(request, title % needle, form=request.form,
  46                         pagename=pagename)
  47     
  48     # Start content (important for RTL support)
  49     request.write(request.formatter.startContent("content"))
  50 
  51     request.write(results)
  52 
  53     # End content and send footer
  54     request.write(request.formatter.endContent())
  55     wikiutil.send_footer(request, pagename)
  56 
  57 
  58 def searchfarm(macro, args):
  59     from farmconfig import wikis
  60     _ = macro.getText
  61     output = ""
  62     searchterm = args
  63 
  64     #Taken from wikilist.py by TheAnarcat!
  65     for wiki in wikis:
  66         name = wiki[0]
  67         url = wiki[1]
  68         from re import sub
  69         # XXX, hack: transform the regexp into a canonical url
  70         # we need canonical urls in the config for this to be clean
  71         # look for (foo|bar) and replace with foo
  72         url = sub('\(([^\|]*)(\|[^\)]*\))+', '\\1', url)
  73         # remove common regexp patterns and slap a protocol to make this a real url
  74         url = 'http://' + sub('[\^\$]|(\.\*)', '', url)
  75         # for farmsearch we additionally need a slash at the end
  76         url = url + '/'
  77 
  78         # Set the url for the remote farm wiki here. Note: Slash at the end is needed
  79         #url = "http://wikifarm.koumbit.net/"
  80         srcwiki = xmlrpclib.ServerProxy(url + '?action=xmlrpc2')
  81     
  82         start = time.time()
  83         searchresults = srcwiki.searchPages(searchterm)
  84         # This is a bad and time consuming solution just to get the number of pages searched
  85         allpages = srcwiki.getAllPages()
  86     
  87         output += macro.formatter.paragraph(1)
  88         #output += macro.formatter.text(_("%s (%d results)") %(url, len(searchresults)))
  89         output += macro.formatter.strong(1)
  90         output += macro.formatter.text(name)
  91         output += macro.formatter.strong(0)
  92         output += macro.formatter.linebreak(0)
  93         output += macro.formatter.text(_("%(hits)d results out of about %(pages)d pages.") %
  94                        {'hits': len(searchresults), 'pages': len(allpages)})
  95         elapsed = time.time() - start
  96         output += macro.formatter.text(u' (%s)' % macro.formatter.text(_("%.2f seconds") % elapsed))
  97     
  98         output += macro.formatter.paragraph(0)
  99         
 100         
 101         for searchresult in searchresults:
 102     
 103             output += macro.formatter.div(1, css_class='searchresults')       
 104             output += macro.formatter.definition_list(1)
 105             
 106             output += macro.formatter.definition_term(1)
 107             output += macro.formatter.url(1, url + searchresult[0] + '?highlight=' + searchterm)
 108             output += macro.formatter.text(searchresult[0])
 109             output += macro.formatter.url(0)
 110             output += macro.formatter.definition_term(0)
 111     
 112             output += macro.formatter.definition_desc(1)
 113             output += macro.formatter.small(1)
 114             output += macro.formatter.rawHTML(searchresult[1])
 115             output += macro.formatter.small(0)
 116             output += macro.formatter.definition_desc(0)
 117     
 118             output += macro.formatter.definition_list(0)
 119             output += macro.formatter.span(0)
 120 
 121         output += macro.formatter.linebreak(0)
 122         output += macro.formatter.linebreak(0)
 123         output += macro.formatter.linebreak(0)
 124         
 125     return output

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2006-11-17 19:56:31, 4.3 KB) [[attachment:a_farmfullsearch.py]]
  • [get | view] (2006-11-17 19:56:51, 4.4 KB) [[attachment:a_farmfullsearch2.py]]
  • [get | view] (2006-11-16 20:53:26, 5.1 KB) [[attachment:farmfullsearch.py]]
  • [get | view] (2006-11-17 13:55:51, 5.3 KB) [[attachment:farmfullsearch2.py]]
  • [get | view] (2006-11-18 16:45:04, 4.9 KB) [[attachment:farmfullsearch2_action_DL.py]]
  • [get | view] (2006-11-18 16:44:37, 5.6 KB) [[attachment:farmfullsearch2_macro_DL.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.