• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python db.to_tsquery函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中taiga.base.utils.db.to_tsquery函数的典型用法代码示例。如果您正苦于以下问题:Python to_tsquery函数的具体用法?Python to_tsquery怎么用?Python to_tsquery使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了to_tsquery函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: filter_queryset

    def filter_queryset(self, request, queryset, view):
        # NOTE: See migtration 0033_text_search_indexes
        q = request.QUERY_PARAMS.get('q', None)
        if q:
            tsquery = "to_tsquery('english_nostop', %s)"
            tsquery_params = [to_tsquery(q)]
            tsvector = """
                 setweight(to_tsvector('english_nostop',
                                       coalesce(projects_project.name, '')), 'A') ||
                 setweight(to_tsvector('english_nostop',
                                       coalesce(inmutable_array_to_string(projects_project.tags), '')), 'B') ||
                 setweight(to_tsvector('english_nostop',
                                       coalesce(projects_project.description, '')), 'C')
            """

            select = {
                "rank": "ts_rank({tsvector},{tsquery})".format(tsquery=tsquery,
                                                               tsvector=tsvector),
            }
            select_params = tsquery_params
            where = ["{tsvector} @@ {tsquery}".format(tsquery=tsquery,
                                                      tsvector=tsvector),]
            params = tsquery_params
            order_by = ["-rank", ]

            queryset = queryset.extra(select=select,
                                      select_params=select_params,
                                      where=where,
                                      params=params,
                                      order_by=order_by)
        return queryset
开发者ID:74Labs,项目名称:taiga-back,代码行数:31,代码来源:filters.py


示例2: _search_by_query

def _search_by_query(queryset, tsquery, tsvector, text):
    select = {
        "rank": "ts_rank({tsvector},{tsquery})".format(tsquery=tsquery,
                                                       tsvector=tsvector),
    }
    order_by = ["-rank", ]
    where = ["{tsvector} @@ {tsquery}".format(tsquery=tsquery,
                                              tsvector=tsvector), ]

    if text:
        queryset = queryset.extra(select=select,
                                  select_params=[to_tsquery(text)],
                                  where=where,
                                  params=[to_tsquery(text)],
                                  order_by=order_by)

    queryset = attach_total_points(queryset)
    return queryset[:MAX_RESULTS]
开发者ID:0-T-0,项目名称:taiga-back,代码行数:18,代码来源:services.py


示例3: search_wiki_pages

def search_wiki_pages(project, text):
    model_cls = apps.get_model("wiki", "WikiPage")
    where_clause = ("to_tsvector('english_nostop', coalesce(wiki_wikipage.slug) || ' ' || "
                                "coalesce(wiki_wikipage.content, '')) "
                    "@@ to_tsquery('english_nostop', %s)")

    if text:
        return (model_cls.objects.extra(where=[where_clause], params=[to_tsquery(text)])
                                 .filter(project_id=project.pk)[:MAX_RESULTS])

    return model_cls.objects.filter(project_id=project.pk)[:MAX_RESULTS]
开发者ID:cubettech,项目名称:taiga-back,代码行数:11,代码来源:services.py


示例4: search_issues

def search_issues(project, text):
    model_cls = apps.get_model("issues", "Issue")
    where_clause = ("to_tsvector('english_nostop', coalesce(issues_issue.subject) || ' ' || "
                    "coalesce(issues_issue.ref) || ' ' || "
                    "coalesce(issues_issue.description, '')) @@ to_tsquery('english_nostop', %s)")

    if text:
        return (model_cls.objects.extra(where=[where_clause], params=[to_tsquery(text)])
                                 .filter(project_id=project.pk)[:MAX_RESULTS])

    return model_cls.objects.filter(project_id=project.pk)[:MAX_RESULTS]
开发者ID:cubettech,项目名称:taiga-back,代码行数:11,代码来源:services.py


示例5: filter_queryset

    def filter_queryset(self, request, queryset, view):
        q = request.QUERY_PARAMS.get('q', None)
        if q:
            table = queryset.model._meta.db_table
            where_clause = ("to_tsvector('english_nostop', coalesce({table}.subject, '') || ' ' || "
                            "coalesce({table}.ref) || ' ' || "
                            "coalesce({table}.description, '')) @@ to_tsquery('english_nostop', %s)".format(table=table))

            queryset = queryset.extra(where=[where_clause], params=[to_tsquery(q)])

        return queryset
开发者ID:spetpet,项目名称:taiga-back,代码行数:11,代码来源:filters.py


示例6: filter_queryset

    def filter_queryset(self, request, queryset, view):
        q = request.QUERY_PARAMS.get('q', None)
        if q:
            table = queryset.model._meta.db_table
            where_clause = ("""
                to_tsvector('simple',
                            coalesce({table}.subject, '') || ' ' ||
                            coalesce(array_to_string({table}.tags, ' '), '') || ' ' ||
                            coalesce({table}.ref) || ' ' ||
                            coalesce({table}.description, '')) @@ to_tsquery('simple', %s)
            """.format(table=table))

            queryset = queryset.extra(where=[where_clause], params=[to_tsquery(q)])

        return queryset
开发者ID:sj1980,项目名称:taiga-back,代码行数:15,代码来源:filters.py


示例7: get_voted_list

def get_voted_list(for_user, from_user, type=None, q=None):
    filters_sql = ""
    and_needed = False

    if type:
        filters_sql += " AND type = %(type)s "

    if q:
        filters_sql += """ AND (
            to_tsvector('english_nostop', coalesce(subject,'') || ' ' ||coalesce(entities.name,'') || ' ' ||coalesce(to_char(ref, '999'),'')) @@ to_tsquery('english_nostop', %(q)s)
        )
        """

    sql = """
    -- BEGIN Basic info: we need to mix info from different tables and denormalize it
    SELECT entities.*,
           projects_project.name as project_name, projects_project.description as description, projects_project.slug as project_slug, projects_project.is_private as project_is_private,
           projects_project.blocked_code as project_blocked_code, projects_project.tags_colors, projects_project.logo,
           users_user.username assigned_to_username, users_user.full_name assigned_to_full_name, users_user.photo assigned_to_photo, users_user.email assigned_to_email
        FROM (
            {userstories_sql}
            UNION
            {tasks_sql}
            UNION
            {issues_sql}
        ) as entities
    -- END Basic info

    -- BEGIN Project info
    LEFT JOIN projects_project
        ON (entities.project = projects_project.id)
    -- END Project info

    -- BEGIN Assigned to user info
    LEFT JOIN users_user
        ON (assigned_to = users_user.id)
    -- END Assigned to user info

    -- BEGIN Permissions checking
    LEFT JOIN projects_membership
        -- Here we check the memberbships from the user requesting the info
        ON (projects_membership.user_id = {from_user_id} AND projects_membership.project_id = entities.project)

    LEFT JOIN users_role
        ON (entities.project = users_role.project_id AND users_role.id =  projects_membership.role_id)

    WHERE
        -- public project
        (
            projects_project.is_private = false
            OR(
                -- private project where the view_ permission is included in the user role for that project or in the anon permissions
                projects_project.is_private = true
                AND(
                    (entities.type = 'issue' AND 'view_issues' = ANY (array_cat(users_role.permissions, projects_project.anon_permissions)))
                    OR (entities.type = 'task' AND 'view_tasks' = ANY (array_cat(users_role.permissions, projects_project.anon_permissions)))
                    OR (entities.type = 'userstory' AND 'view_us' = ANY (array_cat(users_role.permissions, projects_project.anon_permissions)))
                )
        ))
    -- END Permissions checking
        {filters_sql}

    ORDER BY entities.created_date DESC;
    """

    from_user_id = -1
    if not from_user.is_anonymous():
        from_user_id = from_user.id

    sql = sql.format(
        for_user_id=for_user.id,
        from_user_id=from_user_id,
        filters_sql=filters_sql,
        userstories_sql=_build_sql_for_type(for_user, "userstory", "userstories_userstory", "votes_vote", slug_column="null"),
        tasks_sql=_build_sql_for_type(for_user, "task", "tasks_task", "votes_vote", slug_column="null"),
        issues_sql=_build_sql_for_type(for_user, "issue", "issues_issue", "votes_vote", slug_column="null"))

    cursor = connection.cursor()
    params = {
        "type": type,
        "q": to_tsquery(q) if q is not None else ""
    }
    cursor.execute(sql, params)

    desc = cursor.description
    return [
        dict(zip([col[0] for col in desc], row))
        for row in cursor.fetchall()
    ]
开发者ID:CrypticGator,项目名称:taiga-back,代码行数:89,代码来源:services.py


示例8: test_to_tsquery

def test_to_tsquery():
    for (input, expected) in TS_QUERY_TRANSFORMATIONS:
        expected = re.sub("([0-9])", r"'\1':*", expected)
        actual = to_tsquery(input)
        assert actual == expected
开发者ID:spetpet,项目名称:taiga-back,代码行数:5,代码来源:test_utils.py


示例9: get_liked_list

def get_liked_list(for_user, from_user, type=None, q=None):
    filters_sql = ""
    and_needed = False

    if type:
        filters_sql += " AND type = '{type}' ".format(type=type)

    if q:
        filters_sql += """ AND (
            to_tsvector('english_nostop', coalesce(subject,'') || ' ' ||coalesce(entities.name,'') || ' ' ||coalesce(to_char(ref, '999'),'')) @@ to_tsquery('english_nostop', '{q}')
        )
        """.format(q=to_tsquery(q))

    sql = """
    -- BEGIN Basic info: we need to mix info from different tables and denormalize it
    SELECT entities.*,
           projects_project.name as project_name, projects_project.description as description, projects_project.slug as project_slug, projects_project.is_private as project_is_private,
           projects_project.tags_colors,
           users_user.username assigned_to_username, users_user.full_name assigned_to_full_name, users_user.photo assigned_to_photo, users_user.email assigned_to_email
        FROM (
            {projects_sql}
        ) as entities
    -- END Basic info

    -- BEGIN Project info
    LEFT JOIN projects_project
        ON (entities.project = projects_project.id)
    -- END Project info

    -- BEGIN Assigned to user info
    LEFT JOIN users_user
        ON (assigned_to = users_user.id)
    -- END Assigned to user info

    -- BEGIN Permissions checking
    LEFT JOIN projects_membership
        -- Here we check the memberbships from the user requesting the info
        ON (projects_membership.user_id = {from_user_id} AND projects_membership.project_id = entities.project)

    LEFT JOIN users_role
        ON (entities.project = users_role.project_id AND users_role.id =  projects_membership.role_id)

    WHERE
        -- public project
        (
            projects_project.is_private = false
            OR(
                -- private project where the view_ permission is included in the user role for that project or in the anon permissions
                projects_project.is_private = true
                AND(
                    'view_project' = ANY (array_cat(users_role.permissions, projects_project.anon_permissions))
                )
        ))
    -- END Permissions checking
        {filters_sql}

    ORDER BY entities.created_date DESC;
    """

    from_user_id = -1
    if not from_user.is_anonymous():
        from_user_id = from_user.id

    sql = sql.format(
        for_user_id=for_user.id,
        from_user_id=from_user_id,
        filters_sql=filters_sql,
        projects_sql=_build_liked_sql_for_projects(for_user))

    cursor = connection.cursor()
    cursor.execute(sql)

    desc = cursor.description
    return [
        dict(zip([col[0] for col in desc], row))
        for row in cursor.fetchall()
    ]
开发者ID:ndjido,项目名称:taiga-back,代码行数:77,代码来源:services.py



注:本文中的taiga.base.utils.db.to_tsquery函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python dicts.dict_sum函数代码示例发布时间:2022-05-27
下一篇:
Python db.save_in_bulk函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap