Page 1 of 1
How do I create a search engine for my site?
Posted: Mon Jun 01, 2009 1:00 pm
by iFlex
Ok basicly I need a PHP based, And I dont mind javascript, and MySQL if needed, search engine that searches for content in the site. I just need to the source, no fancy stuff beacuse my layout is already coded.
Anyone who can help I will be very gratefull!
-Flex
Re: How do I create a search engine for my site?
Posted: Mon Jun 01, 2009 3:05 pm
by mikemike
Most site's searches work by having all their content in a database and then searching that database in the search pages. If your site is hard-coded then I suggest looking for a CGI-based indexing service, there are some free one's available.
If your search is quite important to your project then Google offer a paid service where they install a Google server into your network and that will index your pages for you - this is probably the most ideal solution, but not the most cost effective I imagine.
Re: How do I create a search engine for my site?
Posted: Tue Jun 02, 2009 7:31 am
by iFlex
Thanks for the suggestion but I am looking for just a PHP code, I cant afford anything like google for now. Because of the way my site is coded inside a frame its very difficult.
Thanks
-Flex
Re: How do I create a search engine for my site?
Posted: Tue Jun 02, 2009 7:53 am
by kingmaker
i think this may help you!!
Here's a tutorial that explains how you can keep track of what kind of traffic search engines are sending to your site. We'll use a database table to store all the keywords that have been used to reach your site and we'll couple each keyword with the referring search engine. Go in phpMyAdmin, create a database and paste this code in the SQL window, this will create the table. In this table we'll store even the timestamp of the visit.
Code: Select all
CREATE TABLE `keywords` (
`id` int(11) unsigned NOT NULL auto_increment,
`searchengine` varchar(10) collate latin1_general_ci NOT NULL,
`keyword` text collate latin1_general_ci NOT NULL,
`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
FULLTEXT KEY `keyword` (`keyword`)
) ENGINE=MyISAM
Now let's see some really simple php code: what we do is basically parse the referer url, find the search engine with a regular expression function (php eregi function)and store the search term in the database:
Code: Select all
<?php
$ref = $_SERVER['HTTP_REFERER'];
$se = "";
if(eregi("msn",$ref))
{
$se = "msn";
$s=explode("?",$ref);
parse_str($s[1]);
$keyword = $q;
}
if(eregi("google",$ref))
{
$se = "google";
$s=explode("?",$ref);
parse_str($s[1]);
$keyword = $q;
}
if(eregi("yahoo",$ref))
{
$se = "yahoo";
$s=explode("?",$ref);
parse_str($s[1]);
$keyword = $p;
}
if(eregi("altavista",$ref))
{
$s=explode("?",$ref);
parse_str($s[1]);
$se = "altavista";
$keyword = $q;
}
if(eregi("ask",$ref))
{
$se = "ask";
$s=explode("?",$ref);
parse_str($s[1]);
$keyword = $q;
}
$connect = mysql_connect(host,user,password);
mysql_select_db(databasename , $connect);
$insert = mysql_query("INSERT INTO keywords VALUES (NULL,'$se','$keyword',NULL)");
mysql_close($connect);
?>
As you can see adding other search engines is easy, you just have to copy and paste one of the if blocks, replace the string with the search engine name and change thekeyword variable name depending on the variable used by the search engine you're adding. To see what variable it uses just run a search on the search engine and see the variable name that preceed the keyword, e.g
http://www.google.com/search?q=php+tutorials as you can see the variable that contains the keyword is "q".
Re: How do I create a search engine for my site?
Posted: Tue Jun 02, 2009 8:55 am
by mikemike
I'm not sure that's what he was looking for, your script just inserts into a database whatever the suer searched to find his site - that is not a search engine.
Unless you're storing content in a database you're going to struggle creating a search in PHP - you'd have to create your own indexing bot to crawl your site and insert content into your database periodically - probably not worth the hassle. One thing you could do is add a custom Google search, this allows you to use Google to just search the pages it's crawled from your site, you can also customise the page slightly, this is free. Just Google 'custom google search'.
Re: How do I create a search engine for my site?
Posted: Tue Jun 02, 2009 9:58 am
by iFlex
mikemike wrote:I'm not sure that's what he was looking for, your script just inserts into a database whatever the suer searched to find his site - that is not a search engine.
Unless you're storing content in a database you're going to struggle creating a search in PHP - you'd have to create your own indexing bot to crawl your site and insert content into your database periodically - probably not worth the hassle. One thing you could do is add a custom Google search, this allows you to use Google to just search the pages it's crawled from your site, you can also customise the page slightly, this is free. Just Google 'custom google search'.
Ahh yes thats what i looking for! Ill try that. Oh and thanks kingsmaker for the code but thats not exactly what im looking for. You dont need to explain to me how to use PHPmyAdmin

I use it already for things like the admin pages I made! Thanks again though!

Re: How do I create a search engine for my site?
Posted: Sat Jun 06, 2009 2:04 pm
by djjjozsi
hello,
lets have a look at this site,
you can insert your mysql table's structure, and set the search conditions for the fields:
http://phpcode.hu/teszt/easysearch/
and its making sql injection safe code, with pager and order-by links for the selected columns.
video tut is on the way.
Re: How do I create a search engine for my site?
Posted: Sat Jun 06, 2009 6:28 pm
by mikemike
Yes, but as discussed his data isn't in a database, it's hard-coded - so that's useless.
Re: How do I create a search engine for my site?
Posted: Sun Jun 07, 2009 12:01 am
by djjjozsi
mikemike wrote:Yes, but as discussed his data isn't in a database, it's hard-coded - so that's useless.
If a search engine is needed, he need to change his site a little bit. If there are html pages, a simple table refresh code can insert the tags from the html files into a table.