changeset 1373:90cb8fe71cdf

get fullsearch action working with the advanced search dialogue
author Franz Pletz <fpletz AT franz-pletz DOT org>
date Fri, 18 Aug 2006 18:06:42 +0200
parents 6dacf2061124
children aa33bb2b40d6
files MoinMoin/action/fullsearch.py MoinMoin/macro/AdvancedSearch.py
diffstat 2 files changed, 41 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/fullsearch.py	Fri Aug 18 14:41:47 2006 +0200
+++ b/MoinMoin/action/fullsearch.py	Fri Aug 18 18:06:42 2006 +0200
@@ -8,6 +8,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
+import re
 from MoinMoin.Page import Page
 from MoinMoin import wikiutil
 
@@ -23,14 +24,15 @@
     try:
         return int(request.form['titlesearch'][0])
     except ValueError:
-        return not isAdvancedSearch(request)
+        return True
     except KeyError:
-        return 'fullsearch' not in request.form
+        return 'fullsearch' not in request.form and \
+                not isAdvancedSearch(request)
 
 def isAdvancedSearch(request):
     try:
         return int(request.form['advancedsearch'][0])
-    except ValueError:
+    except KeyError:
         return False
 
 def execute(pagename, request, fieldname='value', titlesearch=0):
@@ -41,6 +43,9 @@
     # context is relevant only for full search
     if titlesearch:
         context = 0
+    elif advancedsearch:
+        # XXX: hardcoded
+        context = 180
     else:
         context = int(request.form.get('context', [0])[0])
 
@@ -52,6 +57,30 @@
 
     max_context = 1 # only show first `max_context` contexts XXX still unused
 
+    if advancedsearch:
+        and_terms = request.form.get('and_terms', [''])[0].strip()
+        or_terms = request.form.get('or_terms', [''])[0].strip()
+        not_terms = request.form.get('not_terms', [''])[0].strip()
+        #xor_terms = request.form.get('xor_terms', [''])[0].strip()
+        categories = request.form.get('categories', [''])[0].strip()
+        timeframe = request.form.get('time', [''])[0].strip()
+        language = request.form.get('language',
+                [request.cfg.language_default])[0]
+        
+        word_re = re.compile(r'(\"[\w\s]+"|\w+)')
+        needle = ''
+        if language:
+            needle += 'language:%s ' % language
+        if categories:
+            needle += '(%s) ' % ' or '.join(['category:%s' % cat
+                for cat in word_re.findall(categories)])
+        if and_terms:
+            needle += '(%s) ' % and_terms
+        if not_terms:
+            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))
+
     # check for sensible search term
     striped = needle.strip()
     if len(striped) == 0:
@@ -60,6 +89,7 @@
         request.emit_http_headers()
         Page(request, pagename).send_page(request, msg=err)
         return
+    needle = striped
 
     # Setup for type of search
     if titlesearch:
--- a/MoinMoin/macro/AdvancedSearch.py	Fri Aug 18 14:41:47 2006 +0200
+++ b/MoinMoin/macro/AdvancedSearch.py	Fri Aug 18 18:06:42 2006 +0200
@@ -29,7 +29,7 @@
 
     search_boxes = ''.join([
         f.table_row(1),
-        f.table_cell(1, attrs={'rowspan': '7', 'class': 'searchfor'}),
+        f.table_cell(1, attrs={'rowspan': '6', 'class': 'searchfor'}),
         f.text(_('Search for pages')),
         f.table_cell(0),
         ''.join([''.join([
@@ -43,18 +43,18 @@
             f.table_row(0),
         ]) for txt, input_field in (
             ('containing all the following terms',
-                '<input type="text" name="all_terms" size="30">'),
+                '<input type="text" name="and_terms" size="30">'),
             ('containing one or more of the following '
                 'terms', '<input type="text" name="or_terms" size="30">'),
             ('not containing the following terms',
                 '<input type="text" name="not_terms" size="30">'),
-            ('containing only one of the following terms',
-                '<input type="text" name="xor_terms" size="30">'),
+            #('containing only one of the following terms',
+            #    '<input type="text" name="xor_terms" size="30">'),
             # TODO: dropdown-box?
             ('belonging to one of the following categories',
                 '<input type="text" name="categories" size="30">'),
-            ('edited since/until the following date',
-                '<input type="text" name="date" size="30" value="now">'),
+            ('edited in the the following timeframe (XXX)',
+                '<input type="text" name="time" size="30" value="until now">'),
         )])
     ])
 
@@ -70,7 +70,7 @@
 
     import mimetypes
     ft_dropdown = ''.join([
-        u'<select name="language" size="1">',
+        u'<select name="mimetype" size="1">',
         u'<option value="" selected>%s</option>' % _('any type'),
         ''.join(['<option value="%s">%s</option>' % (m[1], '*%s - %s' % m)
             for m in sorted(mimetypes.types_map.items())]),
@@ -89,7 +89,7 @@
             f.table_row(0),
             ]) for txt in (
                 ('Language', lang_dropdown),
-                ('File Type', ft_dropdown),
+                ('File Type (XXX)', ft_dropdown),
                 ('', '<input type="checkbox" name="titlesearch" value="1">%s</input>' %
                 _('Search only in titles')),
                 ('', '<input type="checkbox" name="case" value="1">%s</input>' %