Attachment 'farmfullsearch2_action_DL.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 Changes:
13 * 2006-11-18 (DavidLinke) Handle failure of xmlrpc request gracefully
14 Failure is expected e.g. when authentication is required.
15 """
16
17 import time
18 import xmlrpclib
19 from MoinMoin.Page import Page
20 from MoinMoin import wikiutil
21 from MoinMoin.util import MoinMoinNoFooter
22 from farmconfig import wikis
23
24
25 def execute(pagename, request, fieldname='value', titlesearch=0):
26 _ = request.getText
27
28 # Get other form parameters
29 needle = request.form.get(fieldname, [''])[0]
30
31 # check for sensible search term
32 striped = needle.strip()
33 if len(striped) == 0:
34 err = _('Please use a more selective search term instead '
35 'of {{{"%s"}}}') % needle
36 # send http headers
37 request.http_headers()
38 Page(request, pagename).send_page(request, msg=err)
39 return
40
41 # search the pages
42 results = searchfarm(request, needle)
43
44 # send http headers
45 request.http_headers()
46
47 # This action generate data using the user language
48 request.setContentLanguage(request.lang)
49 title = _('Fulll Text Search: "%s"')
50 wikiutil.send_title(request, title % needle, form=request.form,
51 pagename=pagename)
52
53 # Start content (important for RTL support)
54 request.write(request.formatter.startContent("content"))
55
56 request.write(results)
57
58 # End content and send footer
59 request.write(request.formatter.endContent())
60 wikiutil.send_footer(request, pagename)
61
62
63 def searchfarm(macro, args):
64 _ = macro.getText
65 output = ""
66 searchterm = args
67
68 for wiki in wikis:
69 searchresults = []
70 #Code partly taken from wikilist.py by TheAnarcat!
71 name = wiki[0]
72 url = wiki[1]
73 from re import sub
74 # XXX, hack: transform the regexp into a canonical url
75 # we need canonical urls in the config for this to be clean
76 # look for (foo|bar) and replace with foo
77 url = sub('\(([^\|]*)(\|[^\)]*\))+', '\\1', url)
78 # remove common regexp patterns and slap a protocol to make this a real url
79 url = 'http://' + sub('[\^\$]|(\.\*)', '', url)
80 # for farmsearch we additionally need a slash at the end
81 url = url + '/'
82
83 # Set the url for the remote farm wiki here. Note: Slash at the end is needed
84 #url = "http://wikifarm.koumbit.net/"
85 srcwiki = xmlrpclib.ServerProxy(url + '?action=xmlrpc2')
86
87 start = time.time()
88 try:
89 searchresults = srcwiki.searchPages(searchterm)
90 # This is a bad and time consuming solution just to get the number of pages searched
91 allpages = srcwiki.getAllPages()
92 except xmlrpclib.ProtocolError:
93 output += macro.formatter.paragraph(1)
94 output += macro.formatter.text('Failed to perform search in %s' %
95 url)
96 output += macro.formatter.paragraph(0)
97 continue
98
99 output += macro.formatter.paragraph(1)
100 #output += macro.formatter.text(_("%s (%d results)") %(url, len(searchresults)))
101 output += macro.formatter.strong(1)
102 output += macro.formatter.text(name)
103 output += macro.formatter.strong(0)
104 output += macro.formatter.linebreak(0)
105 output += macro.formatter.text(_("%(hits)d results out of about %(pages)d pages.") %
106 {'hits': len(searchresults), 'pages': len(allpages)})
107 elapsed = time.time() - start
108 output += macro.formatter.text(u' (%s)' % macro.formatter.text(_("%.2f seconds") % elapsed))
109
110 output += macro.formatter.paragraph(0)
111
112
113 for searchresult in searchresults:
114
115 output += macro.formatter.div(1, css_class='searchresults')
116 output += macro.formatter.definition_list(1)
117
118 output += macro.formatter.definition_term(1)
119 output += macro.formatter.url(1, url + searchresult[0] + '?highlight=' + searchterm)
120 output += macro.formatter.text(searchresult[0])
121 output += macro.formatter.url(0)
122 output += macro.formatter.definition_term(0)
123
124 output += macro.formatter.definition_desc(1)
125 output += macro.formatter.small(1)
126 output += macro.formatter.rawHTML(searchresult[1])
127 output += macro.formatter.small(0)
128 output += macro.formatter.definition_desc(0)
129
130 output += macro.formatter.definition_list(0)
131 output += macro.formatter.span(0)
132
133 output += macro.formatter.linebreak(0)
134 output += macro.formatter.linebreak(0)
135 output += macro.formatter.linebreak(0)
136
137 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.You are not allowed to attach a file to this page.