Beispiel #1
0
    def get_query(self, query=''):
        """
        processes the search query and renders the results in a dict
        """
        query = query.replace('%', '').replace('_', '')
        suite = request.args.get("suite") or ""
        suite = suite.lower()
        if suite == "all":
            suite = ""
        # if suite is not specified
        if not suite:
            try:
                exact_matching = qry.get_pkg_by_name(session, query)

                other_results = qry.get_pkg_by_similar_name(session, query)
            except Exception as e:
                raise Http500Error(e)  # db problem, ...
        else:
            try:
                exact_matching = qry.get_pkg_by_name(session, query, suite)

                other_results = qry.get_pkg_by_similar_name(
                    session, query, suite)
            except Exception as e:
                raise Http500Error(e)  # db problem, ...

        if exact_matching is not None:
            exact_matching = exact_matching.to_dict()
        if other_results is not None:
            other_results = [o.to_dict() for o in other_results]
            # we exclude the 'exact' matching from other_results:
            other_results = [x for x in other_results if x != exact_matching]

        results = dict(exact=exact_matching, other=other_results)
        return dict(results=results, query=query, suite=suite)
Beispiel #2
0
    def get_query(self, query=''):
        """
        processes the search query and renders the results in a dict
        """
        query = query.replace('%', '').replace('_', '')
        suite = request.args.get("suite") or ""
        suite = suite.lower()
        if suite == "all":
            suite = ""

        try:
            exact_matching = qry.get_pkg_by_name(session, query, suite)

            other_results = qry.get_pkg_by_similar_name(session,
                                                        query, suite)
        except Exception as e:
            raise Http500Error(e)  # db problem, ...

        if exact_matching is not None:
            exact_matching = exact_matching.to_dict()
        if other_results is not None:
            other_results = [o.to_dict() for o in other_results]
            # we exclude the 'exact' matching from other_results:
            other_results = [x for x in other_results if x != exact_matching]

        results = dict(exact=exact_matching,
                       other=other_results)
        return dict(results=results, query=query, suite=suite)