Attachment 'a_farmfullsearch.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 #request = macro.request
61 _ = macro.getText
62 output = ""
63 searchterm = args
64
65 #Taken from wikilist.py by TheAnarcat!
66 #for wiki in wikis:
67 # name = wiki[0]
68 # url = wiki[1]
69 # from re import sub
70 # # XXX, hack: transform the regexp into a canonical url
71 # # we need canonical urls in the config for this to be clean
72 # # look for (foo|bar) and replace with foo
73 # url = sub('\(([^\|]*)(\|[^\)]*\))+', '\\1', url)
74 # # remove common regexp patterns and slap a protocol to make this a real url
75 # url = 'http://' + sub('[\^\$]|(\.\*)', '', url)
76 # # for farmsearch we additionally need a slash at the end
77 # url = url + '/'
78
79 # Set the url for the remote farm wiki here. Note: Slash at the end is needed
80 url = "http://wikifarm.koumbit.net/"
81 srcwiki = xmlrpclib.ServerProxy(url + '?action=xmlrpc2')
82
83 start = time.time()
84 searchresults = srcwiki.searchPages(searchterm)
85 # This is a bad and time consuming solution just to get the number of pages searched
86 allpages = srcwiki.getAllPages()
87
88 output += macro.formatter.paragraph(1)
89 #output += macro.formatter.text(_("%s (%d results)") %(url, len(searchresults)))
90 output += macro.formatter.strong(1)
91 output += macro.formatter.text(url)
92 output += macro.formatter.strong(0)
93 output += macro.formatter.linebreak(0)
94 output += macro.formatter.text(_("%(hits)d results out of about %(pages)d pages.") %
95 {'hits': len(searchresults), 'pages': len(allpages)})
96 elapsed = time.time() - start
97 output += macro.formatter.text(u' (%s)' % macro.formatter.text(_("%.2f seconds") % elapsed))
98
99 output += macro.formatter.paragraph(0)
100
101
102 for searchresult in searchresults:
103
104 output += macro.formatter.div(1, css_class='searchresults')
105 output += macro.formatter.definition_list(1)
106
107 output += macro.formatter.definition_term(1)
108 output += macro.formatter.url(1, url + searchresult[0] + '?highlight=' + searchterm)
109 output += macro.formatter.text(searchresult[0])
110 output += macro.formatter.url(0)
111 output += macro.formatter.definition_term(0)
112
113 output += macro.formatter.definition_desc(1)
114 output += macro.formatter.small(1)
115 output += macro.formatter.rawHTML(searchresult[1])
116 output += macro.formatter.small(0)
117 output += macro.formatter.definition_desc(0)
118
119 output += macro.formatter.definition_list(0)
120 output += macro.formatter.span(0)
121
122 output += macro.formatter.linebreak(0)
123 output += macro.formatter.linebreak(0)
124 output += macro.formatter.linebreak(0)
125
126 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.