RE: [PHP] Information Retrieval.. help
| From: | Matt Schroebel | Date: | Tue, 05 Nov 2002 20:01:14 +0000 |
| Subject: | RE: [PHP] Information Retrieval.. help | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-122856@lists.php.net to get a copy of this message | ||
Why don't you use full text search, which creates a score?
Two tutorials:
http://www.mysql.com/doc/en/Fulltext_Search.html
http://www.zend.com/zend/tut/tutorial-ferrara1.php
The match words need to be at least 3 characters in length or you'll get
no results.
> -----Original Message-----
> From: Kevin Stone [mailto:kevin@helpelf.com]
> Sent: Tuesday, November 05, 2002 2:44 PM
> To: php-general@lists.php.net
> Subject: [PHP] Information Retrieval.. help
>
>
> Hey list! I have written several simple search scripts to
> retrieve basic data.. that is to say I wasn't worried about
> the actual relevancy of what I was retrieving. Now I need to
> write a search script that retrieves information based on the
> search terms in order of relevancy. It doesn't have to
> feature boolean operations but it does have to be fast and
> flexible. This is what I have so far.
>
> The database contains:
> ID Description
> -- ------------
> 1 jade gold ring
> 2 grandmas golden ring with leaves
> 3 silver and gold diamond bracelet
>
> The user enters the search string:
> "ring gold leaves"
>
> I split the string into words and query them separately:
> "SELECT ID FROM jewlry WHERE description LIKE \"%ring%\""
> returns 1,2
> "SELECT ID FROM jewlry WHERE description LIKE \"%gold%\""
> returns 1,2,3
> "SELECT ID FROM jewlry WHERE description LIKE \"%leaves%\"" returns 2
>
> Then I combine the results into one array and use
> arraycountvalues() to eliminate redundencies and count the
> number of occurances of each row. The number of occurances
> of a row should be equal to its relevancy so I sort the array
> by value:
> array (
> 2 => 3,
> 1 => 2,
> 3 => 1);
>
> Hopefully that wasn't too hard to follow. I as examine my
> code I get the distinct impression that this is an
> extraordinarily Primative method. :) If so do you have any
> suggestions for improving it or can you please point me to
> resources (tutorials, books, websites, etc..) that would help
> me develope more a sophisticated technique?
>
> Much appreciated!
> Kevin Stone
> kevin@helpelf.com
>
>