turn off sphinx for /search and /tag (bug 692945)

This commit is contained in:
Jeff Balogh 2011-10-12 12:51:14 -07:00
Родитель 42974f9fb6
Коммит dc2fee53f9
7 изменённых файлов: 87 добавлений и 238 удалений

Просмотреть файл

@ -1,88 +0,0 @@
{% extends "impala/base.html" %}
{% block search_form %}
{% with search_url = url('search.es_search') %}
{% include 'impala/search.html' %}
{% endwith %}
{% endblock %}
{% if query.q %}
{# L10n: {0} is a search term, such as Firebug. #}
{% set title = _('{0} :: Search')|f(query.q) %}
{# L10n: {0} is a search term, such as Firebug. #}
{% set heading = _('Search Results for "{0}"')|f(query.q) %}
{% else %}
{% set title = _('Search') %}
{% set heading = title %}
{% endif %}
{% block title %}
{{ page_title(title) }}
{% endblock %}
{% block extrahead %}
<meta name="WT.oss" content="{{ query.q }}">
<meta name="WT.oss_r" content="{{ pager.paginator.count }}">
{% endblock %}
{% macro facet(title, links) %}
<li class="facet">
<h3>{{ title }}</h3>
{{ facet_links(links) }}
</li>
{% endmacro %}
{% macro facet_links(links) %}
<ul>
{% for link in links recursive %}
<li{% if link.selected %} class="selected"{% endif %}>
<a href="{{ request.get_full_path()|urlparams(page=None, **link.urlparams) }}">
{{ link.text }}</a>
{% if link.children %}
<ul>{{ loop(link.children) }}</ul>
{% endif %}
</li>
{% endfor %}
</ul>
{% endmacro %}
{% block content %}
<section id="search-facets" class="secondary" role="complementary">
<h2>{{ _('Filter Results') }}</h2>
<ul class="facets island">
{{ facet(_('Category'), categories) }}
<li class="facet">
<h3>{{ _('Works with') }}</h3>
{% if versions %}
{{ facet_links(versions) }}
{% endif %}
{% if platforms %}
{{ facet_links(platforms) }}
{% endif %}
</li>
{{ facet(_('Tag'), tags) }}
</ul>
<p>{{ _('{0} matching results')|f(pager.paginator.count|numberfmt) }}</p>
</section>
<section class="primary" role="main">
<div class="listing results island hero c">
<h1>{{ heading }}</h1>
{{ impala_addon_listing_header(
request.get_full_path()|urlparams(page=None),
sort_opts, query.sort, extra_sort_opts) }}
{% if pager.object_list %}
<div class="items">
{{ impala_addon_listing_items(pager.object_list, field=query.sort,
src='search') }}
</div>
{{ pager|impala_paginator }}
{% else %}
{% include 'search/no_results.html' %}
{% endif %}
</div>
</section>
{% endblock %}

Просмотреть файл

@ -1,66 +1,86 @@
{% extends "base.html" %}
{% extends "impala/base.html" %}
{% block search_form %}
{% include 'impala/search.html' %}
{% endblock %}
{% if query.q %}
{# L10n: {0} is a search term, such as Firebug. #}
{% set title = _('{0} :: Search')|f(query.q) %}
{# L10n: {0} is a search term, such as Firebug. #}
{% set heading = _('Search Results for "{0}"')|f(query.q) %}
{% else %}
{% set title = _('Search') %}
{% set heading = title %}
{% endif %}
{% block title %}
{% if query %}
{{ page_title(_('Add-on Search Results for {0}')|f(query)) }}
{% else %}
{{ page_title(_('Add-on Search Results')) }}
{% endif %}
{{ page_title(title) }}
{% endblock %}
{% block extrahead %}
<meta name="WT.oss" content="{{ query }}">
<meta name="WT.oss" content="{{ query.q }}">
<meta name="WT.oss_r" content="{{ pager.paginator.count }}">
{% endblock %}
{% macro facet(title, links) %}
<li class="facet">
<h3>{{ title }}</h3>
{{ facet_links(links) }}
</li>
{% endmacro %}
{% macro facet_links(links) %}
<ul>
{% for link in links recursive %}
<li{% if link.selected %} class="selected"{% endif %}>
<a href="{{ request.get_full_path()|urlparams(page=None, **link.urlparams) }}">
{{ link.text }}</a>
{% if link.children %}
<ul>{{ loop(link.children) }}</ul>
{% endif %}
</li>
{% endfor %}
</ul>
{% endmacro %}
{% block content %}
<section class="primary" role="main">
<header class="results-head">
{{ breadcrumbs([(None, _('Search'))]) }}
<h2>{{ _('Search Results') }}</h2>
<h3 class="results-count">{{ showing(query, tag, pager) }}</h3>
{% if sort == 'name' %}
{# L10n: {0} is the name of the current locale. #}
<p><em>{{ _('Sorting by name includes only {0}
results.')|f(settings.LANGUAGES.get(LANG.lower())) }}</em></p>
{% endif %}
</header>
<div class="listing results">
{% if pager.object_list %}
<div class="results-inner">
<div class="listing-header">
<ul title="{{ _('Sort results by&hellip;')|safe }}">
{% for item in sort_tabs %}
{% include 'includes/refinement.html' %}
{% endfor %}
</ul>
</div>
{{ addon_listing_items(pager.object_list, show_date=sort, src='search',
show_downloads=sort=='weeklydownloads') }}
</div>
<div class="listing-footer">
{{ pager|paginator }}
</div>
{% else %}
{% include 'search/no_results.html' %}
{% endif %}
</div>
<section id="search-facets" class="secondary" role="complementary">
<h2>{{ _('Filter Results') }}</h2>
<ul class="facets island">
{{ facet(_('Category'), categories) }}
<li class="facet">
<h3>{{ _('Works with') }}</h3>
{% if versions %}
{{ facet_links(versions) }}
{% endif %}
{% if platforms %}
{{ facet_links(platforms) }}
{% endif %}
</li>
{{ facet(_('Tag'), tags) }}
</ul>
<p>{{ _('{0} matching results')|f(pager.paginator.count|numberfmt) }}</p>
</section>
<section class="secondary" role="complementary">
<div id="refine-results" class="highlight">
<h3>{{ _('Refine Results') }}</h3>
{{ refinements(categories, _('Categories'), 'category') }}
{{ refinements(versions, _('Compatible with'), 'compatibility') }}
{{ refinements(platforms, _('Platforms'), 'platform') }}
{{ refinements(tags, _('Tags'), 'tags') }}
<section class="primary" role="main">
<div class="listing results island hero c">
<h1>{{ heading }}</h1>
{{ impala_addon_listing_header(
request.get_full_path()|urlparams(page=None),
sort_opts, query.sort, extra_sort_opts) }}
{% if pager.object_list %}
<div class="items">
{{ impala_addon_listing_items(pager.object_list, field=query.sort,
src='search') }}
</div>
{{ pager|impala_paginator }}
{% else %}
{% include 'search/no_results.html' %}
{% endif %}
</div>
</section>
{% endblock %}

Просмотреть файл

@ -108,8 +108,13 @@ class TestSearchboxTarget(amo.tests.TestCase):
class TestESSearch(amo.tests.ESTestCase):
@classmethod
def setUpClass(cls):
super(TestESSearch, cls).setUpClass()
cls.setUpIndex()
def test_legacy_redirects(self):
base = reverse('search.es_search')
base = reverse('search.search')
r = self.client.get(base + '?sort=averagerating')
self.assertRedirects(r, base + '?sort=rating', status_code=301)
@ -123,7 +128,7 @@ class TestESSearch(amo.tests.ESTestCase):
eq_(len(data), len(addons))
for got, expected in zip(data, addons):
eq_(got['id'], expected.id)
eq_(int(got['id']), expected.id)
eq_(got['name'], unicode(expected.name))
eq_(got['url'], expected.get_url_path())
eq_(got['icon'], expected.icon_url)
@ -226,10 +231,10 @@ class TestWebappSearch(amo.tests.ESTestCase):
def test_get(self):
r = self.client.get(self.url)
eq_(r.status_code, 200)
self.assertTemplateUsed(r, 'search/es_results.html')
self.assertTemplateUsed(r, 'search/results.html')
@amo.tests.mobile_test
def test_mobile_get(self):
r = self.client.get(self.url)
eq_(r.status_code, 200)
self.assertTemplateUsed(r, 'search/mobile/es_results.html')
self.assertTemplateUsed(r, 'search/mobile/results.html')

Просмотреть файл

@ -4,9 +4,8 @@ from . import views
urlpatterns = patterns('',
url('^$', views.search, name='search.search'),
url('^(?:es)?$', views.search, name='search.search'),
url('^ajax$', views.ajax_search, name='search.ajax'),
url('^suggestions$', views.ajax_search_suggestions,
name='search.suggestions'),
url('^es$', views.es_search, name='search.es_search'),
)

Просмотреть файл

@ -7,7 +7,6 @@ from django.utils.encoding import smart_str
import commonware.log
import jingo
import waffle
from tower import ugettext as _
from mobility.decorators import mobile_template
@ -393,7 +392,7 @@ def name_query(q):
return dict(more, **name_only_query(q))
@mobile_template('search/{mobile/}es_results.html')
@mobile_template('search/{mobile/}results.html')
def app_search(request, template=None):
form = ESSearchForm(request.GET or {}, type=amo.ADDON_WEBAPP)
form.is_valid() # Let the form try to clean data.
@ -430,8 +429,8 @@ def app_search(request, template=None):
return jingo.render(request, template, ctx)
@mobile_template('search/{mobile/}es_results.html')
def es_search(request, tag_name=None, template=None):
@mobile_template('search/{mobile/}results.html')
def search(request, tag_name=None, template=None):
APP = request.APP
types = (amo.ADDON_EXTENSION, amo.ADDON_THEME, amo.ADDON_DICT,
amo.ADDON_SEARCH, amo.ADDON_LPAPP)
@ -463,8 +462,8 @@ def es_search(request, tag_name=None, template=None):
categories={'terms': {'field': 'category', 'size': 100}}))
if query.get('q'):
qs = qs.query(or_=name_query(query['q']))
if query.get('tag'):
qs = qs.filter(tag=query['tag'])
if tag_name or query.get('tag'):
qs = qs.filter(tag=tag_name or query['tag'])
if query.get('platform') and query['platform'] in amo.PLATFORM_DICT:
ps = (amo.PLATFORM_DICT[query['platform']].id, amo.PLATFORM_ALL.id)
qs = qs.filter(platform__in=ps)
@ -518,93 +517,6 @@ def es_search(request, tag_name=None, template=None):
return jingo.render(request, template, ctx)
@mobile_template('search/{mobile/}results.html')
def search(request, tag_name=None, template=None):
# Redirect to search/es if this isn't mobile or a /tag page and waffle
# gives us the thumbs up.
if (not request.MOBILE and not tag_name
and waffle.sample_is_active('elastic-search')):
url = reverse('search.es_search') + '?' + request.GET.urlencode()
return redirect(url)
# If the form is invalid we still want to have a query.
query = request.REQUEST.get('q', '')
search_opts = {
'meta': ('versions', 'categories', 'tags', 'platforms'),
'version': None,
}
form = SearchForm(request)
form.is_valid() # Let the form try to clean data.
category = form.cleaned_data.get('cat')
if category == 'collections':
return _collections(request)
elif category == 'personas':
return _personas(request)
# TODO: Let's change the form values to something less gross when
# Remora dies in a fire.
query = form.cleaned_data['q']
addon_type = form.cleaned_data.get('atype', 0)
tag = tag_name if tag_name is not None else form.cleaned_data.get('tag')
if tag_name:
search_opts['show_personas'] = True
page = form.cleaned_data['page']
sort = form.cleaned_data.get('sort')
search_opts['version'] = form.cleaned_data.get('lver')
search_opts['limit'] = form.cleaned_data.get('pp', DEFAULT_NUM_RESULTS)
search_opts['platform'] = form.cleaned_data.get('pid', amo.PLATFORM_ALL)
search_opts['sort'] = sort
search_opts['app'] = request.APP.id
search_opts['offset'] = (page - 1) * search_opts['limit']
if category:
search_opts['category'] = category
elif addon_type:
search_opts['type'] = addon_type
search_opts['tag'] = tag
client = SearchClient()
try:
results = client.query(query, **search_opts)
except SearchError, e:
log.error('Sphinx Error: %s' % e)
return jingo.render(request, 'search/down.html', locals(), status=503)
version_filters = client.meta['versions']
# If we are filtering by a version, make sure we explicitly list it.
if search_opts['version']:
try:
version_filters += (version_int(search_opts['version']),)
except UnicodeEncodeError:
pass # We didn't want to list you anyway.
versions = _get_versions(request, client.meta['versions'],
search_opts['version'])
categories = _get_categories(request, client.meta['categories'],
addon_type, category)
tags = _get_tags(request, client.meta['tags'], tag)
platforms = _get_platforms(request, client.meta['platforms'],
search_opts['platform'])
sort_tabs = _get_sorts(request, sort)
sort_opts = _get_sort_menu(request, sort)
pager = amo.utils.paginate(request, results, search_opts['limit'])
context = dict(pager=pager, query=query, tag=tag, platforms=platforms,
versions=versions, categories=categories, tags=tags,
sort_tabs=sort_tabs, sort_opts=sort_opts, sort=sort)
return jingo.render(request, template, context)
class FacetLink(object):
def __init__(self, text, urlparams, selected=False, children=None):

Просмотреть файл

@ -0,0 +1 @@
DELETE FROM waffle_sample WHERE name = 'elastic-search';

Просмотреть файл

@ -1,5 +1,5 @@
{% set search_form = SimpleSearchForm(request, search_cat) %}
<form id="search" action="{{ search_url|default(url('search.search')) }}">
<form id="search" action="{{ url('search.search') }}">
<input id="search-q" type="text" name="q" required autocomplete="off" title=""
class="text {% if not search_form.q.data %}placeholder{% endif %}"
placeholder="{{ search_form.placeholder() }}"