TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-04-2008, 08:58 PM   #1 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
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)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
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 offline  
Reply With Quote
Old 07-04-2008, 10:46 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
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)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

php tutorial on building a search engines using full text search - Google-sökning
codefreek is offline  
Reply With Quote
Old 07-05-2008, 03:44 PM   #5 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

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

See Also:
> PHP similar_text() Function
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
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: 281
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.
__________________
Nunchaku! Who doesn't like martial arts? =)
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 Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
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 Search this Thread
Search this Thread:

Advanced Search
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 11:39 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design