Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

TMP

  • Loading branch information...
commit 721b1b2073066d3006c815b7a50518ea94f45844 1 parent 4435d96
@davedash davedash authored
View
27 apps/search/templates/search/aggregate.html
@@ -0,0 +1,27 @@
+{% extends "base_fluid_width.html" %}
+{% load base_helpers %}
+
+{% block title %}Search for {{ query }}{% endblock %}
+
+{% block app_content %}
+<h3>Add-on Matches <span class="count">({{ addon_total }})</span></h3>
+
+<ol>
+ {% for item in addons %}
+ <li>{{ item.name }}</li>
+ {% endfor %}
+</ol>
+
+<p>See all {{ addons_total }} add-on matches for <q>{{ query }}</q></p>
+
+<h3>Library Matches <span class="count">({{ library_total }})</span></h3>
+
+<ol>
+ {% for item in libraries %}
+ <li>{{ item.name }}</li>
+ {% endfor %}
+</ol>
+
+<p>See all {{ libraries }} add-on matches for <q>{{ query }}</q></p>
+{% endblock %}
+
View
6 apps/search/urls.py
@@ -0,0 +1,6 @@
+from django.conf.urls.defaults import url, patterns
+
+urlpatterns = patterns('search.views',
+ url(r'^$', 'aggregate', name='search.aggregate'),
+ url(r'^(?P<type>addons|library)/$', 'search', name='search'),
+)
View
35 apps/search/views.py
@@ -0,0 +1,35 @@
+from django.shortcuts import render_to_response
+from django.template import RequestContext
+
+from pyes import facets, query
+
+from search.utils import get_es
+
+
+def render(request, template, data={}):
+ return render_to_response(template, data, RequestContext(request))
+
+
+def _get_facets(response):
+ facets = response['facets']
+ type_facets = dict(((z['term'], z['count']) for z in
+ facets['_type']['terms']))
+ return type_facets['addon'], type_facets['library']
+
+
+def aggregate(request):
+ """This aggregates the first 5 results from add-ons and libraries."""
+ # Query add-on, library facet and use the facet values.
+ q = request.GET.get('q')
+ es = get_es()
+ s = query.Search(query.StringQuery(q))
+ s.facet.add_term_facet('_type')
+ r = es.search(s, 'flightdeck')
+ addon_total, library_total = _get_facets(r)
+ data = dict(addon_total=addon_total, library_total=library_total)
+ return render(request, 'search/aggregate.html', data)
+
+
+def search(request, type):
+ """This is a search into either addons or libraries."""
+ pass
View
2  settings.py
@@ -243,7 +243,7 @@
# FLIGHTDECK APPS
'base', # basic flightdeck things (utils, urls)
'person', # user related stuff (profile etc.)
- 'search', # ElasticSearch and related stuff.
+ 'search', # ElasticSearch and search views.
'amo', # currently addons.mozilla.org authentication
'jetpack', # Jetpack functionality
'xpi', # XPI management
View
10 urls.py
@@ -5,10 +5,7 @@
from base import views as base_views
-urls = [
- # home
- url(r'^$', base_views.homepage, name='home'),
- ]
+urls = [url(r'^$', base_views.homepage, name='home')]
if settings.DEBUG:
@@ -30,13 +27,12 @@
# API Browser
(r'^api/', include('api.urls')),
- # Tutorial
(r'^tutorial/', include('tutorial.urls')),
- # Person
(r'^user/', include('person.urls')),
- # Jetpack
+ (r'^search/', include('search.urls')),
+
(r'', include('jetpack.urls')),
# Monitor
2  vendor
@@ -1 +1 @@
-Subproject commit f398377d0dcdd0e7278215006fc7bc7a31e13267
+Subproject commit 94d382bcb6791b1b73a129a8f34f65e4dd593dd6
Please sign in to comment.
Something went wrong with that request. Please try again.