searchform only for mimetype text/wiki

It was annoying for me that a quick search over the searchform always displayed a lot of attachments (images, word docs, etc.)

So I found a quick and maybe ugly solutions.

new_searchbox.png

System Info:

Version
1.7.1
Theme

ThemeMarket/SimpleMente

Search
Xapian Search enabled
Example

http://rock.heavy.ch

Changes

Theme

I added to the function searchform a html checkbox, where it's possible to submit a mimetype (=text/wiki). In my case this is the default

 <input id="searchmimetype" type="checkbox" checked="checked" name="mimetype" value="text/wiki">  

for your information here is my new searchform; but be aware this is used for my heavy customized theme (original a SimpleMente).

    def searchform(self, d):
        """ assemble HTML code for the search forms

        Changed: linebreak added for simplerock. Searchbox formatting now done by
                 css
        
        @param d: parameter dictionary
        @rtype: unicode
        @return: search form html
        """
        _ = self.request.getText
        form = self.request.form
        updates = {
            'search_label': _('Search:'),
            'search_alt': _('Search'),
            'search_titles_alt': _('Search Titles'),
            'search_full_alt': _('Search Full Text'),
            'search_value': wikiutil.escape(form.get('value', [''])[0], 1),
            'search_full_label': _('Text', formatted=False),
            'search_title_label': _('Titles', formatted=False),
            'search_mimetype_label': _('only pages', formatted=False),
            }
        d.update(updates)

        html = u'''
<form id="searchform" method="get" action="">
<div>
<input type="hidden" name="action" value="fullsearch">
<input type="hidden" name="context" value="180">
<label for="searchinput">%(search_label)s</label>
<input id="searchinput" type="text" name="value" value="%(search_value)s" size="20"
    onfocus="searchFocus(this)" onblur="searchBlur(this)"
    onkeyup="searchChange(this)" onchange="searchChange(this)" alt="%(search_alt)s">
<br>
<span class="searchmimetype"><input id="searchmimetype" type="checkbox" checked="checked" name="mimetype" value="text/wiki"> %(search_mimetype_label)s </span>
<br>
<input id="titlesearch" name="titlesearch" type="submit"
    value="%(search_title_label)s" alt="%(search_titles_alt)s">
<input id="fullsearch" name="fullsearch" type="submit"
    value="%(search_full_label)s" alt="%(search_full_alt)s">
</div>
</form>
<script type="text/javascript">
<!--// Initialize search form
var f = document.getElementById('searchform');
f.getElementsByTagName('label')[0].style.display = 'none';
var e = document.getElementById('searchinput');
searchChange(e);
searchBlur(e);
//-->
</script>
''' % d
        return html

Action

I needed also to change the fullsearch.py

Mainly I add “mimetype:major/minor” to the needle string (like advancedsearch). Here is my diff

--- MoinMoin/action/fullsearch.py       2008-08-04 14:50:56.000000000 -0500
+++ plugin/action/fullsearch.py 2008-08-04 14:50:08.000000000 -0500
@@ -82,6 +82,7 @@
     mtime = None
     msg = ''
     historysearch = 0
+    mimetype = request.form.get('mimetype', [0]) #removed from only advancedsearch 
 
     # if advanced search is enabled we construct our own search query
     if advancedsearch:
@@ -92,7 +93,6 @@
         categories = request.form.get('categories', [''])
         timeframe = request.form.get('time', [''])[0].strip()
         language = request.form.get('language', [''])
-        mimetype = request.form.get('mimetype', [0])
         excludeunderlay = request.form.get('excludeunderlay', [0])[0]
         nosystemitems = request.form.get('nosystemitems', [0])[0]
         historysearch = request.form.get('historysearch', [0])[0]
@@ -157,6 +157,11 @@
             needle += '(%s) ' % ' '.join(['-%s' % t for t in word_re.findall(not_terms)])
         if or_terms:
             needle += '(%s) ' % ' or '.join(word_re.findall(or_terms))
+    else:
+        #added for mimetype search over the searchform
+        if mimetype[0]:
+            needle = 'mimetype:%s (%s)' % (','.join(mimetype), needle)
+           
 
     # check for sensible search term
     stripped = needle.strip()

Result

Futures

Maybe somebody with a better python knowledge could create a better solution... don't know... just want to share my “experience”.

Bye -- MarcelHäfner 2008-08-04 20:28:25


CategoryFeatureRequest

MoinMoin: FeatureRequests/SearchformWithoutAttachmentSearch (last edited 2008-08-04 20:40:12 by MarcelHäfner)