views:

128

answers:

2

How can I recognize when a user has missed a space when entering a search term? For example, if the user enters "usbcable", I want to search for "usb cable". I'm doing a REGEX search in MySQL to match full words.

I have a table with every term used in a search, so I know that "usb" and "cable" are valid terms. Is there a way to construct a WHERE clause that will give me all the rows where the term matches part of the string?

Something like this:

SELECT st.term 
FROM SearchTerms st
WHERE 'usbcable' LIKE '%' + st.term + '%'

Or any other ideas?

+5  A: 

Text Segmentation is a part of Natural Language Processing, and is what you're looking for in this specific example. It's used in search engines and spell checkers, so you might have some luck with example source code looking at open source spell checkers and search engines.

Spell checking might be the correct paradigm to consider anyway, as you first need to know whether it's a legitimate word or not before trying to pry it apart.

Adam Davis
A: 

Posted in the comments, but I thought it important to bring up as an answer:

Does that query not work? – Simon Buchan

Followed by:

Well, I should've tested it before I posted. That query does not work, but with a CONCAT it does, like so: WHERE 'usbcable' LIKE Concat('%', st.term, '%'). I think this is the simplest, and most relevant (specific to my site), way to go. – arnie0674

Certainly far easier than text segmentation for this application...

Adam Davis