Permalink
Browse files

TMP

  • Loading branch information...
davedash committed Mar 15, 2011
1 parent 4435d96 commit 721b1b2073066d3006c815b7a50518ea94f45844
Showing with 73 additions and 9 deletions.
  1. +27 −0 apps/search/templates/search/aggregate.html
  2. +6 −0 apps/search/urls.py
  3. +35 −0 apps/search/views.py
  4. +1 −1 settings.py
  5. +3 −7 urls.py
  6. +1 −1 vendor
@@ -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
@@ -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
@@ -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
@@ -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

0 comments on commit 721b1b2

Please sign in to comment.