Re: search
| From: | Steve Werby | Date: | Tue, 03 Jul 2001 14:18:50 +0000 |
| Subject: | Re: search | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-55985@lists.php.net to get a copy of this message | ||
"AJDIN BRANDIC" <abrandic@coventry.ac.uk> wrote:
> I've got search facility (php-mysql) which is very simple. If i search
> for 'dog' it will find any records containing words 'dog' or
> 'dogs' or
> 'dogowner' etc. But if I search for 'dogs', words 'dog' and
> 'dogowner'
> will not be found. This is a classic case so there must be a solution to
> it but I cannot find one. I tried to do something like
> if word is 'dogs' then I do the search,
> then break word 'dogs' into an array and check if the last element is an
> 's'. If it is remove it, reconstrust the string,which will give 'dog',
> and do search for that too.
> Then display results. Well I connot find a way of breaking a string into
> an array. How do I break 'mynameis' into an array of 8 elements?
> This has got loopholes but still it is better than what I have now.
Ajdin, you may want to take a look at mnoGoSearch, which is search engine
software with a C indexer, PHP front-end and ability to work with numerous
databases, including MySQL. It's a great program, but even if it's not
suitable for what you're doing I suggest looking at the PHP code and
database structure. mnoGoSearch has incorporated the ability to search for
related words by incorporating a dictionary file and a database table of
grammar rules so a search for one word can be made to find other forms of
that word.
FYI, to break a string into an array like you describe use strlen() to get
the length of the string, substr() to pull out the first N characters from
the string, then loop through and add each element to an array by adding as
follows (pseudocode):
for ( $i = strlen( $string ); $i >= 0; $i-- )
$array[] = substr( $string, 0, $i );
--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/