Skip to content
Browse files

bug 585207, blended persona search.

  • Loading branch information...
davedash committed Aug 6, 2010
1 parent d4e0e3f commit 933d6ca4071ae5e58049247693f7b539e9630871
Showing with 40 additions and 9 deletions.
  1. +31 −0 apps/search/
  2. +9 −9 apps/search/
@@ -548,6 +548,37 @@ def _tags_meta(self, results, **kwargs):
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.SetLimits(min(offset, SPHINX_HARD_LIMIT - 1), limit)
term = sanitize_query(term)

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)
return []

class PersonasClient(Client):
"""A search client that queries sphinx for Personas."""

@@ -9,13 +9,15 @@
from tower import ugettext as _

import amo
from amo.decorators import json_view
from amo.helpers import urlparams
from amo import urlresolvers
from addons.models import Category
from import dict_from_int, version_int
from search import forms
from search.client import (Client as SearchClient, SearchError,
CollectionsClient, PersonasClient)
CollectionsClient, AddonsPersonasClient,
from search.forms import SearchForm, SecondarySearchForm
from translations.query import order_by_translation

@@ -217,7 +219,7 @@ def _collections(request):

return jingo.render(request, 'search/collections.html', c)

def ajax_search(request):
""" Returns a json feed of ten results for auto-complete used in
@@ -228,16 +230,14 @@ def ajax_search(request):

q = request.GET.get('q', '')
client = SearchClient()
client = AddonsPersonasClient()
results = client.query(q, limit=10)
items = [dict(, label=unicode(,
icon=result.icon_url, value=unicode(
for result in results]
return [dict(, label=unicode(,
icon=result.icon_url, value=unicode(
for result in results]
except SearchError:
items = []

return HttpResponse(json.dumps(items), mimetype='application/json')
return []

def search(request, tag_name=None):

0 comments on commit 933d6ca

Please sign in to comment.
You can’t perform that action at this time.