mysql中的子字符串需要获取单词

mysql中的子字符串需要获取单词,mysql,sql,Mysql,Sql,表[tbl_post]具有id、说明[长文本] “说明”字段具有以下值: 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 b

表[tbl_post]具有id、说明[长文本]

“说明”字段具有以下值:

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”,我需要“test/tested/testing”的响应

  • 输入搜索字符串

    $ipstring = "travel"
    
    $ipstring = "te"
    
    这里我得到了输出

    • 旅行
    • 周游世界
    • 旅游巴士
    • 旅行性
  • 输入搜索字符串

    $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”之前添加一个空格“”,我将得到“tests”

    但对于第一个查询:如果我在输入字符串“traveling”之前添加一个空格“”

        SELECT SUBSTRING_INDEX ( CONCAT(
                   'travel',
                   SUBSTRING_INDEX(LOWER('Hi how r u? *TravelingtheWorld *TravelingtheWorld'), LOWER(' travel'), -1 )
               ) , ' ',1 ) AS 'mystring' 
    

    。。。我没有得到“世界旅行”

    我建议这个查询:

    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'

    我看到
    $ipstring
    :您使用PHP吗?如果是这样,PHP解决方案是否适合您?是的,我们使用的是PHP Mysql,但我们需要在单个查询中输出Mysql,而不是PHP。提前感谢,即使您有一个PHP函数,它会将一个查询结果集作为参数,并对其进行修改并再次返回,您也不会这样做吗?在纯MySql中,这将是一个可怕的代码,我担心效率会更低。@Pradeepandrewson,这解决了你的问题吗?你能给我一些反馈吗?