jimath Posted March 19, 2008 Share Posted March 19, 2008 hello everyone! i d like to include a search engine in my site. i want to know how difficult could be if i write the code from scratch in php. i d also like to tell me if you know any good tutorials about this subject, and suggest me ready to use scripts written in php. what about the pros and the cons to use sth already implemented? Thank you very much! Link to comment https://forums.phpfreaks.com/topic/96863-search-engine-with-php/ Share on other sites More sharing options...
uniflare Posted March 19, 2008 Share Posted March 19, 2008 hotscripts.com is a website i remember by heart i used to use. contains free and commercial scripts of all kinds. the difficulty to create your own depends on what type of search engine and what functionality you would want. for instance search a database of keywords as apposed to search raw html files would be faster i would imagine as you wold not need to open every html file on your site. hope this helps, Link to comment https://forums.phpfreaks.com/topic/96863-search-engine-with-php/#findComment-495716 Share on other sites More sharing options...
jimath Posted March 19, 2008 Author Share Posted March 19, 2008 for example i d like the user types printers and the site displays the page containing all printers. need i store the path of each page in a db in order to achieve such a searching? Link to comment https://forums.phpfreaks.com/topic/96863-search-engine-with-php/#findComment-495723 Share on other sites More sharing options...
Alexhoward Posted March 19, 2008 Share Posted March 19, 2008 Hi, I too am having search problems. I have created a column of keywords next to the data people will be searching for. Then i am using the LIKE function. SELECT * FROM * WHERE * LIKE * Say you where searching for "car" If the keywords column only has one word in it, it works fine e.g. car but if it has more than one, it doesn't bring back anything e.g. car, van or car van Is this a common problem...? Cheers Link to comment https://forums.phpfreaks.com/topic/96863-search-engine-with-php/#findComment-495724 Share on other sites More sharing options...
uniflare Posted March 19, 2008 Share Posted March 19, 2008 for example i d like the user types printers and the site displays the page containing all printers. need i store the path of each page in a db in order to achieve such a searching? you would only use db searching for larger websites or website where content are stored in tables with page names etc or similar, then add a keyword field. or you could use file searching for htm/html files or even php files (if its per page-php file structure), for this you would add keywords in a syntax recognizable by a php search script using fopen functions to open and read the files and preg_match or similar function to search the keywords in the file. raw file searching must be slower since it opens/reads and closes each file individually, unless you keep a sort of keyword file, like a flat file db table file, with paths to scripts and keywords attached in a .txt file, but that file would need to be updated each time. ---------- if you are using a database engine like mysql you could just use the product table itself as the keyword table, ie: mysql_query("SELECT * FROM `products` WHERE `cat` LIKE '%".mysql_escape_string($_POST['search_string'])."%' ORDER BY `$list_order`"); this query will select and rows from table prouct that cat (short for category) matches the search string (also uses mysql_escape_string to make the $_POST data safe to use in a query), it then orders the list by $list_order variable (can be anything from name to price) --- for added functionality here are a few more examples: mysql_query("SELECT * FROM `products` WHERE (`cat` LIKE '%".mysql_escape_string($_POST['search_string'])."%' OR `name` LIKE '%".mysql_escape_string($_POST['search_string'])."%' OR `manf_code` LIKE '%".mysql_escape_string($_POST['search_string'])."%' OR `description` LIKE '%".mysql_escape_string($_POST['search_string'])."%' OR `price` LIKE '%".mysql_escape_string($_POST['search_string'])."%') ORDER BY `$list_order`"); this is an example or searching multiple fields at once, name/description/ manufacturing code, you could even add a keyword field just in case the description doesn't have them all, though this will usually bring every product if the client searches for "the" or something similar. ------ mysql_query("SELECT * FROM `products` WHERE (`cat` LIKE '%".mysql_escape_string($_POST['search_string'])."%' OR `name` LIKE '%".mysql_escape_string($_POST['search_string'])."%' OR `manf_code` LIKE '%".mysql_escape_string($_POST['search_string'])."%' OR `description` LIKE '%".mysql_escape_string($_POST['search_string'])."%' OR `price` LIKE '%".mysql_escape_string($_POST['search_string'])."%') ORDER BY `$list_order` DESC"); The same as directly above but will order by $list_order in Descending mode, z-a or 9-0 Hi, I too am having search problems. I have created a column of keywords next to the data people will be searching for. Then i am using the LIKE function. SELECT * FROM * WHERE * LIKE * Say you where searching for "car" If the keywords column only has one word in it, it works fine e.g. car but if it has more than one, it doesn't bring back anything e.g. car, van or car van Is this a common problem...? Cheers i do believe you require your own topic m8, im sure you did not mean it but you seem to be hijacking this guys thread make a new thread, give some actual code and wrap it in bbc tags (eg [ code ] <?php php here ?> [/ code ] ) hope this helps, Link to comment https://forums.phpfreaks.com/topic/96863-search-engine-with-php/#findComment-495730 Share on other sites More sharing options...
Alexhoward Posted March 19, 2008 Share Posted March 19, 2008 Hi, No sorry, i didn't mean to be hijacking... but it appears that you've just sent him down the same route i already took. i.e. having a keywords column on your sql table. i'll start a new thread if it makes people happy...? Link to comment https://forums.phpfreaks.com/topic/96863-search-engine-with-php/#findComment-495738 Share on other sites More sharing options...
uniflare Posted March 19, 2008 Share Posted March 19, 2008 hey im not mad it just seemed like a seperate question, i gave a few examples, multiple where queries should work, also could get a little messy with 2 people in 1 topic. ill help u in ya new thread Link to comment https://forums.phpfreaks.com/topic/96863-search-engine-with-php/#findComment-495739 Share on other sites More sharing options...
Alexhoward Posted March 19, 2008 Share Posted March 19, 2008 OK, Apologies to jimath Thanks uniflare Link to comment https://forums.phpfreaks.com/topic/96863-search-engine-with-php/#findComment-495741 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.