annotate MoinMoin/macro/FullSearch.py @ 1217:237ca54182a7

copied code for search box over to macro/FullSearch.py
author Franz Pletz <fpletz AT franz-pletz DOT org>
date Wed, 02 Aug 2006 20:56:26 +0200
parents 0e352443948b
children 12ddd8661ad6
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
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
5 [[FullSearch]]
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
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
8 [[FullSearch()]]
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
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
13 [[FullSearch(Help)]]
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
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
22 TODO: If we need to have context for some cases, either we add a
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
23 context argument, or make another macro that use context, which may
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
24 be easier to use.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
25
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
26 @copyright: 2000-2004 by Jürgen Hermann <jh@web.de>
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
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
30 import re
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
31 from MoinMoin import config, wikiutil, search
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
32
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
33 Dependencies = ["pages"]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
34
1217
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
35
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
36 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
37 """ 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
38
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
39 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
40
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
41 @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
42 @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
43 @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
44 """
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
45 _ = macro._
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
46 if macro.form.has_key('value'):
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
47 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
48 else:
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
49 default = ''
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
50
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
51 # 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
52 boxes = ''
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
53 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
54
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
55 # 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
56 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
57 boxes = [
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'<br>',
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
59 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
60 _('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
61 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
62 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
63 _('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
64 ]
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
65 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
66 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
67
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
68 # Format
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
69 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
70 html = [
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'<form method="get" action="">',
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'<div>',
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="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
74 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
75 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
76 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
77 boxes,
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'</div>',
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
79 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
80 ]
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
81 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
82 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
83
237ca54182a7 copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1189
diff changeset
84
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
85 def execute(macro, needle):
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 '
950
4eb66637ccd0 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 919
diff changeset
101 '{{{"%s"}}}') % 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
919
5469c8b911a4 Splitting out MoinMoin/search.py to MoinMoin/search/*.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 101
diff changeset
107 results = search.searchPages(request, needle)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
108 results.sortByPagename()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
109
1189
0e352443948b make FullSearch macro work again (without paging)
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 950
diff changeset
110 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
111
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
112