duandu2980 2018-10-12 03:51
浏览 61

如何在PHP和SQL Server中进行搜索功能的模糊逻辑?

I am working on a webpage linked to my database that has a search feature as the main function. Users have to search for Company's name to check which group the company belongs to etc. However, I need a fuzzy search logic to do company name screening. I tried many methods but the challenge is the company names are long. I used WHERE NAME LIKE %keywordfromform% but its not fuzzy enough.

For example:

Actual: ABC Company 123 ROAD
User search: Road 123 ABC Company

The result should appear but it doesn't show, this leads to inaccuracy in searches.

  • 写回答

1条回答 默认 最新

  • duanchendu69495 2018-10-12 04:30
    关注

    actual : "ABC Company 123 ROAD"
    user = "Road 123 ABC Company" use explode or preg_split for splitting the string into an array. As you don't know the order so it would be better to break the query string and search by word instead of searching for a whole string.

    If you need any of the words

       SELECT * FROM table
       WHERE column LIKE '%word1%'
       OR column1 LIKE '%word2%'
       OR column1 LIKE '%word3%'
    

    If you need all of the words to be present

       SELECT * FROM table
       WHERE column LIKE '%word1%'
       AND column1 LIKE '%word2%'
       AND column1 LIKE '%word3%'
    
    评论

报告相同问题?