diff --git a/franklincce/explorer/templates/explorer/search.html b/franklincce/explorer/templates/explorer/search.html
new file mode 100644
index 0000000..771d902
--- /dev/null
+++ b/franklincce/explorer/templates/explorer/search.html
@@ -0,0 +1,15 @@
+{% extends "explorer/base.html" %}
+
+{% block content %}
+
+
+
Search legislation by keyword
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/franklincce/explorer/urls.py b/franklincce/explorer/urls.py
index c0ef9bd..f2182c8 100644
--- a/franklincce/explorer/urls.py
+++ b/franklincce/explorer/urls.py
@@ -10,6 +10,7 @@ urlpatterns = [
path("conference//", views.view_conference, name="viewconf"),
path("topics//", views.get_all_classified_by_id, name="LegislationClassification.detail"),
path("topics/", views.get_all_classifications, name="LegislationClassification"),
+ path("search/", views.handle_search, name="search_legislation"),
# these are named weirdly -- see models.py School and Country definitions
path("schools//", views.get_all_by_school, name="School.detail"),
diff --git a/franklincce/explorer/views.py b/franklincce/explorer/views.py
index 0362db8..6b7db90 100644
--- a/franklincce/explorer/views.py
+++ b/franklincce/explorer/views.py
@@ -130,6 +130,31 @@ def return_groups(request):
print(listing)
return render(request, "explorer/by_group.html", { "listing": listing })
+def handle_search(request):
+ try:
+ query = request.GET['search_term']
+ except KeyError:
+ return render(request, "explorer/search.html", {})
+
+ f = LegislativeText.objects.filter
+
+ text_results = f(text__icontains=query)
+ title_results = f(legislation_title__icontains=query)
+ school_results = f(school__name__icontains=query)
+ sponsor_results = f(sponsors__name__icontains=query)
+ country_results = f(country__name__icontains=query)
+
+
+ return render(request, "explorer/results.html", {
+ "result_name": "Results for search term '{}'".format(query),
+ "legislation": text_results.union(
+ title_results,
+ school_results,
+ sponsor_results,
+ country_results
+ )
+ })
+
get_all_by_school = get_all_by_x(School)
get_all_by_country = get_all_by_x(Country)
get_all_by_sponsor = get_all_by_x(Sponsor)