# Indexing CFPOP Query Results

The contents of mail servers are generally quite volatile; specifically, the MessageNumber is reset as messages are added and deleted. To avoid mismatches between the unique MessageNumber identifiers on the server and in the Verity collection, it's a good idea to re-index the collection before processing a search.

As with the other query types, you need to provide a unique value for the KEY attribute and enter the data fields to index in the BODY attribute.

    <!--- Run POP query --->
    <CFPOP ACTION="getall"
        NAME="p_messages
        SERVER="mail.mycompany.com"
        USERNAME="user1"
        PASSWORD="user1">

    <!--- Output POP query result set --->
    <CFOUTPUT QUERY="p_messages">
        #MESSAGENUMBER# <BR>
        #FROM# <BR>
        #TO# <BR>
        #SUBJECT# <BR>
        #BODY# <BR>
    =========================<BR>

    <!--- Index result set --->
    <CFINDEX ACTION="update"
        COLLECTION="pop_query"
        KEY="messagenumber"
        TYPE="custom"
        TITLE="subject"
        QUERY="p_messages"

        BODY="body">

    <!--- Search messages for the word "action" --->
    <CFSEARCH COLLECTION="pop_query"
        NAME="s_messages"
        CRITERIA="action">

    <!--- Output search result set --->
    <CFOUTPUT QUERY=" s_messages">
        #Key#, #Title# <BR>
    </CFOUTPUT>

The CFSEARCH code in the examples above uses the basic attributes needed to search a collection. The next section expands on the capabilities of this tag for more detailed input and output options.