Skip to content
Permalink
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/client.py
  2. +9 −9 apps/search/views.py
@@ -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.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."""

@@ -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 versions.compare import dict_from_int, version_int
from search import forms
from search.client import (Client as SearchClient, SearchError,
CollectionsClient, PersonasClient)
CollectionsClient, AddonsPersonasClient,
PersonasClient)
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)


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

q = request.GET.get('q', '')
client = SearchClient()
client = AddonsPersonasClient()
try:
results = client.query(q, limit=10)
items = [dict(id=result.id, label=unicode(result.name),
icon=result.icon_url, value=unicode(result.name).lower())
for result in results]
return [dict(id=result.id, label=unicode(result.name),
icon=result.icon_url, value=unicode(result.name).lower())
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.