Jump to content

Search Engine with PHP


jimath

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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 :P

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.