简体   繁体   中英

Mysql search, match words if similar

I have a db with a table called sections. In that is a field called head that has a full text index with 3 entries each a string. 2 entries have the word motorcycle and one has motorcycles. I can't seem to find a way to return all 3 if the term "motorcycles" is search.

I have tried

SELECT * FROM sections
     WHERE MATCH (head) AGAINST ('Motorcycles')

but it only returns the plural entry. I have also tried.

SELECT * FROM sections
   WHERE head like '%motorcycles%'

but that also only returns the plural entry. Is there a way to return all three rows based on "motorcycles"?

Have you tried boolean mode?

where match (head) against ('+ Motorcycle*' in Boolean mode)

More information is here .

Your where clause has an extra "s":

 SELECT * FROM sections WHERE head like '%motorcycle%'

Assuming your question is more general than the specific motorcylce example you've given...I'm not aware of a way that you can relax the contraints directly in the SQL (without a stored proc to pre process the input). I'd suggest pre processing your input with a regex to remove/replace the chars that make the word plural. Then use like in the way that you have shown on the singular version of the word.

If i have got your Questions correctly I think you want something like this:

if (SELECT count(1) FROM sections WHERE head like '%motorcycles%')>1
begin
    select * FROM selections
     WHERE head like '%motorcycle%'
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM