Jump to content

Search for synonyms


Chinese

Recommended Posts

Hey,

at first I really like your board, imho it's fairly better than the german boards.

Yes I'm from germany  8)

so i got a question.

I developed a search engine and now im trying to find a solution, how im also able to find synonyms.

Thats why i made a table with this syntax

 id | word | synonym
1 | car | 1
2 | automobile | 1
3 | 05 | 3
4 | 5 | 3

(just an example - the german one would be better, because i dont speak english-slang well)

If i search "automobile" the result should include the results of "car", too - logical.

But that's not a problem with this code.

if ($search = trim($_GET['q'])) {
  	if (!get_magic_quotes_gpc()) $search= addslashes($search);
    if (strlen($search) > 50) die('Interrogation too long');
     
    require('verbindung.php');
    
    $synonymquery = " SELECT word
                        FROM `synonyme`
                        WHERE wort != '$search[0]'
                        AND (
                              synonym = (
                                SELECT synonym
                                FROM synonyme
                                WHERE wort = '$search[0]' )
                              OR id = (
                                SELECT synonym
                                FROM synonyme
                                    WHERE word = '$search' )
                              OR synonym = (
                                SELECT id
                                FROM synonyme
                                WHERE word = '$search[0]' )
                        )";                    
    
  	$result = mysql_query($synonymquery);

    while ($suche = mysql_fetch_array($result) or die (mysql_error())) {

    // rest of the search

    }
}

 

Now my question:

If i search two synonyms at once, it doesnt work. In this case "automobile 5" would be such a search-term.

I thought at a foreach-loop, but the foreach-loop would search for "automobile" and then for "5" and not for "autombile 5".

 

I hope youll get the sense.

 

Would you be so kind to help me?  :)

 

thanks and best wishes from germany,

Chinese

Link to comment
https://forums.phpfreaks.com/topic/152593-search-for-synonyms/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.