0

For the search feature on my site, the user searches for a term or a phrase then it gets processed and using the "LIKE" query to the mysql database - the relevant results are gotten. then they are shortened to 500 characters so snippets of the matching results are shown to the person searching. Only problem with this is that often the word which matched isn't in the 500chars (shortened) result and the user of the search engine may think its not working since the result isnt being displayed in the snippet.

Any (easy) ways around this?

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by asif49
0

A couple of thoughts:

  • Precede every entry with the keyword(s) that they entered, then the 500 char just to emphasize that there is a connection.
  • Scan each entry for the keyword / phrase and then show the result as "...keyword remaining 4xx characters" Thus the result in these cases will start with the keyword with whatever follows it.

Edited by chrishea: n/a

0

I'm not quite sure what you meant there^^

Here's the code I use for limiting it to 500 chars, how would this code be changed to do what you just said:

/*limit how many chars to display*/
  if (strlen($content) > 500)
  {
  $position=500; 
  $post = substr($content,$position,1); // find what is the last character displaying by getting only last one character from the display message.
  while($post !=" "){ //until space is found
  $position++;
  $post = substr($content,$position,1); 
  }
  $post = substr($content,0,$position); 
  $content = $post . "..."; //only put ellipsis at the end if there's no dot there already
  }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.