<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="cn.reghao.tnb.content.app.vod.db.mapper.SearchRecordMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into vod_search_record
        (`id`,`deleted`,`create_time`,`update_time`,`user_id`,`keyword`)
        values 
        (#{id},#{deleted},#{createTime},#{updateTime},#{userId},#{keyword})
    </insert>

    <select id="findHotSearch" resultType="cn.reghao.tnb.content.app.vod.model.vo.HotSearch">
        select keyword,count(*) as rank
        from vod_search_record
        group by keyword
        order by rank desc
        limit 10
    </select>
    <select id="findSuggestKeyword" resultType="cn.reghao.tnb.content.app.vod.model.vo.SuggestKeyword">
        select id as rank,keyword
        from vod_search_record
        where keyword like concat('%',#{keyword},'%')
        limit 5
    </select>
</mapper>
