Browse Source

Search engine templates & views

Gu1 11 years ago
parent
commit
060c041d8b

+ 0 - 1
ffdnispdb/templates/index.html

@@ -1,6 +1,5 @@
 {% extends "layout.html" %}
 {% block container %}
-  {% if error %}<p class=error><strong>Error:</strong> {{ error }}{% endif %}
   <div class="row-fluid">
     <div class="span9">
       <div id="map"></div>

+ 2 - 2
ffdnispdb/templates/layout.html

@@ -31,8 +31,8 @@
       </a>
       <a class="brand" href="/"><span id="ffdn-header"><span>F</span><span>F</span><span>D</span><span>N</span></span> Database</a>
       <div class="nav-collapse collapse">
-        <form class="navbar-search pull-right">
-          <input type="text" id="search-input" class="search-query input-medium" placeholder="{{ _("Search") }}"/>
+        <form method="get" action="/search" class="navbar-search pull-right">
+          <input type="text" id="search-input" class="search-query input-medium" name="q" placeholder="{{ _("Search") }}" />
         </form>
         <ul class="nav pull-right">
           {{ menu_item(_("Home"), 'home') }}

+ 17 - 0
ffdnispdb/templates/search_results.html

@@ -0,0 +1,17 @@
+{% extends "layout.html" %}
+{% from 'project_list_macro.html' import project_list %}
+{% block container %}
+<div style="margin-top: 25px;">
+  <form>
+    <div class="input-append">
+      <input class="input-xxlarge" name="q" type="text" value="{{ search_terms }}">
+      <button type="submit" class="btn">{{ _("Search") }}</button>
+    </div>
+  </form>
+{% if results -%}
+{{ project_list(results) }}
+{%- else -%}
+  {{ _("No ISP matching your query was found :-(") }}
+{%- endif %}
+</div>
+{% endblock %}

+ 7 - 4
ffdnispdb/views.py

@@ -17,7 +17,7 @@ import os.path
 from . import forms
 from .constants import *
 from . import app, db, cache
-from .models import ISP
+from .models import ISP, ISPWhoosh
 from .crawler import PrettyValidator
 
 
@@ -160,9 +160,12 @@ def create_project_json_confirm():
 
 @app.route('/search', methods=['GET', 'POST'])
 def search():
-    if request.method == 'POST':
-        pass
-    return render_template('search.html')
+    terms=request.args.get('q')
+    if not terms:
+        return redirect(url_for('home'))
+
+    res=ISPWhoosh.search(terms)
+    return render_template('search_results.html', results=res, search_terms=terms)
 
 
 @app.route('/format', methods=['GET'])

+ 3 - 0
requirements.txt

@@ -8,9 +8,12 @@ Werkzeug==0.9.3
 argparse==1.2.1
 itsdangerous==0.23
 wsgiref==0.1.2
+blinker==1.3
 jsonschema==2.0.0
 requests==2.0.0
 # ndg & pyasn required for SNI
 ndg-httpsclient==0.3.2
 pyasn1==0.1.7
 docutils==0.11
+# full-text search
+Whoosh==2.5.4