function openthesaurus_searchSynonyms($query)
{
    $start = getmicrotime();
    $items = array();
    $query_str = sprintf("\n\t\tSELECT words.id AS word_id, word, meaning_id\n\t\tFROM words, word_meanings, meanings\n\t\tWHERE \n\t\t\tword = '%s' AND\n\t\t\twords.id = word_meanings.word_id AND\n\t\t\tword_meanings.meaning_id = meanings.id AND\n\t\t\tmeanings.hidden = 0\n\t\n\t\tUNION\n\n\t\tSELECT words.id AS word_id, word, meaning_id\n\t\tFROM words, word_meanings, meanings\n\t\tWHERE \n\t\t\tlookup = '%s' AND\n\t\t\twords.id = word_meanings.word_id AND\n\t\t\tword_meanings.meaning_id = meanings.id AND\n\t\t\tmeanings.hidden = 0\n\n\t\tORDER BY word", myaddslashes($query), myaddslashes($query), myaddslashes($query), myaddslashes($query));
    $db = new DB_Thesaurus();
    $db->query($query_str);
    $synmatches = 1;
    if ($db->nf() == 0) {
        $item['words'] = array();
        $items[] = $item;
    }
    while ($db->next_record()) {
        $mid = $db->f('meaning_id');
        $item['words'] = getSynsetWithUsage($db->f('meaning_id'), 1);
        $items[] = $item;
    }
    $_GET['search'] = 1;
    # otherwise logSearch ignores the search
    logSearch($db, $query, $db->nf(), 0, getEndTimer(), 1);
    XMLRPC_response(XMLRPC_prepare($items), KD_XMLRPC_USERAGENT);
}
include "../include/substring_matches.php";
?>

<?php 
if (uservar('word') && trim(uservar('word')) != "") {
    ?>
	<p><a href="add.php?word=<?php 
    print urlencode($_GET['word']);
    ?>
"><?php 
    print sprintf(_("Add '%s' and synonyms to the thesaurus"), escape($_GET['word']));
    ?>
</a></p>
<?php 
}
?>

<script type="text/javascript">
<!--
	document.f.word.focus();
	document.f.word.select();
// -->
</script>

<?php 
if ($queryterm != "") {
    externalSearchLinks($_GET['word']);
}
logSearch($db, $_GET['word'], 0, 0, getEndTimer());
include "../include/bottom.php";
page_close();
        ?>
		<a href="add.php?id=<?php 
        print $word_id;
        ?>
"><?php 
        print sprintf(_("Add another meaning of '%s' to the thesaurus"), escape($words[$i]));
        ?>
</a><br />
		<?php 
        $i++;
    }
    if (!in_array($word, $words)) {
        ?>
		<a href="add.php?word=<?php 
        print urlencode($_GET['word']);
        ?>
"><?php 
        print sprintf(_("Add '%s' and synonyms to the thesaurus"), escape($_GET['word']));
        ?>
</a>
	<?php 
    }
}
?>

<br />
<?php 
include "../include/external_searches.php";
logSearch($db, $word, $db->nf(), 0, getEndTimer());
include "../include/bottom.php";
page_close();
					</td>
			</tr>
		<?php 
		} 
		?>
		</table>
	</td>
</tr>

<tr><td></td></tr>

<?php if( array_key_exists('word', $_GET) ) { ?>
	<tr>
		<td></td>
		<td colspan="3"><a href="add.php?word=<?php print $_GET['word']; ?>"><?php print sprintf(T_("Add another meaning of '%s' to the thesaurus"), escape($_GET['word'])) ?></a></td>
	</tr>
<?php } ?>

</table>

</form>

<?php
if( isset($_GET['word']) ) {
	logSearch($db, $_GET['word'], $matches_for_log, 0, getEndTimer());
}

include("include/bottom.php");
page_close();
?>
if ($queryterm != "") {
    include "../include/external_searches.php";
}
?>
	</td>
	<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
	<td class="compact" width="65%" valign="top">
		<?php 
if (uservar('word') && $queryterm != "") {
    ?>
			<p class="compact"><strong>Aktionen:</strong></p>
			<ul class="compact">
				<li><a href="add.php?word=<?php 
    print urlencode($_GET['word']);
    ?>
"><?php 
    print sprintf(_("Add '%s' and synonyms to OpenThesaurus"), escape($_GET['word']));
    ?>
</a></li>
			</ul>
		<?php 
}
?>
	</td>
</tr>
</table>

<?php 
logSearch($db, $_GET['word'], $synmatches, 0, getEndTimer());
include "../include/bottom.php";
page_close();
}
?>

<?php 
if (uservar('word')) {
    ?>
	<a href="add.php?word=<?php 
    print urlencode($_GET['word']);
    ?>
"><?php 
    print sprintf(T_("Add '%s' to the thesaurus"), escape($_GET['word']));
    ?>
</a>
<?php 
}
?>

<script type="text/javascript">
<!--
	if( document.f && document.f.word ) {
		document.f.word.focus();
		document.f.word.select();
	}
// -->
</script>

<?php 
externalSearchLinks($_GET['word']);
logSearch($db, $_GET['word'], sizeof($results), 1, getEndTimer());
include "include/bottom.php";
page_close();