コード例 #1
0
    def filter_queryset(self, request, queryset, view):
        locale = request.GET.get('locale', None)
        if '*' == locale:
            return queryset

        sq = queryset.to_dict().pop('query', query.MatchAll().to_dict())

        if request.LANGUAGE_CODE == settings.LANGUAGE_CODE:
            locales = [request.LANGUAGE_CODE]
        else:
            locales = [request.LANGUAGE_CODE, settings.LANGUAGE_CODE]

        positive_sq = {
            'filtered': {
                'query': sq,
                'filter': {'terms': {'locale': locales}}
            }
        }
        negative_sq = {
            'bool': {
                'must_not': [
                    {'term': {'locale': request.LANGUAGE_CODE}}
                ]
            }
        }
        # Note: Here we are replacing the query rather than calling
        # `queryset.query` which would result in a boolean must query.
        queryset.query = query.Boosting(positive=positive_sq,
                                        negative=negative_sq,
                                        negative_boost=0.5)
        return queryset
コード例 #2
0
    def filter_queryset(self, request, queryset, view):
        locale = request.GET.get("locale", None)
        if "*" == locale:
            return queryset

        sq = queryset.to_dict().pop("query", query.MatchAll().to_dict())

        if request.LANGUAGE_CODE == settings.LANGUAGE_CODE:
            locales = [request.LANGUAGE_CODE]
        else:
            locales = [request.LANGUAGE_CODE, settings.LANGUAGE_CODE]

        positive_sq = {
            "bool": {
                "must": sq,
                "filter": {
                    "terms": {
                        "locale": locales
                    }
                }
            }
        }
        negative_sq = {
            "bool": {
                "must_not": [{
                    "term": {
                        "locale": request.LANGUAGE_CODE
                    }
                }]
            }
        }
        # Note: Here we are replacing the query rather than calling
        # `queryset.query` which would result in a boolean must query.
        queryset.query = query.Boosting(positive=positive_sq,
                                        negative=negative_sq,
                                        negative_boost=0.5)
        return queryset
コード例 #3
0
def _get_games_search_query(q: str) -> esq.Q:
    return esq.Boosting(
        positive=esq.MultiMatch(query=q) & esq.Match(isPublic=True),
        negative=_ALL_SEATS_FILLED_QUERY,
        negative_boost=0.5,
    )