From 721b1b2073066d3006c815b7a50518ea94f45844 Mon Sep 17 00:00:00 2001 From: Dave Dash Date: Tue, 15 Mar 2011 13:49:46 -0700 Subject: [PATCH 1/2] TMP --- apps/search/templates/search/aggregate.html | 27 ++++++++++++++++ apps/search/urls.py | 6 ++++ apps/search/views.py | 35 +++++++++++++++++++++ settings.py | 2 +- urls.py | 10 ++---- vendor | 2 +- 6 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 apps/search/templates/search/aggregate.html create mode 100644 apps/search/urls.py create mode 100644 apps/search/views.py diff --git a/apps/search/templates/search/aggregate.html b/apps/search/templates/search/aggregate.html new file mode 100644 index 00000000..068a595b --- /dev/null +++ b/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 %} +

Add-on Matches ({{ addon_total }})

+ +
    + {% for item in addons %} +
  1. {{ item.name }}
  2. + {% endfor %} +
+ +

See all {{ addons_total }} add-on matches for {{ query }}

+ +

Library Matches ({{ library_total }})

+ +
    + {% for item in libraries %} +
  1. {{ item.name }}
  2. + {% endfor %} +
+ +

See all {{ libraries }} add-on matches for {{ query }}

+{% endblock %} + diff --git a/apps/search/urls.py b/apps/search/urls.py new file mode 100644 index 00000000..583488a1 --- /dev/null +++ b/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'^(?Paddons|library)/$', 'search', name='search'), +) diff --git a/apps/search/views.py b/apps/search/views.py new file mode 100644 index 00000000..f8b4f1c8 --- /dev/null +++ b/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 diff --git a/settings.py b/settings.py index f59e9585..c009a3fd 100644 --- a/settings.py +++ b/settings.py @@ -243,7 +243,7 @@ INSTALLED_APPS = [ # 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 diff --git a/urls.py b/urls.py index ef8c6ea9..d70ebf76 100644 --- a/urls.py +++ b/urls.py @@ -5,10 +5,7 @@ from django.conf import settings 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 @@ urls.extend([ # 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 diff --git a/vendor b/vendor index f398377d..94d382bc 160000 --- a/vendor +++ b/vendor @@ -1 +1 @@ -Subproject commit f398377d0dcdd0e7278215006fc7bc7a31e13267 +Subproject commit 94d382bcb6791b1b73a129a8f34f65e4dd593dd6 From d5612f619d4a0b09882ac0ca1e40941f1efcb62e Mon Sep 17 00:00:00 2001 From: Dave Dash Date: Wed, 23 Mar 2011 20:53:37 -0700 Subject: [PATCH 2/2] Remove dump_curl --- apps/search/utils.py | 2 +- vendor | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/search/utils.py b/apps/search/utils.py index 62c1c2a7..f5021c3b 100644 --- a/apps/search/utils.py +++ b/apps/search/utils.py @@ -9,5 +9,5 @@ def get_es(): """Return one es object.""" global _es if not _es: - _es = ES(settings.ES_HOSTS, default_indexes=[settings.ES_INDEX], dump_curl="/tmp/t") + _es = ES(settings.ES_HOSTS, default_indexes=[settings.ES_INDEX]) return _es diff --git a/vendor b/vendor index 94d382bc..f398377d 160000 --- a/vendor +++ b/vendor @@ -1 +1 @@ -Subproject commit 94d382bcb6791b1b73a129a8f34f65e4dd593dd6 +Subproject commit f398377d0dcdd0e7278215006fc7bc7a31e13267