bug 589944, Using addons index for ajax search.

This commit is contained in:
Dave Dash 2010-08-25 10:38:19 -07:00
Родитель 4655c11ee5
Коммит 871eadeee3
3 изменённых файлов: 17 добавлений и 34 удалений

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

@ -561,36 +561,6 @@ class Client(object):
return manual_order(Tag.objects.all(), tag_ids)
class AddonsPersonasClient(Client):
"""Search client that queries both personas and addons."""
def query(self, term, limit=10, offset=0, **kwargs):
sc = self.sphinx
sc.SetSelect('addon_id')
sc.SetLimits(min(offset, SPHINX_HARD_LIMIT - 1), limit)
term = sanitize_query(term)
self.log_query(term)
try:
result = sc.Query(term, 'personas, addons')
except socket.timeout:
log.error("Query has timed out.")
raise SearchError("Query has timed out.")
except Exception, e:
log.error("Sphinx threw an unknown exception: %s" % e)
raise SearchError("Sphinx threw an unknown exception.")
if sc.GetLastError():
raise SearchError(sc.GetLastError())
self.total_found = result['total_found'] if result else 0
if result and result['total']:
return self.get_result_set(term, result, offset, limit)
else:
return []
class PersonasClient(Client):
"""A search client that queries sphinx for Personas."""

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

@ -258,13 +258,27 @@ class AjaxTest(SphinxTestCase):
for val, expected in check_me:
check(val, expected)
@patch('search.client.AddonsPersonasClient.query')
@patch('search.client.Client.query')
def test_errors(self, searchclient):
searchclient.side_effect = SearchError()
r = self.client.get(reverse('search.ajax') + '?q=del')
eq_('[]', r.content)
class AjaxDisabledAddonsTest(SphinxTestCase):
fixtures = ('base/addon_3615',)
def setUp(self):
a = Addon.objects.get(pk=3615)
a.status = amo.STATUS_DISABLED
a.save()
super(AjaxDisabledAddonsTest, self).setUp()
def test_json(self):
r = self.client.get(reverse('search.ajax') + '?q=del')
eq_('[]', r.content)
class TagTest(SphinxTestCase):
fixtures = ('base/apps', 'addons/persona',)

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

@ -15,8 +15,7 @@ from addons.models import Category
from versions.compare import dict_from_int, version_int
from search import forms
from search.client import (Client as SearchClient, SearchError,
CollectionsClient, AddonsPersonasClient,
PersonasClient)
CollectionsClient, PersonasClient)
from search.forms import SearchForm, SecondarySearchForm
from translations.query import order_by_translation
@ -232,7 +231,7 @@ def ajax_search(request):
"""
q = request.GET.get('q', '')
client = AddonsPersonasClient()
client = SearchClient()
try:
results = client.query(q, limit=10)
return [dict(id=result.id, label=unicode(result.name),