Esempio n. 1
0
def get_search(args):
    query = args.get("q", None)
    results = search(query, db.session)

    data = {}
    for key, values in results.items():
        if len(values) > 0:
            data[key] = [obj.jsonify() for obj in values]

    return jsonify(data)
Esempio n. 2
0
def get_search(args):
    query = args.get('q', None)
    results = search(query, db.session)

    data = {}
    for key, values in results.items():
        if len(values) > 0:
            data[key] = [obj.jsonify() for obj in values]

    return jsonify(data)
Esempio n. 3
0
def get_search(depth=1):
    query = request.query.q
    if not query:
        raise bottle.abort(400, "Query parameter is required")

    results = search.search(query, request.session)

    # if accepted type was */* or json then we always return json
    response.content_type = "; ".join((mimetype.json, "charset=utf8"))

    data = {}
    for key, values in results.items():
        if len(values) > 0:
            data[key] = [obj.json() for obj in values]
    return data
Esempio n. 4
0
 def search(self, text):
     """
     search the database using text
     """
     # set the text in the entry even though in most cases the entry already
     # has the same text in it, this is in case this method was called from
     # outside the class so the entry and search results match
     logger.debug('SearchView.search(%s)' % text)
     error_msg = None
     error_details_msg = None
     self.session.close()
     # create a new session for each search...maybe we shouldn't
     # even have session as a class attribute
     self.session = db.Session()
     bold = '<b>%s</b>'
     results = []
     try:
         results = search.search(text, self.session)
     except ParseException, err:
         error_msg = _('Error in search string at column %s') % err.column
Esempio n. 5
0
 def search(self, text):
     """
     search the database using text
     """
     # set the text in the entry even though in most cases the entry already
     # has the same text in it, this is in case this method was called from
     # outside the class so the entry and search results match
     logger.debug('SearchView.search(%s)' % text)
     error_msg = None
     error_details_msg = None
     self.session.close()
     # create a new session for each search...maybe we shouldn't
     # even have session as a class attribute
     self.session = db.Session()
     bold = '<b>%s</b>'
     results = []
     try:
         results = search.search(text, self.session)
     except ParseException, err:
         error_msg = _('Error in search string at column %s') % err.column
Esempio n. 6
0
def index(args, ext=None):
    query = args.get("q", None)
    results = search(query, db.session) if query is not None else {}

    data = {}

    if request.prefers_json:
        value_factory = lambda k, v: [obj.jsonify() for obj in v]
        response_factory = lambda d: utils.json_response(d)
    else:
        value_factory = lambda k, v: [
            {"url": result_resource_map.get(key).format(obj.id), "str": obj.str()} for obj in v
        ]
        response_factory = lambda d: render_template("search/index.html", results=d)

    for key, values in results.items():
        if len(values) > 0:
            data[key] = value_factory(key, values)

    return response_factory(data)
Esempio n. 7
0
def index(args, ext=None):
    query = args.get('q', None)
    results = search(query, db.session) if query is not None else {}

    data = {}

    if request.prefers_json:
        value_factory = lambda k, v: [obj.jsonify() for obj in v]
        response_factory = lambda d: utils.json_response(d)
    else:
        value_factory = lambda k, v: [{
            'url': result_resource_map.get(key).format(obj.id),
            'str': obj.str()
        } for obj in v]
        response_factory = lambda d: render_template('search/index.html', results=d)

    for key, values in results.items():
        if len(values) > 0:
            data[key] = value_factory(key, values)

    return response_factory(data)