24, July 2008

do I need to use fulltext search for one column? - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  Databases  >  MySQL
Topic: do I need to use fulltext search for one column?
« previous next »
Pages: [1] 2 Print

Author Topic: do I need to use fulltext search for one column?  (Read 1863 times)
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« on: Jul 27, 2006, 11: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?


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7974
40801 credits
Members referred : 3



« Reply #1 on: Jul 28, 2006, 02: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

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #2 on: Jul 28, 2006, 02:22:42 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
This is a really good idea thanks


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7974
40801 credits
Members referred : 3



« Reply #3 on: Jul 28, 2006, 02:37:34 PM »

Welcome Wink

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #4 on: Jul 28, 2006, 02:40:02 PM »

dou you think that this way 1-2 mio. records are not a problem?


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7974
40801 credits
Members referred : 3



« Reply #5 on: Jul 28, 2006, 02:42:58 PM »

I used this type in a database of 2 mil and it was ok.

Of course for big tables using mysql 5 (instead of 4) is allways better Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #6 on: Jul 28, 2006, 02:50:56 PM »

I see another problem, there are this kind of entries possible:
subdomein.domein.nl
www.domein.nl Visit through proxy
domein.nl

above its possible to split them while using regex

but what with this kind of domain names:
maniche18.blogs.sapo.pt

I saw another URL's with more dots like
www.domein.wh.at.ev.er Visit through proxy

maybe its better to remove the www only?


Last blog : 4th of July Lottery from TemplateMonster.com
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #7 on: Jul 28, 2006, 02:51:45 PM »

I used this type in a database of 2 mil and it was ok.

Of course for big tables using mysql 5 (instead of 4) is allways better Smiley
yes that's possible if this host works fine (you know which host I'm talking about)


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7974
40801 credits
Members referred : 3



« Reply #8 on: Jul 28, 2006, 02:57:01 PM »

If you want to make it better, you should hold a table with all the valid tlds, and associate it with the domain.

This way you will keep the subdomain(s), the domain, and the id of the tld.
This is propably the faster, but needs some work...

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #9 on: Jul 28, 2006, 03:17:14 PM »

If you want to make it better, you should hold a table with all the valid tlds, and associate it with the domain.

This way you will keep the subdomain(s), the domain, and the id of the tld.
This is propably the faster, but needs some work...

yes, maybe this is the best solution... what about index the domain name without www?


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7974
40801 credits
Members referred : 3



« Reply #10 on: Jul 28, 2006, 03:21:55 PM »

That would be better, but with no significant reduce in overhead.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #11 on: Jul 28, 2006, 09:51:25 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
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?


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7974
40801 credits
Members referred : 3



« Reply #12 on: Jul 29, 2006, 02: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:

Code:
<?php
$dom 
explode '.'$domainLeft );
$topDom array_pop $dom );
$restDom implode '.'$dom );

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #13 on: Jul 29, 2006, 02:13:17 AM »

Quote
First you get the tld by checkink the last characters of the domain with the tlds table,

somthing like:

SELECT tld FROM table WHERE 'www.domein.co.uk Visit through proxy' LIKE %tld

? maybe its too late but I don't get it... splitting all other parts is not the problem...


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7974
40801 credits
Members referred : 3



« Reply #14 on: Jul 29, 2006, 02:16:57 AM »

I guess that will work, but I am not really in a mood to think too Smiley

Check it out and let me know if it works (or not) so we can solve it tommorow Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #15 on: Jul 29, 2006, 02:20:05 AM »

I guess that will work, but I am not really in a mood to think too Smiley

Check it out and let me know if it works (or not) so we can solve it tommorow Smiley
Ok I will go to bed now (to get fresh ideas the next day)


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7974
40801 credits
Members referred : 3



« Reply #16 on: Jul 29, 2006, 02:23:12 AM »

Good night man, see ya tomorow Smiley (now this thread looks more like a chat zone, lol )

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #17 on: Jul 29, 2006, 12:23:42 PM »

I played a little bit more with this domain split.

I think there are more poblems:

example: www.domain.co.uk Visit through proxy

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) Wink


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7974
40801 credits
Members referred : 3



« Reply #18 on: Jul 29, 2006, 12:44:42 PM »

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, -1strlen$sql['tld'] ) = $sql['tld'] )
  {
     
//You found the tld
  $domainLeft substr $domain0, ( strlen($sql['tld'] - strlen($domain) + )); // 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 Smiley )
« Last Edit: Jul 29, 2006, 12:47:35 PM by Nikolas »

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #19 on: Jul 29, 2006, 02:50:10 PM »

Hey Nick,

Thank you that brings back the development time for this feature to only a few hours Wink

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($domain0, -(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)


Last blog : 4th of July Lottery from TemplateMonster.com
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=3425
Tags : php tutorials mysql domains databases Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] 2 Print 
Webdigity Webmaster Forums  >  Web Development  >  Databases  >  MySQL
Topic: do I need to use fulltext search for one column?
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Jul 24, 2008, 11:25:04 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 35.712
Total Topics: 7.376
Total Members: 3.706
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: FortuneBeach

38 Guests, 3 Users online :

12 users online today: