annotate MoinMoin/macro/FullSearch.py @ 3244:886b8969dbc6

fix some unit tests
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 12 Mar 2008 01:08:43 +0100
parents 03b3c6fd70e3
children 17d11e11daf2
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
3 MoinMoin - FullSearch Macro
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
5 <<FullSearch>>
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
6 displays a search dialog, as it always did.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
7
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
8 <<FullSearch()>>
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
9 does the same as clicking on the page title, only that
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
10 the result is embedded into the page. note the '()' after
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
11 the macro name, which is an empty argument list.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
12
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
13 <<FullSearch(Help)>>
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
14 embeds a search result into a page, as if you entered
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
15 'Help' into the search box.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
16
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
17 The macro creates a page list without context or match info, just
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
18 like PageList macro. It does not make sense to have context in non
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
19 interactive search, and this kind of search is used usually for
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
20 Category pages, where we don't care about the context.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
21
1832
b180f047d918 comments only: cleaned up TODO, XXX, ...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
22 TODO: If we need to have context for some cases, either we add a context argument,
b180f047d918 comments only: cleaned up TODO, XXX, ...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
23 or make another macro that uses context, which may be easier to use.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
24
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
25 @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
26 2006 MoinMoin:FranzPletz
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
27 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
28 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
29
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1449
diff changeset
30 from MoinMoin import wikiutil, search
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
31
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
32 Dependencies = ["pages"]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
33
1217
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
34
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
35 def search_box(type, macro):
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
36 """ Make a search box
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
37
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
38 Make both Title Search and Full Search boxes, according to type.
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
39
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
40 @param type: search box type: 'titlesearch' or 'fullsearch'
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
41 @rtype: unicode
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
42 @return: search box html fragment
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
43 """
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
44 _ = macro._
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1832
diff changeset
45 if 'value' in macro.form:
1217
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
46 default = wikiutil.escape(macro.form["value"][0], quote=1)
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
47 else:
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
48 default = ''
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
49
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
50 # Title search settings
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
51 boxes = ''
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
52 button = _("Search Titles")
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
53
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
54 # Special code for fullsearch
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
55 if type == "fullsearch":
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
56 boxes = [
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
57 u'<br>',
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
58 u'<input type="checkbox" name="context" value="160" checked="checked">',
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
59 _('Display context of search results'),
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
60 u'<br>',
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
61 u'<input type="checkbox" name="case" value="1">',
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
62 _('Case-sensitive searching'),
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
63 ]
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
64 boxes = u'\n'.join(boxes)
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
65 button = _("Search Text")
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
66
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
67 # Format
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
68 type = (type == "titlesearch")
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
69 html = [
3040
8608b258f8e6 bug fix of MoinMoinBugs/MoveAttachmentNotWorkingWithModPython (thanks to Boleslaw Kulbabinski) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
70 u'<form method="get" action="%s/%s">' % (macro.request.getScriptname(), wikiutil.quoteWikinameURL(macro.request.formatter.page.page_name)),
1217
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
71 u'<div>',
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
72 u'<input type="hidden" name="action" value="fullsearch">',
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
73 u'<input type="hidden" name="titlesearch" value="%i">' % type,
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
74 u'<input type="text" name="value" size="30" value="%s">' % default,
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
75 u'<input type="submit" value="%s">' % button,
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
76 boxes,
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
77 u'</div>',
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
78 u'</form>',
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
79 ]
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
80 html = u'\n'.join(html)
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
81 return macro.formatter.rawHTML(html)
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
82
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
83
3241
03b3c6fd70e3 changed to new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3123
diff changeset
84 def macro_FullSearch(macro, needle=None):
3244
886b8969dbc6 fix some unit tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3241
diff changeset
85
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
86 request = macro.request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
87 _ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
88
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
89 # if no args given, invoke "classic" behavior
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
90 if needle is None:
1217
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
91 return search_box("fullsearch", macro)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
92
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
93 # With empty arguments, simulate title click (backlinks to page)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
94 elif needle == '':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
95 needle = '"%s"' % macro.formatter.page.page_name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
96
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
97 # With whitespace argument, show error message like the one used in the search box
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
98 # TODO: search should implement those errors message for clients
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
99 elif needle.isspace():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
100 err = _('Please use a more selective search term instead of '
3123
5cb80bd604b4 refactored _() getText calls to match new api
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3040
diff changeset
101 '{{{"%s"}}}', wiki=True) % needle
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
102 return '<span class="error">%s</span>' % err
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
103
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
104 needle = needle.strip()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
105
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
106 # Search the pages and return the results
1449
e219092e1a0d a few small fixes to get misc things working with xapian
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1364
diff changeset
107 results = search.searchPages(request, needle, sort='page_name')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
108
1189
0e352443948b make FullSearch macro work again (without paging)
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 950
diff changeset
109 return results.pageList(request, macro.formatter, paging=False)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
110
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
111