changeset 432:66981eb25822

Added searching in non-current revisions Fixes #18.
author Michael Mayorov <marchael@kb.csu.ru>
date Sat, 13 Aug 2011 16:20:46 +0000
parents 6800ab9dd159
children 406966afa113
files MoinMoin/apps/frontend/views.py MoinMoin/templates/forms.html MoinMoin/templates/search_results.html
diffstat 3 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Sat Aug 13 15:58:40 2011 +0000
+++ b/MoinMoin/apps/frontend/views.py	Sat Aug 13 16:20:46 2011 +0000
@@ -125,6 +125,7 @@
     q = String.using(optional=False).with_properties(autofocus=True, placeholder=L_("Search Query"))
     submit = String.using(default=L_('Search'), optional=True)
     pagelen = String.using(optional=False)
+    search_in_all = Boolean.using(label=L_('search also in non-current revisions'), optional=True)
 
     validators = [ValidSearch()]
 
@@ -138,9 +139,9 @@
     pagenum = 1 # We start from first page
     pagelen = search_form['pagelen'].value
     index_object = WhooshIndex()
-    latest_index = index_object.latest_revisions_index
-    with latest_index.searcher() as searcher:
-        mparser = MultifieldParser(["name", "content"], schema=latest_index.schema)
+    ix = index_object.all_revisions_index if request.values.get('search_in_all') else index_object.latest_revisions_index
+    with ix.searcher() as searcher:
+        mparser = MultifieldParser(["name", "content"], schema=ix.schema)
         q = mparser.parse(query)
         results = searcher.search_page(q, int(pagenum), pagelen=int(pagelen))
         return render_template('search_results.html',
--- a/MoinMoin/templates/forms.html	Sat Aug 13 15:58:40 2011 +0000
+++ b/MoinMoin/templates/forms.html	Sat Aug 13 16:20:46 2011 +0000
@@ -54,3 +54,9 @@
     </dd>
     {% endif %}
 {% endmacro %}
+
+{% macro render_field_without_markup(gen, field, field_type) %}
+    {{ gen.input(field, type=field_type) }}
+    {{ gen.label(field) }}
+    {{ render_errors(field) }}
+{% endmacro %}
--- a/MoinMoin/templates/search_results.html	Sat Aug 13 15:58:40 2011 +0000
+++ b/MoinMoin/templates/search_results.html	Sat Aug 13 16:20:46 2011 +0000
@@ -16,6 +16,7 @@
             {{ gen.input(medium_search_form['q'], type='search', id='moin-search-query') }}
             {{ gen.input(medium_search_form['submit'], type='submit') }}
             {{ gen.input(medium_search_form['pagelen'], type='hidden', value='25') }}
+            {{ forms.render_field_without_markup(gen, medium_search_form['search_in_all'], 'checkbox') }}
             {{ forms.render_errors(medium_search_form) }}
         </div>
     {{ gen.form.close() }}