News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Search Algorithms

Started by Big P, August 11, 2003, 10:35:31 AM

Previous topic - Next topic

Big P

I've never written a search algorithm before, but took a stab at one today:


<style type="text/css">
.highlight {
        background-color: yellow;
        font-weight: bold;
        color: black;
}
</style>
<form method="post" action="search.php">
<input type="text" name="query" /><br />
<input type="submit" name="Submit!" />
</form>
<br />
<br />
<?
  $qs = mysql_query('SELECT subject, titletext, maintext FROM phpnews_news WHERE subject RLIKE "{<{:<:]]' . $_POST['query'] . '{<{:>:]]" OR titletext RLIKE "' . $_POST['query'] . '" OR maintext RLIKE "' . $_POST['query'] . '" LIMIT 5');

  while($results = mysql_fetch_array($qs))
  {
    /* Highlight Search Words */
    $results['subject'] = str_replace($_POST['query'], '<b class="highlight">' . $_POST['query'] . '</b>', $results['subject']);
    $results['titletext'] = str_replace($_POST['query'], '<b class="highlight">' . $_POST['query'] . '</b>', $results['titletext']);
    $results['maintext'] = str_replace($_POST['query'], '<b class="highlight">' . $_POST['query'] . '</b>', $results['maintext']);

    echo '
    <p>
      <b>Subject:</b> ' , $results['subject'] , '<br />
      <b>Titletext:</b> ' , $results['titletext'] , '<br />
      <b>Maintext:</b> ' , $results['maintext'] , '<br />
    </p>';
  }
 
  exit;


Could anyone recommend any ways of improving this? Basically phpnews_news is where all the news is stored, and 'subject', 'titletext' & 'maintext' are the fields that are being searched. :)
PHPNews has been released! Download it now!

Read My Blog!

[Unknown]

Grr... someone messed up preparsecode... (probably me :$.)
Those {<{ are supposed to be two [ next to each other.

That looks fine... I see nothign wrong with it.  Have you looked at the discussion on search engine methods in errm... *the place*?

-[Unknown]

Big P

PHPNews has been released! Download it now!

Read My Blog!

Advertisement: