# <cm:search> Tag

The <cm:search> tag searches for and retrieves content nodes based on a supplied query and stores the results in a variable.

## Syntax

<tagName attribute="value" />

## Attributes

query

Optional (String) - The search query to execute based on the query syntax described in Building Content Queries with Expressions. An expression is constructed with the query value. This is used if the expression attribute is not used.

expression

Optional (Expression) - The search expression to execute as a com.bea.p13n.expression.Expression. This value can be set programmatically.

id

Required (String) - The variable in which the search results are placed.

max

Optional (String) - The maximum number of content nodes returned by the search.

sortBy

Optional (String) - Use this attribute to sort the retrieved content in ascending or descending order. Enter the content attributes on which you want to sort the content.

However, you can sort content only on content properties that are explicit, meaning the values are stored in their own database column. System properties (see com.bea.content.expression.Search) are explicit by default. But the content properties you create in the WebLogic Administration portal (properties contained within the content "types" you create) are implicit. If you want to sort on those properties, you must make them explicit by doing the following:

Note: You can sort on explicit properties only against a BEA repository. Third-party repositories might behave differently.

1. In your database, create a column in CM_NODE table of type Integer to store the explicit property values you want to sort on. Name the column whatever you like (within the naming contraints).
2. In the WebLogic Administration Portal, set the property you want to sort on to be explicit, and enter the name of the database column you created.
   For example, if you have a property called "myproducts," and you created a database column called "PRODUCT" for it, the following is how you would define the "myproducts" property: select the "Is Explicit?" option and enter "PRODUCT" as the special reference.
   Any content nodes that use this property will have the property value stored in the PRODUCT database column, and the retrieved content can be sorted by that property.

> Use ASC and DESC to sort retrieved content in ascending or descending order.
> Examples:
> sortBy=“myproducts ASC”
> sortBy="cm_modifiedDate DESC" (This is a system attribute that is explicit by default.)

failOnError

Optional (boolean) - This attribute can have one of two values:

- false (default value): Handles JSP processing errors gracefully and prints nothing if an error occurs. Returns null on an error.
- true: Throws an exception. You can handle the exception in the code, let the page proceed to the normal error page, or let the application server handle it less gracefully.

contextParams

Optional (Map) - The context parameters of the search.

useCache

Optional (boolean) - Set to true to cache the search results at the servlet container layer. (The default is "false.") A different cache is used than what is set in the Administration Portal. You do not need to set this cache attribute if you are already using application cache.

cacheScope

Optional (String) - The scope in which the cache is used: "application," "page," "request," or "session." The default is "session." See the description of the useCache attribute for guidance.

cacheId

Optional (String) - The variable in which the cached items are stored. See the description of the useCache attribute for guidance.

cacheTimeout

Optional (long) - The number of milliseconds to store the items in cache. See the description of the useCache attribute for guidance.

## Example

    <cm:search id="docs" query="author = 'Hemingway'" />
    <ul>
    <es:forEachInArray array="<%=docs%>" id="aDoc" type="com.bea.content.Node">
        <li>The document title is: <cm:getProperty id="aDoc" name="Title" conversionType="html" />
    </es:forEachInArray>
    </ul>

Related Topics

<cm:getNode> Tag

<cm:getProperty> Tag

<es:forEachInArray>