How to get MySQL to treat the underscore as a word delimiter for full-text search?

I use MySQL fulltext and PHP (codeigniter) to search for a database containing RSS elements. The problem is that some of these elements use underscores instead of spaces. Because MySQL considers underscores as part of a word, these elements will never be matched in a search unless the user types the exact title, including underscores.

The server is shared, so I do not have access to the MySQL Server system variables.

Can this behavior be changed in any other way? Perhaps this can be done using the search query itself?

I know that I could just replace all underscore characters in the database with spaces, but this could jeopardize the original integrity of these names. Just wondering if there is another way to do this.

+3
source share
2 answers

I know that I could just replace all underscore characters in the database with spaces, but this could jeopardize the original integrity of these names. Just wondering if there is another way to do this.

Instead of replacing the underscore in the original title field, you can use a separate field dedicated to full-text search.

This allows you to replace underscores and fill in keywords in this field (category names, authors, tags, etc.) to increase the relevance of search results. We have used this many times with success to get rid of HTML tags in search output content.

+1

, . , - , - mySQL ( " '-' " ). .

.

+1

Source: https://habr.com/ru/post/1732527/


All Articles