Example #1
0
    def process_request(self,
                        query,
                        addon_type='ALL',
                        limit=10,
                        platform='ALL',
                        version=None,
                        compat_mode='strict'):
        """
        Query the search backend and serve up the XML.
        """
        if not waffle.switch_is_active('new-api-search'):
            return self._sphinx_api_search(query, addon_type, limit, platform,
                                           version, compat_mode)

        limit = min(MAX_LIMIT, int(limit))

        filters = {
            'app': self.request.APP.id,
            'status__in': amo.REVIEWED_STATUSES,
            'is_disabled': False,
            'has_version': True,
        }

        # Opts may get overridden by query string filters.
        opts = {
            'addon_type': addon_type,
            'platform': platform,
            'version': version,
        }

        if self.version < 1.5:
            # By default we show public addons only for api_version < 1.5.
            filters['status__in'] = [amo.STATUS_PUBLIC]

            # Fix doubly encoded query strings.
            try:
                query = urllib.unquote(query.encode('ascii'))
            except UnicodeEncodeError:
                # This fails if the string is already UTF-8.
                pass

        query, qs_filters = extract_filters(query, filters['app'], opts)

        qs = Addon.search().query(or_=name_query(query))
        filters.update(qs_filters)
        qs = qs.filter(**filters)

        return self.render('api/search.xml', {
            'using_ES': True,
            'results': qs[:limit],
            'total': qs.count(),
        })
Example #2
0
    def process_request(self, query, addon_type='ALL', limit=10,
                        platform='ALL', version=None, compat_mode='strict'):
        """
        Query the search backend and serve up the XML.
        """
        if not waffle.flag_is_active(self.request, 'new-api-search'):
            return self._sphinx_api_search(query, addon_type, limit, platform,
                                           version, compat_mode)

        limit = min(MAX_LIMIT, int(limit))

        filters = {
            'app': self.request.APP.id,
            'status__in': amo.REVIEWED_STATUSES,
            'is_disabled': False,
            'has_version': True,
        }

        # Opts may get overridden by query string filters.
        opts = {
            'addon_type': addon_type,
            'platform': platform,
            'version': version,
        }

        if self.version < 1.5:
            # By default we show public addons only for api_version < 1.5.
            filters['status__in'] = [amo.STATUS_PUBLIC]

            # Fix doubly encoded query strings.
            try:
                query = urllib.unquote(query.encode('ascii'))
            except UnicodeEncodeError:
                # This fails if the string is already UTF-8.
                pass

        query, qs_filters = extract_filters(query, filters['app'], opts)

        qs = Addon.search().query(or_=name_query(query))
        filters.update(qs_filters)
        if 'type' not in filters:
            # Filter by ALL types, which is really all types except for apps.
            filters['type__in'] = list(amo.ADDON_SEARCH_TYPES)
        qs = qs.filter(**filters)

        return self.render('api/search.xml', {
            'results': qs[:limit],
            'total': qs.count(),
        })
Example #3
0
    def process_request(self, query, addon_type="ALL", limit=10, platform="ALL", version=None, compat_mode="strict"):
        """
        Query the search backend and serve up the XML.
        """
        if not waffle.switch_is_active("new-api-search"):
            return self._sphinx_api_search(query, addon_type, limit, platform, version, compat_mode)

        limit = min(MAX_LIMIT, int(limit))

        filters = {
            "app": self.request.APP.id,
            "status__in": amo.REVIEWED_STATUSES,
            "is_disabled": False,
            "has_version": True,
        }

        # Opts may get overridden by query string filters.
        opts = {"addon_type": addon_type, "platform": platform, "version": version}

        if self.version < 1.5:
            # By default we show public addons only for api_version < 1.5.
            filters["status__in"] = [amo.STATUS_PUBLIC]

            # Fix doubly encoded query strings.
            try:
                query = urllib.unquote(query.encode("ascii"))
            except UnicodeEncodeError:
                # This fails if the string is already UTF-8.
                pass

        query, qs_filters = extract_filters(query, filters["app"], opts)

        qs = Addon.search().query(or_=name_query(query))
        filters.update(qs_filters)
        qs = qs.filter(**filters)

        return self.render("api/search.xml", {"results": qs[:limit], "total": qs.count()})
Example #4
0
    def process_request(self, query, addon_type='ALL', limit=10,
                        platform='ALL', version=None, compat_mode='strict'):
        """
        Query the search backend and serve up the XML.
        """
        limit = min(MAX_LIMIT, int(limit))
        app_id = self.request.APP.id

        filters = {
            'app': app_id,
            'status__in': amo.REVIEWED_STATUSES,
            'is_disabled': False,
            'has_version': True,
        }

        # Opts may get overridden by query string filters.
        opts = {
            'addon_type': addon_type,
            'platform': platform,
            'version': version,
        }

        if self.version < 1.5:
            # By default we show public addons only for api_version < 1.5.
            filters['status__in'] = [amo.STATUS_PUBLIC]

            # Fix doubly encoded query strings.
            try:
                query = urllib.unquote(query.encode('ascii'))
            except UnicodeEncodeError:
                # This fails if the string is already UTF-8.
                pass

        query, qs_filters = extract_filters(query, filters['app'], opts)

        qs = Addon.search().query(or_=name_query(query))
        filters.update(qs_filters)
        if 'type' not in filters:
            # Filter by ALL types, which is really all types except for apps.
            filters['type__in'] = list(amo.get_addon_search_types())
        qs = qs.filter(**filters)

        addons = qs[:limit]
        total = qs.count()

        if waffle.switch_is_active('d2c-api-search'):
            is_d2c = True
            results = []
            for addon in qs:
                compat_version = addon.compatible_version(app_id, version,
                                                          platform,
                                                          compat_mode)
                if compat_version:
                    addon.compat_version = compat_version
                    results.append(addon)
                    if len(results) == limit:
                        break
                else:
                    # We're excluding this addon because there are no
                    # compatible versions. Decrement the total.
                    total -= 1
        else:
            is_d2c = False
            results = addons

        return self.render('api/search.xml', {
            'is_d2c': is_d2c,
            'results': results,
            'total': total,
            # For caching
            'version': version,
            'compat_mode': compat_mode,
        })
Example #5
0
    def process_request(self, query, addon_type='ALL', limit=10,
                        platform='ALL', version=None, compat_mode='strict'):
        """
        Query the search backend and serve up the XML.
        """
        limit = min(MAX_LIMIT, int(limit))
        app_id = self.request.APP.id

        filters = {
            'app': app_id,
            'status': amo.STATUS_PUBLIC,
            'is_disabled': False,
            'has_version': True,
        }

        # Opts may get overridden by query string filters.
        opts = {
            'addon_type': addon_type,
            'platform': platform,
            'version': version,
        }

        if self.version < 1.5:
            # By default we show public addons only for api_version < 1.5.
            filters['status__in'] = [amo.STATUS_PUBLIC]

            # Fix doubly encoded query strings.
            try:
                query = urllib.unquote(query.encode('ascii'))
            except UnicodeEncodeError:
                # This fails if the string is already UTF-8.
                pass

        query, qs_filters = extract_filters(query, filters['app'], opts)

        qs = Addon.search().query(or_=name_query(query))
        filters.update(qs_filters)
        if 'type' not in filters:
            # Filter by ALL types, which is really all types except for apps.
            filters['type__in'] = list(amo.ADDON_SEARCH_TYPES)
        qs = qs.filter(**filters)

        if qs_filters.get('platform__in', []):
            # More than one platform, pluck it out.
            platforms = qs_filters.get('platform__in')[:]
            platforms.remove(1)  # ALL is already queried in compat SQL.
            if platforms:
                platform = amo.PLATFORMS[platforms[0]].api_name

        addons = qs[:limit]
        total = qs.count()

        results = []
        for addon in qs:
            compat_version = addon.compatible_version(app_id, version,
                                                      platform, compat_mode)
            if compat_version:
                addon.compat_version = compat_version
                results.append(addon)
                if len(results) == limit:
                    break
            else:
                # We're excluding this addon because there are no
                # compatible versions. Decrement the total.
                total -= 1

        return self.render('api/search.xml', {
            'results': results,
            'total': total,
            # For caching
            'version': version,
            'compat_mode': compat_mode,
        })
Example #6
0
    def process_request(self, query, addon_type='ALL', limit=10,
                        platform='ALL', version=None, compat_mode='strict'):
        """
        Query the search backend and serve up the XML.
        """
        limit = min(MAX_LIMIT, int(limit))
        app_id = self.request.APP.id

        # We currently filter for status=PUBLIC for all versions. If
        # that changes, the contract for API version 1.5 requires
        # that we continue filtering for it there.
        filters = {
            'app': app_id,
            'status': amo.STATUS_PUBLIC,
            'is_disabled': False,
            'has_version': True,
        }

        # Opts may get overridden by query string filters.
        opts = {
            'addon_type': addon_type,
            'version': version,
        }
        # Specific case for Personas (bug 990768): if we search providing the
        # Persona addon type (9), don't filter on the platform as Personas
        # don't have compatible platforms to filter on.
        if addon_type != '9':
            opts['platform'] = platform

        if self.version < 1.5:
            # Fix doubly encoded query strings.
            try:
                query = urllib.unquote(query.encode('ascii'))
            except UnicodeEncodeError:
                # This fails if the string is already UTF-8.
                pass

        query, qs_filters, params = extract_filters(query, opts)

        qs = Addon.search().query(or_=name_query(query))
        filters.update(qs_filters)
        if 'type' not in filters:
            # Filter by ALL types, which is really all types except for apps.
            filters['type__in'] = list(amo.ADDON_SEARCH_TYPES)
        qs = qs.filter(**filters)

        qs = qs[:limit]
        total = qs.count()

        results = []
        for addon in qs:
            compat_version = addon.compatible_version(app_id,
                                                      params['version'],
                                                      params['platform'],
                                                      compat_mode)
            # Specific case for Personas (bug 990768): if we search providing
            # the Persona addon type (9), then don't look for a compatible
            # version.
            if compat_version or addon_type == '9':
                addon.compat_version = compat_version
                results.append(addon)
                if len(results) == limit:
                    break
            else:
                # We're excluding this addon because there are no
                # compatible versions. Decrement the total.
                total -= 1

        return self.render('api/search.xml', {
            'results': results,
            'total': total,
            # For caching
            'version': version,
            'compat_mode': compat_mode,
        })
Example #7
0
    def process_request(self,
                        query,
                        addon_type='ALL',
                        limit=10,
                        platform='ALL',
                        version=None,
                        compat_mode='strict'):
        """
        Query the search backend and serve up the XML.
        """
        limit = min(MAX_LIMIT, int(limit))
        app_id = self.request.APP.id

        filters = {
            'app': app_id,
            'status__in': amo.REVIEWED_STATUSES,
            'is_disabled': False,
            'has_version': True,
        }

        # Opts may get overridden by query string filters.
        opts = {
            'addon_type': addon_type,
            'platform': platform,
            'version': version,
        }

        if self.version < 1.5:
            # By default we show public addons only for api_version < 1.5.
            filters['status__in'] = [amo.STATUS_PUBLIC]

            # Fix doubly encoded query strings.
            try:
                query = urllib.unquote(query.encode('ascii'))
            except UnicodeEncodeError:
                # This fails if the string is already UTF-8.
                pass

        query, qs_filters = extract_filters(query, filters['app'], opts)

        qs = Addon.search().query(or_=name_query(query))
        filters.update(qs_filters)
        if 'type' not in filters:
            # Filter by ALL types, which is really all types except for apps.
            filters['type__in'] = list(amo.ADDON_SEARCH_TYPES)
        qs = qs.filter(**filters)

        addons = qs[:limit]
        total = qs.count()

        if waffle.switch_is_active('d2c-api-search'):
            is_d2c = True
            results = []
            for addon in qs:
                compat_version = addon.compatible_version(
                    app_id, version, platform, compat_mode)
                if compat_version:
                    addon.compat_version = compat_version
                    results.append(addon)
                    if len(results) == limit:
                        break
                else:
                    # We're excluding this addon because there are no
                    # compatible versions. Decrement the total.
                    total -= 1
        else:
            is_d2c = False
            results = addons

        return self.render(
            'api/search.xml',
            {
                'is_d2c': is_d2c,
                'results': results,
                'total': total,
                # For caching
                'version': version,
                'compat_mode': compat_mode,
            })
Example #8
0
    def process_request(self, query, addon_type="ALL", limit=10, platform="ALL", version=None, compat_mode="strict"):
        """
        Query the search backend and serve up the XML.
        """
        limit = min(MAX_LIMIT, int(limit))
        app_id = self.request.APP.id

        filters = {"app": app_id, "status__in": amo.REVIEWED_STATUSES, "is_disabled": False, "has_version": True}

        # Opts may get overridden by query string filters.
        opts = {"addon_type": addon_type, "platform": platform, "version": version}

        if self.version < 1.5:
            # By default we show public addons only for api_version < 1.5.
            filters["status__in"] = [amo.STATUS_PUBLIC]

            # Fix doubly encoded query strings.
            try:
                query = urllib.unquote(query.encode("ascii"))
            except UnicodeEncodeError:
                # This fails if the string is already UTF-8.
                pass

        query, qs_filters = extract_filters(query, filters["app"], opts)

        qs = Addon.search().query(or_=name_query(query))
        filters.update(qs_filters)
        if "type" not in filters:
            # Filter by ALL types, which is really all types except for apps.
            filters["type__in"] = list(amo.ADDON_SEARCH_TYPES)
        qs = qs.filter(**filters)

        addons = qs[:limit]
        total = qs.count()

        if waffle.switch_is_active("d2c-api-search"):
            is_d2c = True
            results = []
            for addon in qs:
                compat_version = addon.compatible_version(app_id, version, platform, compat_mode)
                if compat_version:
                    addon.compat_version = compat_version
                    results.append(addon)
                    if len(results) == limit:
                        break
                else:
                    # We're excluding this addon because there are no
                    # compatible versions. Decrement the total.
                    total -= 1
        else:
            is_d2c = False
            results = addons

        return self.render(
            "api/search.xml",
            {
                "is_d2c": is_d2c,
                "results": results,
                "total": total,
                # For caching
                "version": version,
                "compat_mode": compat_mode,
            },
        )