AcidReignX
Programmer
I'm trying to create a search engine for my site, but I can't seem to find any MYSQL options for weighting the queries. And I'm almost positive that I had found them a couple months ago. Are they only available in certain versions? Basically what I need is a clone of an engine like they have on the mysql site, though a clone of google, yahoo, msn, etc... might be easier since more people are familiar with the context. I'm tried to use Regular Expressions to get the issue resolved, but unfortunately it will return a lot of queries that I'm not interested in receiving. So my question is how do I forgo this problem?
I've probably started out the wrong way, so smack me in the face if this looks completely wrong... at any rate, this is what I have (essentially):
<code>
<?php
// [CHANGE] rain forest "tropical birds" [TO] rain|forest|"tropical|birds" [FOR REGEXP]
$words = str_replace("|", " ", trim($_GET['query']));
$query = "SELECT * FROM engine WHERE hotkeys REGEXP '(" . $words . ")' OR description REGEXP '(" . $words . ")' ORDER BY rank";
$result = @mysql_query($query);
while($fetch = @mysql_fetch_array($result, MYSQL_ASSOC))
{
// Output the line
echo "
<div class='show_query'>
<div class='query_title'>" . $fetch['title'] . "</div>
<div class='query_description'>" . $fetch['description'] . "</div>
</div>";
}
?>
</code>
I realize that double quotes in my search are completely useless as of right now, too, but I wanted to point those out. My goal is to have the output that is MOST RELATED to the user's input to be listed. The "order by" function here is pretty much useless, because the query is still going to output anything with the word "rain" in it, even if it is entirely unrelated to the rain forest. Hence the need for stuff like quotes and matching it with something like "forest". If there is some sort of command or function available for mysql that would allow such weighting, that in particular is what I'm looking for. However, if anybody here is familiar with making an engine like this, that would ideal =) because I could sure use some pointers.
Thanks in advance =)
I've probably started out the wrong way, so smack me in the face if this looks completely wrong... at any rate, this is what I have (essentially):
<code>
<?php
// [CHANGE] rain forest "tropical birds" [TO] rain|forest|"tropical|birds" [FOR REGEXP]
$words = str_replace("|", " ", trim($_GET['query']));
$query = "SELECT * FROM engine WHERE hotkeys REGEXP '(" . $words . ")' OR description REGEXP '(" . $words . ")' ORDER BY rank";
$result = @mysql_query($query);
while($fetch = @mysql_fetch_array($result, MYSQL_ASSOC))
{
// Output the line
echo "
<div class='show_query'>
<div class='query_title'>" . $fetch['title'] . "</div>
<div class='query_description'>" . $fetch['description'] . "</div>
</div>";
}
?>
</code>
I realize that double quotes in my search are completely useless as of right now, too, but I wanted to point those out. My goal is to have the output that is MOST RELATED to the user's input to be listed. The "order by" function here is pretty much useless, because the query is still going to output anything with the word "rain" in it, even if it is entirely unrelated to the rain forest. Hence the need for stuff like quotes and matching it with something like "forest". If there is some sort of command or function available for mysql that would allow such weighting, that in particular is what I'm looking for. However, if anybody here is familiar with making an engine like this, that would ideal =) because I could sure use some pointers.
Thanks in advance =)