<?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="com.quinn.mapper.FindMapper">

    <select id="countListFinds" resultType="int">
        select count(1) from (
        select 1 from qn_source a
        where a.source_name like CONCAT('%',#{findWhat},'%')
        or a.content_json like CONCAT('%',#{findWhat},'%')
		union all
        select 1 from qn_blog b
        where b.title like CONCAT('%',#{findWhat},'%')
        or b.content_json like CONCAT('%',#{findWhat},'%')
        ) t
    </select>

    <select id="listFinds" resultType="com.quinn.pojo.FindResult">
        select * from (
        select a.sid as topicId,'SOURCE' as category,a.gmt_create as gmtCreate,a.source_name as topicName,a.content_json as contentText  from qn_source a
        where a.source_name like CONCAT('%',#{findWhat},'%')
        or a.content_json like CONCAT('%',#{findWhat},'%')
		union all
        select b.bid as topicId,'BLOG' as category,b.gmt_create as gmtCreate,b.title as topicName,b.content_json as contentText from qn_blog b
        where b.title like CONCAT('%',#{findWhat},'%')
        or b.content_json like CONCAT('%',#{findWhat},'%')
        ) t order by gmtCreate
        limit #{myPageParam.pageNum},#{myPageParam.size}
    </select>

</mapper>
