# Building a Search Interface

Now that you've created and indexed a searchable data source, you need to build a search interface to allow users to access the data source. The CFSEARCH tag provides users with a set of operators and modifiers to create sophisticated query expressions. We'll explore these options in detail below, but first let's take a look at getting a basic search application up and running.

## Using the Verity wizard in Studio

To quickly create a search application for an existing collection, click the File > New command in ColdFusion Studio and select the Verity Wizard in the CFML tab of the New Document dialog. The wizard creates a set of application pages based on the entries you make in the wizard dialogs.

You can customize the search interface by adding instructional text for users and applying styles to the form pages.

## Basic search operations

| To search the collection:

1. Create a new file in Stuio.
2. Modify the file so that it appears as follows:

       <HTML>
       <HEAD>
           <TITLE>Select the collection to search</TITLE>
       </HEAD>

       <BODY>
       <H2>Search</H2>

       <FORM METHOD="Post" ACTION="collectionsearchaction.cfm">
           <P>Enter the collection you want to search:
           <INPUT TYPE="text" NAME="collection" SIZE="25" MAXLENGTH="35"></
       P>
           <P>Select the type of search:<BR>
           <INPUT TYPE=radio
               NAME=type
               VALUE=Simple checked> Simple<BR>
           <INPUT TYPE=radio
               NAME=type
               VALUE=Explicit> Explicit<BR>

           <P>Enter a search string:</P>
           <INPUT TYPE=text
               NAME=searchstring SIZE=50>

           <P><INPUT TYPE=submit
               NAME=search1
               VALUE="Search">
           <INPUT TYPE=reset
               VALUE="Reset">
       </FORM>

       </BODY>
       </HTML>

3. Save the file as `collectionsearchform.cfm`.

| To present the results of the search to the user:

1. Create a new file in Stuio.
2. Modify the file so that it appears as follows:

       <HTML>
       <HEAD>
           <TITLE>Search output template</TITLE>
       </HEAD>

       <BODY>
       <CFSEARCH NAME="Search1"
           COLLECTION="#form.collection#"
           FORM TYPE="#form.type#"
           CRITERIA="#form.searchstring#">

       <H2>Search Results</H2>

       <CFOUTPUT>
           #Search1.RecordCount# found out of
           #Search1.RecordsSearched# searched.
       </CFOUTPUT>

       <HR NOSHADE>
           <CFOUTPUT QUERY="Search1">
               <A HREF="#Search1.URL#">#Search1.title#</A><BR>
           </CFOUTPUT>
       <HR NOSHADE>
       </BODY>
       </HTML>

3. Save the file as `collectionsearchaction.cfm`.
4. View the file `collectionsearchform.cfm` in your browser, enter values in the form, then submit it.

## Summarization

As part of the indexing process, Verity automatically produces a summary of every document file or query result set. The default summarization selects the best sentences, based on internal rules, up to a maximum of 500 characters. Summarization information is returned by default with every CFSEARCH operation. For more information on this topic, see the Allaire Knowledge Base article, "Custom1, Custom2 and Summary Fields" (ID# 1081) on our Web site at http://www.allaire.com/Support/KnowledgeBase/SearchForm.cfm.

To access the summary, invoke the property in the following form:

    #search_query.Summary#

For example, in a search operation where the value of the NAME attribute is "mysearch" the following CFML outputs the summary of the search results:

    <CFOUTPUT QUERY="mysearch">
        #Summary#<BR>
    </CFOUTPUT>

For information on an advanced summarization technique, see the Allaire Knowledge Base article, "Synchronizing information stored in Verity Collection Document Fields with Corresponding Data from a Database" (ID# 1161) on our Web site at http://www.allaire.com/Support/KnowledgeBase/SearchForm.cfm.

## CFSEARCH properties

Three properties are generated for each CFSEARCH query that provide information about a particular query:

- RecordCount -- The total number of records returned by the query.
- CurrentRow -- The current row of the query being processed by CFOUTPUT.
- RecordsSearched -- The total number of records in the index that were searched. If no records were returned in the search, this property returns a null value.