TalkPHP
 
 
Account Login
Latest Articles
» How to keep your forms from double posting data
» cURL Basics
» Securing your PHP applications Part 1
» The way the function rolls
» Database Abstraction with Zend_Db - Part 2
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Display Modes
Old 07-04-2008, 08:58 PM   #1 (permalink)
The Acquainted
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 160
Thanks: 5
CoryMathews is on a distinguished road
Default Search

Just wondering if anyone, who has implemented a search, would be willing to share the code behind it.

NOTE: I am looking for more then a simple query using like.
CoryMathews is offline  
Reply With Quote
Old 07-04-2008, 10:40 PM   #2 (permalink)
TalkPHP Loves You
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Nottingham
Posts: 1,448
Thanks: 72
Wildhoney is on a distinguished road
Default

How about using full text search, or taking a look at Lucene?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is online now  
Reply With Quote
Old 07-04-2008, 10:46 PM   #3 (permalink)
The Gregarious
Upcoming Programmer Inquisitive 
 
Join Date: Sep 2007
Posts: 540
Thanks: 64
Tanax is on a distinguished road
Default

So what "more" are you looking for? A search is just a simple thing..
Tanax is offline  
Reply With Quote
Old 07-05-2008, 12:38 PM   #4 (permalink)
The Addict
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 283
Thanks: 166
codefreek is on a distinguished road
Default

php tutorial on building a search engines using full text search - Google-sökning
__________________
inquisitive
1. Eager to acquire knowledge.
2. Too curious; overly interested; nosy.
codefreek is offline  
Reply With Quote
Old 07-05-2008, 03:44 PM   #5 (permalink)
The Acquainted
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 163
Thanks: 32
ETbyrne is on a distinguished road
Default

This is what I use:
> PHP: similar_text - Manual

See Also:
> PHP similar_text() Function
__________________
My Website > http://www.evanbot.com
ETbyrne is online now  
Reply With Quote
Old 07-05-2008, 04:58 PM   #6 (permalink)
The Wanderer
 
Rizza's Avatar
 
Join Date: Dec 2007
Location: Orlando, FL
Posts: 23
Thanks: 0
Rizza is on a distinguished road
Default

Quote:
Originally Posted by ETbyrne View Post
I would definitely encourage you to find something else to process your searches. The similar_text function is night and day slower than using the database to search with. Even Regex Like in MySQL is faster and that's pretty sad. The problem with using similar_text is...

1. You need to load all data you want into PHP (that means you have HUGE memory overhead)
2. It only accepts strings, which means you're forced to throw it into a loop of some sort.
3. It only returns a percentage value, which means you need to either store another array or replace the key for each array item that you're searching through.
4. Once it's all said and done, you have to sort the array, then pop off the number of items you want.

That's dirty. If you ever have to search for anything over say... 100 rows you'll be paying for it horribly, especially if there are a lot of people that are using that search functionality.

Use Lucene. It takes more setup but its far better than any other options out there and once you've set it up once, you know how to set it up way faster the next time. FULLTEXT is easy, but primitive and has significant downfalls, especially if you have a small indexible database or your indexed content has a lot of the same content.
__________________
HYDRA Studio!
Rizza is offline  
Reply With Quote
Old 07-05-2008, 05:13 PM   #7 (permalink)
Jim
The Addict
 
Jim's Avatar
 
Join Date: Nov 2007
Location: the Netherlands
Posts: 221
Thanks: 2
Jim is on a distinguished road
Default

I personally dislike FULL TEXT, the reason for that is because your keyword must be at least 4 keys long.

This gave me problems when a user wanted to find my PHP IRC BOT tutorial and went searching only with "IRC". And people wont keep searching until they found the correct keyword.

The remedy for this problems was lowering the minimal keyword size in the mysql boot config (while starting it from cli), but that must be done as a server admin. So people on shared webhosts arent able to do that themself.
Send a message via MSN to Jim Send a message via Skype™ to Jim
Jim is offline  
Reply With Quote
Old 07-05-2008, 05:16 PM   #8 (permalink)
The Wanderer
 
Rizza's Avatar
 
Join Date: Dec 2007
Location: Orlando, FL
Posts: 23
Thanks: 0
Rizza is on a distinguished road
Default

Like I said, there are some significant draw backs. The index must have 3 or more words in the index entry, all words containing 4 or more characters (by default). If you have high word saturation (like my company had an issue with "Orlando" in a project), FULLTEXT will ignore it until there is less total saturation of that word.
__________________
HYDRA Studio!
Rizza is offline  
Reply With Quote
Old 07-05-2008, 05:31 PM   #9 (permalink)
The Acquainted
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 160
Thanks: 5
CoryMathews is on a distinguished road
Default

Well I have spent the last about 3-4 hours looking into this more and more reading about 15 terrible tutorials and lots from the mysql site and have come up with this search method.

It requires a full text search on the fields given so they must varchars, text fields ect.

Anyways heres the query.

Code:
SELECT *,
  MATCH(`FullName`, `Description`, `Category`)
  AGAINST('".$searchString."') AS Relevance 
  FROM `TestTable` 
  HAVING Relevance > 0.2
  ORDER BY Relevance DESC
");
Running it on about 300 rows seems pretty quick still. The Description field is about a paragraph of text and the other 2 are usually just a word or 2.
(27 total, Query took 0.0015 sec)

Thanks for the help guys it pointed me in the right direction. Also if anyone see's any problems with this please let me know.


Ye the 3 character min is going to be a problem and I am on a shared server right now so I guess I will just have to check before searching and tell the user they must input more then 3 characters.
CoryMathews is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 05:13 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0