Jump to content

search result page


PrMa

Recommended Posts

Ok, I have a search function on my webpage, but there are one problem that I can't overcome.

 

The search is a BOOLEAN fulltext search, and the result is displayed as following: "text text text text text  KEYWORD text text text text text"

 

However, this only works when I'm searching for a single word, or exact phrase.

 

So to the problem: Whenever I'm using any boolean operators, the presented result will be the first part of the searched string. Like: "Text text text text text text text text text" The keyword, in this case won't even be shown in the result.

 

How shall i change my code so the presented result doesn't get affected by the boolean operators, and still shown as "text text text text text  KEYWORD text text text text text"?

 

Yeah, and if two or more searchwords are present, I want the first one to be displayed in the middle of the string.

 

This is how i get and present the result:

 

$q = mysql_query("SELECT * FROM tbl WHERE MATCH (conts) AGAINST ('$_GET[s]' IN BOOLEAN MODE)") or die(mysql_error());
while($r = mysql_fetch_array($q)){


echo "<span class=rubrik><a target=_self href=\"".$r['url']."\">",$r['title']."</a></span><br>... ";
echo substr($r['conts'], stripos($r['conts'],$_GET[s])-55, 110);
echo " ...<br>";
echo "<a target=_self href=\"".$r['url']."\">",$r['url']."</a><br><br>";

 

 

Hope someone have a solution to this :)

Link to comment
Share on other sites

Read my Comment, Try this:

 

<?php
//modify "title, content,URL,id" to the fields you use (check all lines)
$query_count = "SELECT SQL_CALC_FOUND_ROWS
  title,
  content,
  URL,
  id
FROM $searchType
  WHERE
    MATCH(URL,title,content) AGAINST ('$searchQuery' IN BOOLEAN MODE) AND
content IS NOT NULL
LIMIT $limitvalue, $limit";

$sql = mysql_query($query_count)or die(mysql_error()); 
$result_count = mysql_query("SELECT FOUND_ROWS()")or die(mysql_error());
$total = mysql_fetch_array($result_count);
$totalrows = $total[0];



echo 'Found '.$totalrows.' Results';

while($r = mysql_fetch_array($q)){


echo "<span class=rubrik><a target=_self href=\"".$r['url']."\">",$r['title']."</a></span><br>... ";
echo substr($r['conts'], stripos($r['conts'],$_GET[s])-55, 110);
echo " ...<br>";
echo "<a target=_self href=\"".$r['url']."\">",$r['url']."</a><br><br>";
?>

Link to comment
Share on other sites

Thanks for the comment!

 

It didn't sovle my problem tough. Or maybe I just don't understand it.

 

However, when I execute the search using your method, I get this:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 10

 

Line 10 is: LIMIT $limitvalue, $limit";

 

If i take that line away, the search works exaktly the same way as before = not wanted.

 

So, what am I missing?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.