~bac/charmworld/bug-1257878

« back to all changes in this revision

Viewing changes to charmworld/views/search.py

  • Committer: Tarmac
  • Author(s): Brad Crittenden
  • Date: 2013-11-15 20:11:46 UTC
  • mfrom: (461.2.4 fix-search-api)
  • Revision ID: tarmac-20131115201146-5agh31m3xiimpnc7
Handle api_searchs with ~user

Treat them as a search "owner: user" as we do in the in-site search.
Also don't puke if special characters in the user-entered search
cause an ElasticHttpError.

https://codereview.appspot.com/23330046/

R=gary.

Approved by Juju Gui Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
from pyramid.httpexceptions import HTTPFound
5
5
from pyramid.renderers import render_to_response
6
6
from pyramid.view import view_config
7
 
import re
8
7
 
9
8
from charmworld.search import (
10
9
    IndexNotReady,
15
14
 
16
15
def do_search(request):
17
16
    text = request.params["search_text"]
18
 
    # If the user has a token beginning with tilde then we assume they want to
19
 
    terms = text.split()
20
 
    terms = [re.sub('^~', 'owner:', term) for term in terms]
21
 
    text = ' '.join(terms)
22
17
    return request.index_client.search(text)
23
18
 
24
19