Is it possible to search for whole given word in Full text search of mysql

前提是你 提交于 2020-01-17 04:26:39

问题


I am using Full Text Search with mysql on 3 columns. Assume data like:

  1. Row1 contain two columns with 'Greater Noida Expressway' and 'Sector 91'.
  2. Row2 contain two columns with 'Ho Chi Minh Marg' and 'Greater Kailash 2'.
  3. Row3 contain two columns with 'Rohini' and 'Sector 91'

Now, if I query with

SELECT * FROM trafficker.traffics WHERE MATCH (column1, column2) AGAINST ('Greater Noida'); 

Above query will result me first two rows as matching will be done on 'Greater' and 'Noida'. And 'Greater' will also be found in 'Greater Kailash' of Row2 :|

Is there any way I can block the search on 'space' and consider Greater Noida as one search phrase and not separated by 'space'??

This will be very useful as it will help me in filtering the noise as actual data is going to be very huge..

Thanks in advance!

Edit: Another problem is that if I search for Sector 91. It will only search for Sector and will ignore 91(as this is less than four characters). Is there any way to resolve this other than downloading the source code and compiling the same. Because I am sure it won't work on shared server :(


回答1:


Check the 'in boolean mode' option:

http://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html

You can wrap the words in quotes, like:

SELECT * FROM trafficker.traffics WHERE MATCH (column1, column2) AGAINST ('"Greater Noida"' IN BOOLEAN MODE); 

That should get you close to what you want.




回答2:


we can define priority of search by adding + and - before seach phrase in boolean mode

  • including that word
  • Excluding that word For Eg

    SELECT * FROM trafficker.traffics WHERE MATCH (column1, column2) AGAINST ('"+mobile -nokia"' IN BOOLEAN MODE);



来源:https://stackoverflow.com/questions/12281763/is-it-possible-to-search-for-whole-given-word-in-full-text-search-of-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!