close ad
Help us test the new Databridge BETA with MySQLi support
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

found search text - highlight and crop the result

Thread began 11/17/2009 4:26 am by office377308 | Last modified 11/18/2009 2:58 pm by Dave Buchholz | 1173 views | 5 replies |

office377308

found search text - highlight and crop the result

I do a full text search in a mysql database field. The result works as expected, but I need 2 more things on the result page:
1) I want to show only part of the text found. It should serve as a link.
2) I want to emphasize the search word within this text part.

Is there a function somewhere which does the job similar to Tom Mucks

Dynamic Search Extension Suite for PHP in extensions/ ?

any idea?
thanks

Sign in to reply to this post

Dave BuchholzBeta Tester

Interesting question, this is something I would like to see incorporated into DataAssist Search as well.

Sign in to reply to this post

Jason ByrnesWebAssist

1) to show only a part of a string, use the substr() function.

the substr() function takes 3 arguments:
the string
starting character
ending character

to show the first 11 characters of a string use:
<?php echo substr($row_RSName['ColumnName'], 0, 12); ?>

2) I will add a feature request for adding search string highlighting to DataAssist search. For now though, you would need to hand code this. I was able to find a number of examples of how to accomplish this using javascript through google:

search?q=javascript+highlight+search+text&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

Sign in to reply to this post

Dave BuchholzBeta Tester

Jason,

the only issue I have with your suggestion is that personally I would want the search term to appear in the text displayed with a set number of words either side of it and what you suggest doesn't guarantee it.

Sign in to reply to this post

Jason ByrnesWebAssist

That would be a much more complex bit of code.


you could explode the string into an array, then loop through the array to find the search phrase then show it along with the word before or after. A very quick sample of the code for that would look like:

php:
<?php 

$searchPhrase 
"this is some stuff on my page, I hope you like it";
$searchTerm "stuff";
$searchIndex "";
$searchArray explode(" "$searchPhrase);
foreach(
$searchArray as $key  => $value) {
    if(
$value == $searchTerm$searchIndex $key;
}
echo(
$searchArray[$searchIndex-1]." <span style=\"color:red;\">".$searchArray[$searchIndex]."</span> ".$searchArray[$searchIndex+1]);
?>





of course, there are a number of scenarios this code does not account for, what if the search phrase is the first word? last word? it is meant as an example of one direction you could go.

Sign in to reply to this post

Dave BuchholzBeta Tester

Originally Said By: Jason Byrnes
  That would be a much more complex bit of code.  



I know :-)

Thanks for the ideas at some point in the near future I'll look at this in more detail.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...