Solved

Algoritm to search for "Match whole words"

  • 17 February 2020
  • 3 replies
  • 155 views

Userlevel 3
Badge +5

Does anyone know a good algorithm to search a string on whole words only. For example, look for order and not order_line in a query. 

 

This could be an useful addition to code search. 

icon

Best answer by Jasper 18 February 2020, 16:40

View original

3 replies

Userlevel 5
Badge +16

Maybe you can find some inspiration using for example scholar.google.com, I am pretty sure this is a well researched topic. A quick search led me to this overview, it states some different search techniques. https://www.ncbi.nlm.nih.gov/pmc/articles/PMC61442/

Userlevel 7
Badge +11

Something like this should work: 

where '.' + column_to_search + '.' 
like '%[^a-z_]search_term[^a-z_]%'

This query adds a period before the column to take into account situations where the word is at the beginning or end, and then checks if the word is enclosed by characters other than a to z or underscore.

Userlevel 3
Badge +5

Perhaps an option if you want to search on words is the use of FullText search:

https://docs.microsoft.com/en-us/sql/relational-databases/search/full-text-search?view=sql-server-ver15

Reply