资源表使用全文索引替换like查询

This commit is contained in:
wangliwen 2022-06-27 15:44:18 +08:00
parent 6a784f705c
commit f967285913
2 changed files with 44 additions and 33 deletions

View File

@ -3,4 +3,7 @@ alter table`tb_resource_car` ADD INDEX `resourceid`(`resource_id`) USING BTREE c
alter table `tb_resource_score` ADD INDEX `resourceid`(`resource_id`) USING BTREE comment '评分的资源id';
alter table `tb_resource_browse` ADD INDEX `resourceid`(`resource_id`) USING BTREE comment '资源id索引';
alter table `t_ability_application` ADD INDEX `resourceid`(`resource_id`) USING BTREE comment '资源id';
alter table `t_ability_application` ADD INDEX `userId`(`user_id`) USING BTREE comment '用户';
alter table `t_ability_application` ADD INDEX `userId`(`user_id`) USING BTREE comment '用户';
alter table `tb_data_resource` ADD FULLTEXT INDEX `type`(`type`);
alter table `tb_data_attr` ADD FULLTEXT INDEX `attr_value`(`attr_value`);
alter table `tb_data_resource` ADD FULLTEXT INDEX `name`(`name`);

View File

@ -133,10 +133,12 @@
WHERE 1 = 1
AND tdr.del_flag = 0
<if test="dto.type != null and dto.type != ''">
AND tdr.type LIKE CONCAT('%',#{dto.type},'%')
AND MATCH (tdr.type) AGAINST ( #{dto.type} IN BOOLEAN MODE)
<!--AND tdr.type LIKE CONCAT('%',#{dto.type},'%') -->
</if>
<if test="dto.name != null and dto.name != ''">
AND tdr.name LIKE CONCAT('%',#{dto.name},'%')
<!-- AND tdr.name LIKE CONCAT('%',#{dto.name},'%') -->
AND MATCH (tdr.name) AGAINST ( #{dto.name} IN BOOLEAN MODE)
</if>
<if test="dto.districtId != null and dto.districtId != ''">
AND tdr.district_id = #{dto.districtId}
@ -163,7 +165,8 @@
<foreach collection="dto.infoList" item="item" separator="union all">
SELECT data_resource_id FROM tb_data_attr
WHERE attr_type = #{item.attrType}
AND attr_value LIKE CONCAT('%', #{item.attrValue}, '%')
<!-- AND attr_value LIKE CONCAT('%', #{item.attrValue}, '%') -->
AND MATCH ( attr_value) AGAINST ( #{item.attrValue} IN BOOLEAN MODE)
AND del_flag = 0
</foreach>) tb
GROUP BY tb.data_resource_id
@ -207,10 +210,12 @@
1 = 1
AND tdr.del_flag = 0
<if test="type != null and type != ''">
AND tdr.type LIKE CONCAT('%',#{type},'%')
<!-- AND tdr.type LIKE CONCAT('%',#{type},'%') -->
AND MATCH (tdr.type) AGAINST ( #{type} IN BOOLEAN MODE)
</if>
<if test="name != null and name != ''">
AND tdr.name LIKE CONCAT('%',#{name},'%')
<!--AND tdr.name LIKE CONCAT('%',#{name},'%') -->
AND MATCH (tdr.name) AGAINST ( #{name} IN BOOLEAN MODE)
</if>
ORDER BY ${orderFiled} ${orderType}
LIMIT ${pageNum}, ${pageSize}
@ -313,7 +318,8 @@
WHERE 1 = 1
AND tdr.del_flag = 0
<if test="dto.name != null and dto.name != ''">
AND tdr.name LIKE CONCAT('%',#{dto.name},'%')
AND MATCH (tdr.name) AGAINST ( #{dto.name} IN BOOLEAN MODE)
<!--AND tdr.name LIKE CONCAT('%',#{dto.name},'%') -->
</if>
<if test="dto.type != null and dto.type != ''">
AND tdr.type = #{dto.type}
@ -879,7 +885,8 @@
AND tdr.del_flag = 0
AND tda.del_flag = 0
AND tdr.id = tda.data_resource_id
AND attr_value LIKE CONCAT('%', #{type}, '%')
AND MATCH (attr_value) AGAINST ( #{type} IN BOOLEAN MODE)
<!-- AND attr_value LIKE CONCAT('%', #{type}, '%') -->
</select>
<select id="selectAppAreaCountList" resultType="java.util.Map">
@ -900,35 +907,36 @@
</select>
<select id="applicationAreaCapabilitySet" parameterType="java.util.Map" resultType="java.util.Map">
SELECT
SUBSTRING_INDEX( SUBSTRING_INDEX( tdav.attr_value, ';', b.help_topic_id + 1 ), ';',- 1 ) AS type ,
COUNT( tdav.data_resource_id ) AS total
SUBSTRING_INDEX( SUBSTRING_INDEX( tdav.attr_value, ';', b.help_topic_id + 1 ), ';',- 1 ) AS type ,
COUNT( tdav.data_resource_id ) AS total
FROM
tb_data_attr tdav
JOIN mysql.help_topic b ON b.help_topic_id &lt; ( LENGTH( tdav.attr_value ) - LENGTH( REPLACE ( tdav.attr_value,
';', '' ) ) + 1 )
tb_data_attr tdav
JOIN mysql.help_topic b ON b.help_topic_id &lt; ( LENGTH( tdav.attr_value ) - LENGTH( REPLACE ( tdav.attr_value,
';', '' ) ) + 1 )
WHERE
1 = 1
AND tdav.attr_type = '应用领域'
AND tdav.del_flag = 0
AND SUBSTRING_INDEX( SUBSTRING_INDEX( tdav.attr_value, ';', b.help_topic_id + 1 ), ';',- 1 ) != ''
1 = 1
AND tdav.attr_type = '应用领域'
AND tdav.del_flag = 0
AND SUBSTRING_INDEX( SUBSTRING_INDEX( tdav.attr_value, ';', b.help_topic_id + 1 ), ';',- 1 ) != ''
GROUP BY
type
type
</select>
<select id="applicationAreaCapabilityList" parameterType="java.util.Map" resultType="java.util.Map">
SELECT
SUBSTRING_INDEX( SUBSTRING_INDEX( tdav.attr_value, ';', b.help_topic_id + 1 ), ';',- 1 ) AS type ,
COUNT( tdav.data_resource_id ) AS total
SUBSTRING_INDEX( SUBSTRING_INDEX( tdav.attr_value, ';', b.help_topic_id + 1 ), ';',- 1 ) AS type ,
COUNT( tdav.data_resource_id ) AS total
FROM
(select a.* from tb_data_attr a inner join tb_data_resource c on a.data_resource_id = c.id where c.type = #{resourceType} AND c.dept_id = #{id} ) tdav
JOIN mysql.help_topic b ON b.help_topic_id &lt; ( LENGTH( tdav.attr_value ) - LENGTH( REPLACE ( tdav.attr_value,
';', '' ) ) + 1 )
(select a.* from tb_data_attr a inner join tb_data_resource c on a.data_resource_id = c.id where c.type =
#{resourceType} AND c.dept_id = #{id} ) tdav
JOIN mysql.help_topic b ON b.help_topic_id &lt; ( LENGTH( tdav.attr_value ) - LENGTH( REPLACE ( tdav.attr_value,
';', '' ) ) + 1 )
WHERE
1 = 1
AND tdav.attr_type = '应用领域'
AND tdav.del_flag = 0
AND SUBSTRING_INDEX( SUBSTRING_INDEX( tdav.attr_value, ';', b.help_topic_id + 1 ), ';',- 1 ) != ''
1 = 1
AND tdav.attr_type = '应用领域'
AND tdav.del_flag = 0
AND SUBSTRING_INDEX( SUBSTRING_INDEX( tdav.attr_value, ';', b.help_topic_id + 1 ), ';',- 1 ) != ''
GROUP BY
type
type
</select>
@ -973,9 +981,9 @@
<select id="selectResourceNumAsType" parameterType="java.util.Map" resultType="java.util.Map">
SELECT COUNT(b.id) AS resourceNum,
a.id AS deptId,
a.name AS deptName,
SUM(b.visits) AS visits
a.id AS deptId,
a.name AS deptName,
SUM(b.visits) AS visits
FROM
sys_dept a
INNER JOIN
@ -1058,7 +1066,7 @@
WHERE
a.del_flag = 0
<if test="id != null and id != ''">
and b.dept_id = #{id}
and b.dept_id = #{id}
</if>
<if test="resourceType != null and resourceType != ''">
AND b.type = #{resourceType}
@ -1067,7 +1075,7 @@
<select id="selectResourceShare" parameterType="java.util.Map" resultType="integer">
SELECT COUNT(id) AS nums
FROM
tb_data_resource
tb_data_resource
WHERE
del_flag = 0
<if test="id != null and id != ''">