Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time

TextSnipper.cfc

Utility for creating snippets of documents on a search results page.

Tell it how long you want your snippet to be (in characters) and what keywords to find/highlight. Pass an HTML string to the snip() function and it will return a relevant substring with keywords highlighted. It takes care of little annoyances: stripping unwanted HTML, starting and stopping at word boundaries, and adding ellipses where necessary.

Example

	<cfset snipper = createObject("component", "TextSnipper")>
	<cfset snipper.setMaxLength(600)>    	
	<cfset snipper.setKeywords("Kobe,LeBron")>  
	<cfoutput>#snipper.snip(articleBody)#</cfoutput>

… Lakers G Kobe Bryant in terms of popularity in the country. Rovell: “Kobe is clearly bigger than LeBron. I’d say he’s at least two times bigger, and the reason for that is that Chinese really do respect a champion.” Rhoads: “For LeBron and Team LeBron, the ultimate objective has to be to get those rings onto LeBron’s …

Notes

  • setMaxLength() is optional. The default maxLength is 250 characters.
  • setKeywords() is optional. If no keywords are found, the first part of the text will be snipped.
  • It's chainable: #snipper.setMaxLength(300).setKeywords("foo,bar").snip()#

About

Utility for creating snippets of documents on a search results page.

Resources

Releases

No releases published

Packages

No packages published