Enhancing search results

ColdFusion lets you enhance the results of searches by letting you incorporate search features that let users more easily find the information they need. The following search enhancements are available through Verity:

Highlighting search terms

Term highlighting lets users quickly scan retrieved documents to determine whether they contain the desired information. This can be especially useful when searching lengthy documents, letting users quickly locate relevant information returned by the search.

To implement term highlighting, use the following cfsearch attributes in the search results page:

Attributes Description

ContextHighlightBegin

Specifies the HTML tag to prepend to the search term within the returned documents. This attribute must be used in conjunction with ContextHighlightEnd to highlight the resulting search terms. The default HTML tag is <b>, which highlights search terms using bold type.

ContextHighlightEnd

Specifies the HTML tag to append to the search term within the returned documents.

ContextPassages

The number of passages/sentences Verity returns in the context summary (the context column of the results). The default value is 0; this disables the context summary.

ContextBytes

The total number of bytes that Verity returns in the context summary. The default is 300 bytes.

The following example adds to the previous search results example, highlighting the returned search terms with bold type.

To create a search results page using term highlighting:

  1. Create a ColdFusion page with the following content:
    <html>
    <head>
    	<title>Search Results</title>
    </head>
    <body>
    <cfsearch 
    	name = "codecoll_results"
    	collection = "CodeColl"
    	criteria = "#Form.Criteria#">
    	ContextHighlightBegin="<b>"
    	ContextHighlightEnd="</b>"
    	ContextPassages="1" 
    	ContextBytes="500"
    	maxrows = "100">
    <h2>Search Results</h2>
    <cfoutput>
    Your search returned #codecoll_results.RecordCount# file(s).
    </cfoutput>
    
    <cfoutput query="codecoll_results">
    	<p>
    	File: <a href="#URL#">#Key#</a><br>
    	Document Title (if any): #Title#<br>
    	Score: #Score#<br>
    	Summary: #Summary#<br>
    	Highlighted Summary: #context#</p>
    </cfoutput>
    </body>
    </html>
    
  2. Save the file as collection_search_action.cfm.

    Note: This overwrites the previous ColdFusion example page.

  3. View collection_search_form.cfm in the web browser:
  4. Enter a target word(s) and click Search.

View comments in LiveDocs