Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,148,892 members, 7,802,874 topics. Date: Saturday, 20 April 2024 at 12:26 AM |
Nairaland Forum / Science/Technology / Webmasters / Code On Developing A Web Search Engine Please : Php,ajax & Sql Programmers: (2246 Views)
Developing A Sports Betting Site And What It Entails / Form Validation Tutorial Using Javascript, Php And Ajax! / Cost of Developing a Website in Nigeria (2) (3) (4)
Code On Developing A Web Search Engine Please : Php,ajax & Sql Programmers: by Bheey: 4:34pm On Mar 17, 2010 |
Ideas wanted please , This is actually a Project. thanks! Thanks. |
Re: Code On Developing A Web Search Engine Please : Php,ajax & Sql Programmers: by Nobody: 5:16pm On Mar 17, 2010 |
try reading on curl and familirize with file_get_contents with php ,also read on some autocomplete and ssearch algorithm u shud know most of the logic goes to the database so brace up cuz u will read some advance database tutorials, later might drop a link that's if chinaland doesn't delete my post |
Re: Code On Developing A Web Search Engine Please : Php,ajax & Sql Programmers: by donline: 3:02am On Mar 18, 2010 |
i have an automated software that can do this 4 u without much stress call 08035057766 for the solutions |
Re: Code On Developing A Web Search Engine Please : Php,ajax & Sql Programmers: by Nobody: 7:41am On Mar 18, 2010 |
There are 2 ways to do a search engine, it is either you crawl through the sites each time a search is made. How you are going to get the list of sites is not by coding per say, the sites get submitted. Crawling through each sites everytime is a very slow way, so most modern search engines go through the following steps: 1. After a site gets submitted, it is indexed into the dbase such that a search made will just search the dbase which is faster than crawling through the entire site. 2. You need a script that can read the url of a site and find the links and read the links too. In short, it will search the whole site like a tree and save that tree record into a dbase. I have codes some site search scripts in the past but have misplaced the codes, but that is a briefing of the algorithm. And yes, the indexing script will need to use something like curl. And i suspect you might need a cron job to update the dbase from time to time. In this kinda project, you will need an array of scripts. You may first start by checking phpclasses.org - this is not something i can post codes for free like that. But at least i have contributed in my own little way. |
Re: Code On Developing A Web Search Engine Please : Php,ajax & Sql Programmers: by Bheey: 4:10pm On May 04, 2010 |
Thanks guys. And donline, its a web search engine , a web job search engine to be precise. Please let me know if you can post it 2 me. I'll give u my email address. @ *dhtml, its not a crawler o , a spider is a much more bigger project. @ pc guru, thanks for the reply. This is the used that I used. But I can't still get what I want. This is my index page code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form method="post" action="BinarySearch1.php"> <input name="search_text" type="text"> <input name="search_Submit" type="submit" value="Search for Job" /> </form> </body> </html> This is the CSS Styles code: .search_boom { color: #4A4A24; background-color: #E8E8D0; } .table2 { border: thin solid #4A4A24; width: 880px; } .table1 { } .BoomStyle1 { color: #2222FF; text-decoration: none; } .div_Main1 { width: 880px; color: #2222FF; background-color: #ECECFF; border: thin solid #9191FF; } .Header_Query { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; font-style: italic; line-height: normal; color: #003366; } This is the BinarySearch1.php code: <?php include_once(', /db_searchMe.php'); //Post Search Keyword Now! $Submit= trim($_POST['search_Submit']); $text1 = trim($_POST['search_text']); //echo "$text1" . "<br>"; //Test Output //if (!isset($Submit)) if (!isset($Submit)) { echo "You didn't submit a keyword"; } else { if (strlen ($text1) <= 2) echo "Search term too short"; else { //This exports the values to be compared with //This Query only exports values that fills up the array() $query = "SELECT * FROM searchengine order by title ASC"; $result = mysql_query($query); $row = mysql_num_rows($result); //Declare the array variable $arr = array(); $arr2 = array(); //Dynamically Populate the 1:n array of Job Titles from the Database for($i = 0; $i < $row; $i++) { $info = mysql_fetch_array($result); $title_a = $info['title']; //echo $title_a . "<p>" ; $arr[] = $title_a; //$arr2[] .= array($i => $title_a); } //, Start Binary Searching Here, include_once('BS_Code.php'); //, End Binary Searching, $starttime = microtime(true); echo '<p>' . $starttime . '</p>'; // $query = mysql_query("select * from table" //, Get other details from the database, $sql_out="select * from searchengine where title like '%$val%' order by title ASC"; $result_out=mysql_query($sql_out) or die(mysql_error()); $row_out=mysql_num_rows($result_out); //--------------------------------------------------------------------------------------- $endtime = microtime(true); echo '<p>' . $endtime . '</p>'; $time = $endtime - $starttime; echo $time; //--------------------------------------------------------------------------------------- if($row_out<1) { $rows="No job listing found for the keyword <b>" . $val . "</b>"; } elseif($row_out==1) { $rows="<b> One </b> job listing found for the keyword <b>" . $val . "</b>"; } else { $rows= "<b>" . $row_out . " job listings </b> found for the keyword <b>" . $val . "</b>"; } echo "<br><i>" . $rows . "</i>"; echo "<span class='Header_Query'><br> Query took " . $time . " seconds </span>"; for($k=0;$k<$row_out;$k++) { $me=mysql_fetch_assoc($result_out); ?> <link href="Styles_search1.css" rel="stylesheet" type="text/css" /> <table width="30%" border="0"> <tr> <td width="10%"> <span class="Header_Query"> <?php echo $k+1 . "<br>"; ?> </td> <td> <?php echo "<br><b>" . $me['title'] . "<b><br>"; $url_boom = $me['url']; echo "<a href='$url_boom'><b>" . $me['description'] . "<b><br></a>"; ?> </td> <?php } ?> </tr> <?php } //End Inner Else } //End Outer Else //, End, ?> </table> This is the BS_Code.php code: <?php // Algorithms // Recursive binary search algorithm on an array of strings. // Returns the index of an element in the array, // or -1 if the string can not be found. // The string must be sorted in ascending order in the array. // The array is a global variable, that optimizes speed. // The move is performed by the starting and ending indices. //Assign Array to variable $A=$arr; //Test Output //print_r($A) . "<p>"; //echo "<p>"; $size=count($A); $val=""; function binarySearch($value,$starting,$ending) { if($ending<$starting) { return -1; } $mid=intVal(($starting+$ending)/2); global $A; $result=intVal(strcmp($value,$A[$mid])); //echo $result . "<br>"; if($result===0) { return $mid; } else { if($result<0) { $ending=$mid-1; // echo $ending . "<br>"; } else { if($result>0) { $starting=$mid+1; // echo $starting . "<br>"; } }} return binarySearch($value,$starting,$ending); } //________________________________________ print_r(array_values($A)).'<br>'; //_________________________________________ echo "<br>"; //print_r($B); echo "<br>"; //_________________________________________ //echo "Give a word to search:" . "<br>"; //_________________________________________ //Assign $val=$text1; //fclose($fp); $y=binarySearch($val,0,count($A)-1); if($y>=0) { echo $val, " ", "is at position", " ", $y, "\n"; } else { echo $val, " ", "not found in the array, ", "\n"; } ?> This is the table structure (a dummy table anyway): CREATE TABLE IF NOT EXISTS `searchengine` ( `id` int(11) NOT NULL auto_increment, `title` varchar(100) collate latin1_general_ci NOT NULL, `description` text collate latin1_general_ci NOT NULL, `url` varchar(200) collate latin1_general_ci NOT NULL, `keywords` varchar(400) collate latin1_general_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=9 ; -- -- Dumping data for table `searchengine` -- INSERT INTO `searchengine` VALUES (1, 'Google', 'This is a search engine to find what you need on it.', 'http://www.google.com', 'google search engine'); INSERT INTO `searchengine` VALUES (2, 'phpacademy', 'Free php video tutorials!', 'http://www.phpacademy.info', 'php free videos video tutorial tutorials'); INSERT INTO `searchengine` VALUES (3, 'Yahoo!', 'A search engine. Find what you need!', 'http://www.yahoo.com', 'yahoo search engine'); INSERT INTO `searchengine` VALUES (4, 'Booming Solutions', 'My Solutions ni o!', 'http://www.boomingsolutions.net', 'Boom, Solutions, Booming Solutions, Web Design'); INSERT INTO `searchengine` VALUES (5, 'For All I care O!', 'Ok Now!', 'http://www.boomingsolutions.net', 'Check Me Out'); INSERT INTO `searchengine` VALUES (6, 'Same To This Too O!', 'Says who?', 'http://www.boomingsolutions.net', 'Say I said so o!'); INSERT INTO `searchengine` VALUES (7, 'Boom', 'Same ni!', 'http://www.boomingsolutions.net', 'Boom, Solutions, Booming Solutions, Web Design'); INSERT INTO `searchengine` VALUES (8, 'Solutions', 'I told ya!', 'http://www.boomingsolutions.net', 'Say I said so o!'); Now, these codes are working properly. What it does is that it outputs values from my database and stores them in an array and then searches the input from the user in the array using Binary Search Algorithm. The problem now is this: I want to explode the search term by the user and then run a loop to search through the array and then output all corresponding outputs using SPACE as the delimiter. For instance if the user enters "Booming Solutions and Yahoo are same", then it explodes it by the spaces(as delimiter) to 'Booming', 'Solutions', 'Yahoo', and 'Same' (while ignoring common words like 'and' and 'are'). It then runs a loop using the Binary code algorithm above to display the following outputs: Boom Booming Solutions Solutions Same To This Too O! Yahoo! according to the table structure. Do anyone have an idea on how to go about this please? An urgent reply is needed as I have to present it very soon! |
Re: Code On Developing A Web Search Engine Please : Php,ajax & Sql Programmers: by Bheey: 10:06am On May 05, 2010 |
@pc guru, thanks for the advice , can u look into the code and c where all wat u said fits? @donline, can u send it to me? , let me know pls. *dhtml. I'm not into a crawler or spider o , thanks though 4 d tip. This is just a local web search engine for a job website that have a database of jobs with links to the job sites that are recruiting fo the various vacancies. This is the code I've worked on. But I still can't get what I want. This is my index page code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form method="post" action="BinarySearch1.php"> <input name="search_text" type="text"> <input name="search_Submit" type="submit" value="Search for Job" /> </form> </body> </html> This is the CSS Styles code: .search_boom { color: #4A4A24; background-color: #E8E8D0; } .table2 { border: thin solid #4A4A24; width: 880px; } .table1 { } .BoomStyle1 { color: #2222FF; text-decoration: none; } .div_Main1 { width: 880px; color: #2222FF; background-color: #ECECFF; border: thin solid #9191FF; } .Header_Query { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; font-style: italic; line-height: normal; color: #003366; } This is the BinarySearch1.php code: <?php include_once(', /db_searchMe.php'); //Post Search Keyword Now! $Submit= trim($_POST['search_Submit']); $text1 = trim($_POST['search_text']); //echo "$text1" . "<br>"; //Test Output //if (!isset($Submit)) if (!isset($Submit)) { echo "You didn't submit a keyword"; } else { if (strlen ($text1) <= 2) echo "Search term too short"; else { //This exports the values to be compared with //This Query only exports values that fills up the array() $query = "SELECT * FROM searchengine order by title ASC"; $result = mysql_query($query); $row = mysql_num_rows($result); //Declare the array variable $arr = array(); $arr2 = array(); //Dynamically Populate the 1:n array of Job Titles from the Database for($i = 0; $i < $row; $i++) { $info = mysql_fetch_array($result); $title_a = $info['title']; //echo $title_a . "<p>" ; $arr[] = $title_a; //$arr2[] .= array($i => $title_a); } //, Start Binary Searching Here, include_once('BS_Code.php'); //, End Binary Searching, $starttime = microtime(true); echo '<p>' . $starttime . '</p>'; // $query = mysql_query("select * from table" //, Get other details from the database, $sql_out="select * from searchengine where title like '%$val%' order by title ASC"; $result_out=mysql_query($sql_out) or die(mysql_error()); $row_out=mysql_num_rows($result_out); //--------------------------------------------------------------------------------------- $endtime = microtime(true); echo '<p>' . $endtime . '</p>'; $time = $endtime - $starttime; echo $time; //--------------------------------------------------------------------------------------- if($row_out<1) { $rows="No job listing found for the keyword <b>" . $val . "</b>"; } elseif($row_out==1) { $rows="<b> One </b> job listing found for the keyword <b>" . $val . "</b>"; } else { $rows= "<b>" . $row_out . " job listings </b> found for the keyword <b>" . $val . "</b>"; } echo "<br><i>" . $rows . "</i>"; echo "<span class='Header_Query'><br> Query took " . $time . " seconds </span>"; for($k=0;$k<$row_out;$k++) { $me=mysql_fetch_assoc($result_out); ?> <link href="Styles_search1.css" rel="stylesheet" type="text/css" /> <table width="30%" border="0"> <tr> <td width="10%"> <span class="Header_Query"> <?php echo $k+1 . "<br>"; ?> </td> <td> <?php echo "<br><b>" . $me['title'] . "<b><br>"; $url_boom = $me['url']; echo "<a href='$url_boom'><b>" . $me['description'] . "<b><br></a>"; ?> </td> <?php } ?> </tr> <?php } //End Inner Else } //End Outer Else //, End, ?> </table> This is the BS_Code.php code: <?php // Algorithms // Recursive binary search algorithm on an array of strings. // Returns the index of an element in the array, // or -1 if the string can not be found. // The string must be sorted in ascending order in the array. // The array is a global variable, that optimizes speed. // The move is performed by the starting and ending indices. //Assign Array to variable $A=$arr; //Test Output //print_r($A) . "<p>"; //echo "<p>"; $size=count($A); $val=""; function binarySearch($value,$starting,$ending) { if($ending<$starting) { return -1; } $mid=intVal(($starting+$ending)/2); global $A; $result=intVal(strcmp($value,$A[$mid])); //echo $result . "<br>"; if($result===0) { return $mid; } else { if($result<0) { $ending=$mid-1; // echo $ending . "<br>"; } else { if($result>0) { $starting=$mid+1; // echo $starting . "<br>"; } }} return binarySearch($value,$starting,$ending); } //________________________________________ print_r(array_values($A)).'<br>'; //_________________________________________ echo "<br>"; //print_r($B); echo "<br>"; //_________________________________________ //echo "Give a word to search:" . "<br>"; //_________________________________________ //Assign $val=$text1; //fclose($fp); $y=binarySearch($val,0,count($A)-1); if($y>=0) { echo $val, " ", "is at position", " ", $y, "\n"; } else { echo $val, " ", "not found in the array, ", "\n"; } ?> This is the table structure (a dummy table anyway): CREATE TABLE IF NOT EXISTS `searchengine` ( `id` int(11) NOT NULL auto_increment, `title` varchar(100) collate latin1_general_ci NOT NULL, `description` text collate latin1_general_ci NOT NULL, `url` varchar(200) collate latin1_general_ci NOT NULL, `keywords` varchar(400) collate latin1_general_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=9 ; -- -- Dumping data for table `searchengine` -- INSERT INTO `searchengine` VALUES (1, 'Google', 'This is a search engine to find what you need on it.', 'http://www.google.com', 'google search engine'); INSERT INTO `searchengine` VALUES (2, 'phpacademy', 'Free php video tutorials!', 'http://www.phpacademy.info', 'php free videos video tutorial tutorials'); INSERT INTO `searchengine` VALUES (3, 'Yahoo!', 'A search engine. Find what you need!', 'http://www.yahoo.com', 'yahoo search engine'); INSERT INTO `searchengine` VALUES (4, 'Booming Solutions', 'My Solutions ni o!', 'http://www.boomingsolutions.net', 'Boom, Solutions, Booming Solutions, Web Design'); INSERT INTO `searchengine` VALUES (5, 'For All I care O!', 'Ok Now!', 'http://www.boomingsolutions.net', 'Check Me Out'); INSERT INTO `searchengine` VALUES (6, 'Same To This Too O!', 'Says who?', 'http://www.boomingsolutions.net', 'Say I said so o!'); INSERT INTO `searchengine` VALUES (7, 'Boom', 'Same ni!', 'http://www.boomingsolutions.net', 'Boom, Solutions, Booming Solutions, Web Design'); INSERT INTO `searchengine` VALUES (8, 'Solutions', 'I told ya!', 'http://www.boomingsolutions.net', 'Say I said so o!'); Now, these codes are working properly. What it does is that it outputs values from my database and stores them in an array and then searches the input from the user in the array using Binary Search Algorithm. The problem now is this: I want to explode the search term by the user and then run a loop to search through the array and then output all corresponding outputs using SPACE as the delimiter. For instance if the user enters "Booming Solutions and Yahoo are same", then it explodes it by the spaces(as delimiter) to 'Booming', 'Solutions', 'Yahoo', and 'Same' (while ignoring common words like 'and' and 'are'). It then runs a loop using the Binary code algorithm above to display the following outputs: Boom Booming Solutions Solutions Same To This Too O! Yahoo! according to the table structure. Do anyone of you have an idea on how to go about this please? |
Re: Code On Developing A Web Search Engine Please : Php,ajax & Sql Programmers: by Nobody: 10:38am On May 06, 2010 |
this code is too long mehn |
Re: Code On Developing A Web Search Engine Please : Php,ajax & Sql Programmers: by sayhi2ay(m): 5:59pm On May 06, 2010 |
Bheey: Going through your code, meanwhile, try use something like this 4 validation, function isformsubmit(){ ($_SERVER['REQUEST_METHOD'] == “POST”) ? return TRUE : return NULL; } if ((isset($_POST['submit'])) && (isformsubmit()) ){ cos if someone changes the name of a field to "submit", they dont necessarily have to click the button to hack into your code, and might avoid some functions attached to that submit action |
Re: Code On Developing A Web Search Engine Please : Php,ajax & Sql Programmers: by sayhi2ay(m): 6:09pm On May 06, 2010 |
Bheey: This is where data structure comes into play, quick question - why do you need it to explode when you'd still have a different output, why not go ahead and output, leaving the exploding out of the equation ? |
Re: Code On Developing A Web Search Engine Please : Php,ajax & Sql Programmers: by c7(m): 7:13pm On May 06, 2010 |
The code don dey scare me. Its too L O N G ! I'll try to check it later |
Re: Code On Developing A Web Search Engine Please : Php,ajax & Sql Programmers: by c7(m): 7:13pm On May 06, 2010 |
The code don dey scare me. Its too L O N G ! I'll try to check it later |
(1) (Reply)
Bobrisky.com For Sale / Microsoft Office 2016 Activation Key Needed / Download Naijaloaded Mobile Wordpress Themes
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 71 |