Adobe ColdFusion 8

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. Verity provides the following search enhancements:

  • Highlighting search terms
  • Providing alternative spelling suggestions
  • Narrowing searches using categories

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 by highlighting the returned search terms with bold type.

Create a search results page that includes term highlighting

  1. Create a ColdFusion page with the following content:
    Sep 26, 2008: corrected
    <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.

Providing alternative spelling suggestions

Many unsuccessful searches are the result of incorrectly spelled query terms. Verity can automatically suggest alternative spellings for misspelled queries using a dictionary that is dynamically built from the search index.

To implement alternative spelling suggestions, you use the cfsearch tag's suggestions attribute with an integer value. If the number of documents returned by the search is less than or equal to the value you specify, Verity provides alternative search term suggestions. In addition to using the suggestions attribute, you may also use the cfif tag to output the spelling suggestions, and a link through which to search on the suggested terms.

Note: Using alternative spelling suggestions incurs a small performance penalty. This occurs because the cfsearch tag must also look up alternative spellings in addition to the specified search terms.

The following example specifies that if the number of search results returned is less than or equal to 5, an alternative search term--which is displayed using the cfif tag--is displayed with a link that the user can click to activate the alternate search.

Create a search results page that provides alternative spelling suggestions

  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#">
        status = "info"
        suggestions="5"
        ContextPassages = "1"
        ContextBytes = "300"
        maxrows = "100">
    <h2>Search Results</h2>
    <cfoutput>
    Your search returned #codecoll_results.RecordCount# file(s).
    </cfoutput>
    <cfif info.FOUND LTE 5 AND isDefined("info.SuggestedQuery")>
        Did you mean:
        <a href="search,cfm?query=#info.SuggestedQuery#>#info.SuggestedQuery#</a>
    </cfif> 
    <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 any misspelled target words and click Search.

Narrowing searches by using categories

Verity lets you organize your searchable documents into categories. Categories are groups of documents (or database tables) that you define, and then let users search within them. For example, if you wanted to create a search tool for a software company, you might create categories such as whitepapers, documentation, release notes, and marketing collateral. Users can then specify one or more categories in which to search for information. Thus, if users visiting the website wanted to learn about a conceptual aspect of your company's technology, they might restrict their search to the whitepaper and marketing categories.

Typically, you will want to provide users with pop-up menus or check boxes from which they can select categories to narrow their searches. Alternately, you might create a form that lets users enter both a category name in which to search, and search keywords.

Create a search application that uses categories

  1. Create a collection with support for categories enabled.
  2. Index the collection, specifying the category and categoryTree attributes appropriate to the collection.

    For more information on indexing Verity collections with support for categories, see Indexing collections that contain categories.

  3. Create a search page that lets users search within the categories that you created.

    Create a search page using the cfsearch tag that lets users more easily search for information by restricting searches to the specified category and, if specified, its hierarchical tree.

    For more information on searching Verity collections with support for categories, see Searching collections that contain categories.