* Segis-Eresmas
> I have a table with a Text field (with texts) and Fulltext index.  When
> I search a word (...) f.e. 'with match...against...', How can i do it to
> see the line and the line number of the text in that text-field?

There is no such functionality in mysql, you would have to implement this in
your application. PHP example:

$searchwords = explode(" ",$searchcrit);
$q = "SELECT * FROM mytable WHERE MATCH (textcol) AGAINST ($searchcrit)";
$result = mysql_query($q) or die(mysql_error());
while($myrow = mysql_fetch_array($result)) {
  $candidates = Array();
  $score = 0;
  $line_number = 0;
  $lines = explode("\n",$myrow["textcol"]);
  foreach ($lines as $line) {
    $line_number += 1;
    foreach ($searchwords as $searchword) {
      if (strpos($line,$searchword)!==false) $score += 1;
    }
    if ($score > 0) $candidates[] = array($score,$line,$line_number);
  }
  sort($candidates);
  list($best_score,$best_match,$line_number) = array_pop($candidates);
  output_result_line($myrow,$best_match,$line_number);
}

This code snippet is not tested, there may be errors. The idea is to count
the number of found searchwords for each line in the textcolumn, to
determine which of the lines best match the search criteria. The more words,
or the more times a search word is encountereed on a line, the higher score
it gets. The sorting is supposed to put the highest score at the end of the
list, array_pop() should retrieve it. If your search criteria can contain
words with a + or - prefix (or other operators, see the manual), you must
handle that in the code. I suppose the + character should be ignored or
increase the score, and when a - character prefix is encountered, the word
should be ignored.

<URL: http://www.mysql.com/doc/en/Fulltext_Search.html >

--
Roger


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to