zaggs — 2010-03-09T05:40:39-05:00 — #1
I have some domains stored in a database and I have created a search to return matching domains based on what the user types.
For example if the user types "h" all domains containing a "h" should be returned.
The problem comes when a user searches for an "o" for example as "o" is contained in the extension (.com and .co.uk).
I am guessing that I am going to need some kind of regex to achieve what I am trying to do. Any help would be greatly appreciated!
Here is the current MySQL query I am using:
domain like '%".mysql_real_escape_string($_GET['keywords'])."%'
r937 — 2010-03-09T06:59:50-05:00 — #2
simplest solution: don't do the analysis when retrieving the data, do it when storing the data -- split the domain (e.g. example.com) into two columns, the domain (e.g. example) and the tld (e.g. com)
zaggs — 2010-03-09T07:01:46-05:00 — #3
Hmmm yes I thought of doing it this way, but im integrating with an existing system and this will simply be too much work.
Is there a way using regex?
rustybuddy — 2010-03-09T10:34:33-05:00 — #4
you could add two cols to the table and write a short query script to take the domain name, and split it and insert the results in the two new cols. Personally I would loose the ' . ' altogether and program for that on the view side. This would also allow you to do future searches if the visitor only wanted to look at .com names. You would then have the ability to get all the .com names from the table.
url | domain | extension
Just a suggestion.
philiptoop — 2010-03-09T11:48:20-05:00 — #5
A couple of questions
Is the part of the domain name you wish to match on effectively up to the first dot. That is hotgolf.com not www.hotgolf.com or www3.hot.golf.com.
When you have two or more characters for example "ho", do you want them as consecutive characters in the part of the domain name being searched.
zaggs — 2010-03-09T11:52:03-05:00 — #6
The domains are always stored like hotgolf.com (so it will only be the first dot).
Yes when I have "ho" being searched it should return hotgolf.com.
Hope this makes sense.
r937 — 2010-03-09T12:49:09-05:00 — #7
okay, now you're in business!!
WHERE <font color='"Blue"'>SUBSTRING_INDEX(domain,'.',1)</font> LIKE ...
zaggs — 2010-03-09T12:57:59-05:00 — #8
will that work for .co.uk domains? Or does that make it more complicated?
r937 — 2010-03-09T13:14:36-05:00 — #9
what happened when you tested it?
dacoda — 2010-03-09T13:21:44-05:00 — #10
I think you just need to do this "select * from table where column LIKE '%$var' "
zaggs — 2010-03-09T13:33:33-05:00 — #11
It returned ".com" domains but no ".co.uk"
dacoda — 2010-03-09T13:40:23-05:00 — #12
I mean "SElect * from table where column LIKE '$var%'";
zaggs — 2010-03-09T13:42:40-05:00 — #13
That won't work. Thanks anyway
r937 — 2010-03-09T13:43:01-05:00 — #14
then ur doing it wrong
CREATE TABLE zaggs
( domain VARCHAR(99)
INSERT INTO zaggs VALUES
( 'hotgolf.com' )
,( 'example.com' )
,( 'hotgolf.co.uk' )
,( 'puke.com' )
SELECT * FROM zaggs
WHERE SUBSTRING_INDEX(domain,'.',1) LIKE '%ho%'
SELECT * FROM zaggs
WHERE SUBSTRING_INDEX(domain,'.',1) LIKE '%uk%'