DevShed - Quick and Dirty Search Engine with PHP and MySQL
★ wanayoo — archive 1999 http://www.devshed.com/Server_Side/PHP/Search_Engine/page2.htmlNouvelle recherche | Portail wanayoo

Developer Shed
Wednesday, 11.03.99  

HOME > SERVER SIDE > PHP > ARTICLE    SOURCE

Power Search
Free Newsletter:


Client Side
DHTML
Graphics
JavaScript
XML

Server Side
Administration
ASP
JServ
MySQL
PHP
Python
Roxen
Zend
Zope
Web Hosting

Tools
HTML Editors
Graphic Editors
FTP Programs

Dev Talk
Forums
Mailing List
Brain Dump
Developer News
Feedback

ClipScripts
Add script
Edit script


Advertise
on DevShed
JUMP TO:
> Introduction
> Searching the Table
Quick and Dirty Search Engine with PHP and MySQL
By Clay Johnson
April 30, 1999

Searching the Table
Now you have an easy to-use table of keywords and their associations. How do you query this table? Here's what I do:

First I format each searchterms passed into the script as 'word1','word2','word3' and stick it in a string called $querywords.

Then I throw them into this SQL query:


SELECT count(search_table.word) as score, search_table.qid,your_table.blob FROM search_table,your_table WHERE your_table.qid = search_table.qid AND search_table.word IN($querywords) GROUP BY search_table.qid ORDER BY score DESC";
Set that query to $search, and print out the results like so:


<? $getresults = mysql_query($search); $resultsnumber = mysql_numrows($getresults); IF ($resultsnumber == 0){ PRINT "Your search returned no results. Try other keyword(s)."; } ELSEIF ($resultsnumber > 0){ PRINT "Your search returned $resultsnumber results<BR>Listing them in order of relevance<BR><BR>"; for($count = 0; $count<$resultsnumber; $count++){ $body = mysql_result($getresults,$count,"blob"); $qid = mysql_result($getresults,$count,"qid"); //tighten up the results $body2print = substr($body, 0, 100); $cnote = $count+1; PRINT "$cnote. <a href=/old?u=http%3A%2F%2Fwww.devshed.com%2FServer_Side%2FPHP%2FSearch_Engine%2Fyourcontent.php3%3Fqid%3D%24qid%26gt%3B&y=1999 <i>$body2print...</i></a><BR>"; } } ?>
Presto, you've got keyword searching for your database, complete with relevancy ranking. It may not be Google or altavista.

It may not support all those fancy boolean operators, or excite's (*cough*) conceptual mapping technology. But it works, its quick and enough to handle your user's demand.


Click here to discuss this article
with other readers
. 28 comments.


Click here to receive updates on the latest articles.



Now Available:

Click to Order!

Search for books on PHP

Printer friendly versionPrinter friendly version

Developer News:
• Apache Cocoon 1.5 is released!
• Project Turbine Started
• JetSpeed 1.0B1 Released
• Jakarta goes live
•  More news..
•  Submit Your News..

Hot Forum Topics
Comparing Java Servlets and PHP
PHP for the PWS
Free ecommerce server setup
Copying IIS sites to another server
PHP without my hands on the wheel



Copyright © 1997-99 ngenuity. All rights reserved. Privacy Policy.