Skip to main content
Solved

Algoritm to search for "Match whole words"

  • February 17, 2020
  • 3 replies
  • 158 views

Ester
Moderator
Forum|alt.badge.img+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. 

Best answer by Jasper

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.

View original
Did this topic help you find an answer to your question?

3 replies

Freddy
Forum|alt.badge.img+16
  • Thinkwise Local Partner Brasil
  • 529 replies
  • February 17, 2020

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/


Jasper
Superhero
  • 678 replies
  • Answer
  • February 18, 2020

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.


Forum|alt.badge.img+5
  • Captain
  • 47 replies
  • February 19, 2020

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings