comparison MoinMoin/macro/FullSearch.py @ 0:77665d8e2254

tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0 (automatically generated log message) imported from: moin--main--1.5--base-0
author Thomas Waldmann <tw-public@gmx.de>
date Thu, 22 Sep 2005 15:09:50 +0000
parents
children 2202f548cbb0
comparison
equal deleted inserted replaced
-1:000000000000 0:77665d8e2254
1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - FullSearch Macro
4
5 [[FullSearch]]
6 displays a search dialog, as it always did.
7
8 [[FullSearch()]]
9 does the same as clicking on the page title, only that
10 the result is embedded into the page. note the '()' after
11 the macro name, which is an empty argument list.
12
13 [[FullSearch(Help)]]
14 embeds a search result into a page, as if you entered
15 'Help' into the search box.
16
17 The macro creates a page list without context or match info, just
18 like PageList macro. It does not make sense to have context in non
19 interactive search, and this kind of search is used usually for
20 Category pages, where we don't care about the context.
21
22 TODO: If we need to have context for some cases, either we add a
23 context argument, or make another macro that use context, which may
24 be easier to use.
25
26 @copyright: 2000-2004 by Jürgen Hermann <jh@web.de>
27 @license: GNU GPL, see COPYING for details.
28 """
29
30 import re, urllib
31 from MoinMoin import config, wikiutil, search
32
33 Dependencies = ["pages"]
34
35 def execute(macro, needle):
36 request = macro.request
37 _ = request.getText
38
39 # if no args given, invoke "classic" behavior
40 if needle is None:
41 return macro._m_search("fullsearch")
42
43 # With empty arguments, simulate title click (backlinks to page)
44 elif needle == '':
45 needle = '"%s"' % macro.formatter.page.page_name
46
47 # With whitespace argument, show error message like the one used in the search box
48 # TODO: search should implement those errors message for clients
49 elif needle.isspace():
50 err = _('Please use a more selective search term instead of '
51 '{{{"%s"}}}') % needle
52 return '<span class="error">%s</span>' % err
53
54 needle = needle.strip()
55
56 # Search the pages and return the results
57 query = search.QueryParser().parse_query(needle)
58 results = search.searchPages(request, query)
59 results.sortByPagename()
60
61 return results.pageList(request, macro.formatter)
62
63