Topic: do I need to use fulltext search for one column? (Read 4522 times)
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
It's time to use PHP5!
« on: Jul 27, 2006, 10:29:23 pm »
Hello,
I have a table with these two important columns: "folder" (int) and domain_name (varchar(255).
I accept there will be 1mio records some time and I need to search fast inside the column domain_name for a match like:
Code:
SELECT folder FROM table WHERE domain_name = 'www.webdigity.com';
is this a problem? or is it better to use a fulltext search?
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits Members referred : 3
« Reply #1 on: Jul 28, 2006, 01:17:47 pm »
I am not sure for the full text, but if you want to make this query faster you can break the domain to 3 fields (subdomain, domain, tld) and make them index
I am not sure for the full text, but if you want to make this query faster you can break the domain to 3 fields (subdomain, domain, tld) and make them index
This is a really good idea thanks
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits Members referred : 3
I am not sure for the full text, but if you want to make this query faster you can break the domain to 3 fields (subdomain, domain, tld) and make them index
Hey Nick,
I checked this but how do you parse an unkown domain name format like domain.com or domain.co.uk or sub.domain.co.uk
to resolve the three parts? checking the last part against 280 tld's?
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits Members referred : 3
« Reply #12 on: Jul 29, 2006, 01:07:54 am »
First you get the tld by checkink the last characters of the domain with the tlds table,
Then you remove the tld part and split the domain with the . character, like this:
there are two mathches in my tld table: co.uk and uk
another problem is the sub domain because this is optional, how does the script knows that?
(by the way the select statemant doesn't work)
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits Members referred : 3
« Reply #18 on: Jul 29, 2006, 11:44:42 am »
I will try to make this with pseudo - php code :
Code:
<?php
$domain = 'whatever.com';
$sql->query ( "SELECT tld FROM tlds ORDER BY LENGTH DESC" );//Meaning that it will give first the co.uk and then the uk while ( $sql->next() ) { if ( substr ( $domain, -1, strlen( $sql['tld'] ) = $sql['tld'] ) { //You found the tld $domainLeft = substr ( $domain, 0, ( strlen($sql['tld'] - strlen($domain) + 1 )); // It will left the whatever, without the extension and the . if ( strpos ( $domainLeft, '.' ) === false ) //It has subdomain { $subDomain = ''; $finalDomain = $domainLeft; }else{ $subDomain = explode ( '.', $domainLeft ); $finalDomain = array_pop ( $subDomain ); $subDomain = implode ( '.', $subDomain ); } } }
I am not sure if it is working, but the logic is correct (or I have to drink another coffee to think it better )
« Last Edit: Jul 29, 2006, 11:47:35 am by Nikolas »
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
It's time to use PHP5!
« Reply #19 on: Jul 29, 2006, 01:50:10 pm »
Hey Nick,
Thank you that brings back the development time for this feature to only a few hours
after some modification, this is the result:
Code:
<?php $domain = "mail.finalwebsites.co.uk";
$res = mysql_query("SELECT tld FROM domain_info ORDER BY LENGTH(tld) DESC"); //Meaning that it will give first the co.uk and then the uk while ($arr = mysql_fetch_assoc($res)) { $tmp_tld = substr($domain, -strlen($arr['tld'])); if ($tmp_tld == $arr['tld']) { // You found the tld $tld = $arr['tld']; $domainLeft = substr($domain, 0, -(strlen($tld) + 1)); // It will left the whatever, without the extension and the . if (strpos($domainLeft, ".") === false) { // It hasn't a subdomain $subDomain = ""; $finalDomain = $domainLeft; } else { $domain_parts = explode(".", $domainLeft); $finalDomain = array_pop($domain_parts); // select the domain and remove it from the array $subDomain = implode(".", $domain_parts); // a subdomain can more then one parts seperated with dot's } echo "The tld is: ".$tld."<br>"; echo "the domain name is :".$finalDomain."<br>"; echo "the subdomain is: "; echo (!empty($subDomain)) ? $subDomain : "n/a"; echo "<br>"; break; } }
by the way this function is a rare one (searched already the internet for a while). I like to post this script to the tutorial section, what about the tld table? Maybe we should send this data on request? (to members only)
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=3425