0

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.

8
  • Use full text searching, or explode on every space and do a separate like comparison for each term. Commented Oct 12, 2018 at 3:58
  • hi thanks for your reply, hmm.. which one would you recommend? I am new to this and its quite urgent, would prefer the easier solution.. @user3783243 Commented Oct 12, 2018 at 5:27
  • Please read Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. Commented Oct 12, 2018 at 9:30
  • @AngelLim Full text will probably be faster, and more accurate. I haven't used the mssql full text in a while though so I can't advise much more on it. learn.microsoft.com/en-us/sql/relational-databases/search/… Commented Oct 12, 2018 at 12:36
  • @user3783243 I tried the fulltext and it took really long to execute query (not sure what the reason is, could it be because i am using intranet?) the first time i tried, the result wasnt very accurate. and the subsequent time i could not execute because it took really long. Do you know why? Commented Oct 15, 2018 at 5:36

1 Answer 1

0

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%'
Sign up to request clarification or add additional context in comments.

2 Comments

Hi, thanks for your reply. How do I use the explode or preg_split?
explode(separator,string) check this example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.