表 [tbl_post] 具有 id,description [long_text] 。
description 字段具有以下值:
Hi how r u? #TravelingtheWorld #TravelingtheWorld
Hi how r u? #Traveled
bla bla bla travelbybus blah blah
blah blah blah @travelegency blah blah
the intelligence demonstrated in during tests iterations
blah blah blah testing blahh
blah blah blah tested blahh
我们有 @ 和#功能。
如果我尝试搜索值" test",我需要"测试/测试/测试"
的响应SELECT SUBSTRING_INDEX(CONCAT(
'$ipstring',
SUBSTRING_INDEX(LOWER('description'), LOWER('$ipstring'), -1)
) , ' ',1 ) AS 'mystring'
FROM tbl_post
WHERE `description` LIKE '$ipstring%'
OR `description` LIKE '% $ipstring%'
OR `description` LIKE '%#$ipstring%'
OR `description` LIKE '%@$ipstring%'
输入搜索字符串
$ipstring = "travel"
这里我得到输出
输入搜索字符串
$ipstring = "te"
这里有输出
查询:
首次查询
SELECT SUBSTRING_INDEX ( CONCAT(
'travel',
SUBSTRING_INDEX(LOWER('Hi how r u? *TravelingtheWorld *TravelingtheWorld'), LOWER('travel'), -1 )
) , ' ',1 ) AS 'mystring'
第二次查询
SELECT SUBSTRING_INDEX ( CONCAT(
'te',
SUBSTRING_INDEX(LOWER('the intelligence demonstrated in during tests iterations'), LOWER('te'), -1 )
) , ' ',1 ) AS 'mystring'
如果我添加空格" "在输入字符串"之前te",我将得到"测试"
SELECT SUBSTRING_INDEX ( CONCAT(
'te',
SUBSTRING_INDEX(LOWER('the intelligence demonstrated in during tests iterations'), LOWER(' te'), -1 )
) , ' ',1 ) AS 'mystring'
但是对于第一个查询:如果我添加一个空格" "在输入字符串之前'行进'
SELECT SUBSTRING_INDEX ( CONCAT(
'travel',
SUBSTRING_INDEX(LOWER('Hi how r u? *TravelingtheWorld *TravelingtheWorld'), LOWER(' travel'), -1 )
) , ' ',1 ) AS 'mystring'
......我没有得到" TravelingtheWorld"
答案 0 :(得分:0)
我建议这个查询:
select *
from (
select description,
substring_index(
substr(
description,
instr(
concat(
' ',
replace(
replace(lower(description), '@', ' '),
'#',
' '
),
' '
),
' travel'
)
),
' ',
1
) as extract
from tbl_post
) as m
where length(m.extract) > 0
您必须提供带有前缀空格的' te'
或' travel'
等搜索字词。