How to allow fulltext searching with hyphens in the search query

前端 未结 5 463
温柔的废话
温柔的废话 2020-12-03 14:57

I have keywords like \"some-or-other\" where the hyphens matter in the search through my mysql database. I\'m currently using the fulltext function.

Is there a way

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 15:12

    My preferred solution to this is to remove the hyphen from the search term and from the data being searched. I keep two columns in my full-text table - search and return. search contains sanitised data with various characters removed, and is what the users' search terms are compared to, after my code has sanitised those as well.

    Then I display the return column.

    It does mean I have two copies of the data in my database, but for me that trade-off is well worth it. My FT table is only ~500k rows, so it's not a big deal in my use case.

提交回复
热议问题