Contents
fullsearch
Version History
Action |
Author |
Designed for MoinMoin Release... |
|
see Author |
1.8.4 |
Purpose
I want that a fastsearch (normally in the right upper corner, but depends on the used theme) only returns results from wiki pages (mimetpye=text/wiki). Primarly it should NOT contain any images or audiofiles. In my case I had a lot of images with similarly wikipages, and for the user it was annoying to always find the correct wikipage between all this other mimetypes. that's why I changed the current action a bit.
Usage / Installation
You need to implement those following two steps to integrate my modified action fullsearch in your moinmoin theme.
action
Download the action, move it into your correct plugin directory for the actions and rename it to fullsearch.py (till now everything is working like before; drawback is if "some" moinmoin core developer modify the fullsearch.py action you need to adjust this by yourself in future releases). Here is also a diff: fullsearch.diff
search form
you have to modify also your theme code and add a custom "searchform" function to your "Theme" class (if it's not alreay there), like:
1 def searchform(self, d):
2 """
3 assemble HTML code for the search forms
4
5 @param d: parameter dictionary
6 @rtype: unicode
7 @return: search form html
8 """
9 _ = self.request.getText
10 form = self.request.form
11 updates = {
12 'search_label': _('Search:'),
13 'search_value': wikiutil.escape(form.get('value', [''])[0], 1),
14 'search_full_label': _('Text'),
15 'search_title_label': _('Titles'),
16 'baseurl': self.request.getScriptname(),
17 'pagename_quoted': wikiutil.quoteWikinameURL(d['page'].page_name),
18 }
19 d.update(updates)
20
21 html = u'''
22 <form id="searchform" method="get" action="%(baseurl)s/%(pagename_quoted)s">
23 <div>
24 <input type="hidden" name="action" value="fullsearch">
25 <input type="hidden" name="context" value="180">
26 <input id="searchmimetype" type="hidden" value="text/wiki" name="mimetype"/>
27 <label for="searchinput">%(search_label)s</label>
28 <input id="searchinput" type="text" name="value" value="%(search_value)s" size="20"
29 onfocus="searchFocus(this)" onblur="searchBlur(this)"
30 onkeyup="searchChange(this)" onchange="searchChange(this)" alt="Search">
31 <input id="titlesearch" name="titlesearch" type="submit"
32 value="%(search_title_label)s" alt="Search Titles">
33 <input id="fullsearch" name="fullsearch" type="submit"
34 value="%(search_full_label)s" alt="Search Full Text">
35 </div>
36 </form>
37 <script type="text/javascript">
38 <!--// Initialize search form
39 var f = document.getElementById('searchform');
40 f.getElementsByTagName('label')[0].style.display = 'none';
41 var e = document.getElementById('searchinput');
42 searchChange(e);
43 searchBlur(e);
44 //-->
45 </script>
46 ''' % d
47 return html
The keypoint is to add this following line into the searchform html code:
<input id="searchmimetype" type="hidden" value="text/wiki" name="mimetype"/>
Procedure
- search form contains a hidden attribute name="mimetype" and value="text/wiki"
this will add to the normal url (when you hit title or text search) the parameter &mimetype=text%2Fwiki
the new action fullsearch will use this parameter for a mimetype search (1:1 like the FindPage form will do with the dropdown field))
if a user still want to search for e.g. an image; he would need to use the FindPage
- only wikipages will be displayed in the resultlists
Example
now here doing a titlesearch with the keyword gun on my wiki site rock.heavy:
all mimetypes are displayed (ugly):
only wikipages are displayed (better):
Copyright
just modified the current fullsearch action, so no big deal.
ToDo
Discussion
- I think a stable solution should be maybe achieve after all the storage work (moin 2.0) is done.
- The point maybe is that it depends on the focus of the wiki if you want per default a search also for "attachments" or only for page titles.
- Maybe add a checkbox below the input field of the search form (only wikipages = yes)
- setup in the wikiconfig what the default search will do
- setup up in the user preferences
- or give the possiblity to exclude some mimetype in the searchresult (resorting stuff..)