Commits

Thomas Waldmann  committed 919ae0e

add a separate +search view, remove incomplete search paging support, cleanup

.../+search -> get a search form to fill out

.../+search?q=foo -> search for "foo"

use "search" view url as action for search forms

rename "search_in_all" to "history" (clearer, shorter for URL in GET requests)

remove most search related code from "show" view (except feeding the empty
search form to the template)

fix css so the small theme searchform is right-aligned again

  • Participants
  • Parent commits 72adfe3
  • Branches pytest2

Comments (0)

Files changed (4)

File MoinMoin/apps/frontend/views.py

 Disallow: /+diffsince/
 Disallow: /+diff/
 Disallow: /+diffraw/
+Disallow: /+search
 Disallow: /+dispatch/
 Disallow: /+admin/
 Allow: /
         return True
 
 class SearchForm(Form):
-    q = String.using(optional=False).with_properties(autofocus=True, placeholder=L_("Search Query"))
+    q = String.using(optional=False, default=u'').with_properties(autofocus=True, placeholder=L_("Search Query"))
+    history = Boolean.using(label=L_('search also in non-current revisions'), optional=True)
     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()]
 
 
-def _search(search_form, item_name):
+@frontend.route('/+search', methods=['GET', 'POST'])
+def search():
+    search_form = SearchForm.from_flat(request.values)
+    valid = search_form.validate()
+    search_form['submit'].set_default() # XXX from_flat() kills all values
     query = search_form['q'].value
-    pagenum = 1  # We start from first page
-    pagelen = int(search_form['pagelen'].value)
-    all_revs = bool(request.values.get('search_in_all'))
-    qp = flaskg.storage.query_parser(["name_exact", "name", "content"], all_revs=all_revs)
-    q = qp.parse(query)
-    with flaskg.storage.searcher(all_revs) as searcher:
-        results = searcher.search_page(q, pagenum, pagelen)
+    if valid:
+        history = bool(request.values.get('history'))
+        qp = flaskg.storage.query_parser(["name_exact", "name", "content"], all_revs=history)
+        q = qp.parse(query)
+        with flaskg.storage.searcher(all_revs=history) as searcher:
+            results = searcher.search(q, limit=100)
+            return render_template('search_results.html',
+                                   results=results,
+                                   query=query,
+                                   medium_search_form=search_form,
+                                   item_name='+search', # XXX
+                                  )
+    else:
         return render_template('search_results.html',
-                               results=results,
                                query=query,
                                medium_search_form=search_form,
-                               item_name=item_name,
+                               item_name='+search', # XXX
                               )
 
 
-@frontend.route('/<itemname:item_name>', defaults=dict(rev=-1), methods=['GET', 'POST'])
-@frontend.route('/+show/<int:rev>/<itemname:item_name>', methods=['GET', 'POST'])
+
+@frontend.route('/<itemname:item_name>', defaults=dict(rev=-1), methods=['GET'])
+@frontend.route('/+show/<int:rev>/<itemname:item_name>', methods=['GET'])
 def show_item(item_name, rev):
-    # first check whether we have a valid search query:
-    search_form = SearchForm.from_flat(request.values)
-    if search_form.validate():
-        return _search(search_form, item_name)
-    search_form['submit'].set_default() # XXX from_flat() kills all values
-
     flaskg.user.addTrail(item_name)
     item_displayed.send(app._get_current_object(),
                         item_name=item_name)
                               data_rendered=Markup(item._render_data()),
                               show_revision=show_revision,
                               show_navigation=show_navigation,
-                              search_form=search_form,
+                              search_form=SearchForm.from_defaults(),
                              )
     return Response(content, status)
 

File MoinMoin/templates/layout.html

 <div id="moin-header">
 {% block header %}
     {% if search_form %} 
-    {{ gen.form.open(search_form, id='moin-searchform', method='get', action=url_for('frontend.show_item', item_name=item_name)) }}
+    {{ gen.form.open(search_form, id='moin-searchform', method='get', action=url_for('frontend.search')) }}
         <div>
             {{ gen.input(search_form['q'], type='search', id='moin-search-query', size='30') }}
             {{ gen.input(search_form['submit'], type='submit') }}
-            {{ gen.input(search_form['pagelen'], type='hidden', value='25') }}
             {{ forms.render_errors(search_form) }}
         </div>
     {{ gen.form.close() }}

File MoinMoin/templates/search_results.html

 {% extends theme("layout.html") %}
 {% import "utils.html" as utils %}
 {% block content %}
+    {% if results is defined %}
     <p class="searchstats">
         {% if results %}
-        {{ _("Result: Page %(start_page)d of %(end_page)d.
-              Showing results %(start_result)d - %(end_result)d of %(result_len)d (%(runtime).3f secs).",
-              start_page=results.pagenum, end_page=results.pagecount,
-              start_result=results.offset + 1, end_result=results.offset + results.pagelen,
-              result_len=results|length, runtime=results.results.runtime
+        {{ _("%(result_len)d results found (%(runtime).3f secs).",
+              result_len=results|length, runtime=results.runtime
             )
         }}
         {% else %}
-        {{ _("No results found (%(runtime).3f secs).", runtime=results.results.runtime) }}
+        {{ _("No results found (%(runtime).3f secs).", runtime=results.runtime) }}
         {% endif %}
     </p>
-    {{ gen.form.open(medium_search_form, id='moin-long-searchform', method='get', action=url_for('frontend.show_item', item_name=item_name)) }}
+    {% endif %}
+    {{ gen.form.open(medium_search_form, id='moin-long-searchform', method='get', action=url_for('frontend.search')) }}
         <div>
             {{ 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_field_without_markup(gen, medium_search_form['history'], 'checkbox') }}
             {{ forms.render_errors(medium_search_form) }}
         </div>
     {{ gen.form.close() }}
-    {% if results %}
+    {% if results is defined %}
     <div class="searchresults">
         <table>
             {% for result in results %}

File MoinMoin/themes/modernized/static/css/common.css

             line-height: 1.12em; }
 
 /* moin-header searchform */
-#moin-searchform { margin: 8px .5em; padding: 0; font-size: 0.82em; float: right;  text-align: left; }
+#moin-searchform { margin: 8px .5em; padding: 0; font-size: 0.82em; float: right;  text-align: right; }
 #moin-searchform input { font-size: 100%; vertical-align: middle;
             background-color: #F3F7FD; /* same as body bg col */
             border: 1px solid #A4B9DF; }