# <pz:contentQuery> Tag

The <pz:contentQuery> tag performs a content attribute search for content in the Repository Manager, returning an array of Node objects from the Repository Manager. If the useCache attribute is set to true, the results of a content management query will be cached. The tag only has a begin tag and does not have a body or end tag.

Use the following tags in conjunction with <pz:*> tags to access and display the returned content:

- <es:forEachInArray> to iterate over the Node objects in the array.
- <cm:*> tags to access metadata attributes in the content, retrieve content, and put it into the HTTP response output stream.

## Syntax

<tagName attribute="value" />

## Attributes

max

Optional (String, long) - Limits the maximum number of content nodes returned. If not present, it returns all of the content nodes found.

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.)

query

Required (String) - The search query to execute based on the query syntax described in Building Content Queries with Expressions.

id

Required (String) - The array variable name that contains the Node objects found. If no content is found, the variable is assigned an empty array (not null) of Node objects.

useCache

Optional (String, Boolean) - Determines whether Nodes are cached. This attribute can have one of two values:

- False (default value): NodeCache is not used. If false (not specified), the cacheId, cacheScope and cacheTimeout settings are ignored.
- True: NodeCache is used.

cacheId

Optional (String) - The identifier name used to cache the Node. Internally, the cache is implemented as a Map; this will become the key. If not specified, the id attribute of the tag is used.

cacheTimeout

Optional (String, long) - The time, in milliseconds, for which the cached Node is valid. If more than this amount of time has passed since the Node was cached, the cached Node will be cleared, retrieved, and placed back into the cache.

Use -1 for no-timeout (always use the cached Node). Default = -1.

cacheScope

Optional (String) - Specifies the lifecycle scope of the content cache. Similar to <jsp:useBean>.

Possible values:

- application: Any JSP page in the web application that any customer requests can access the cache.
- session (the default): Any JSP in the web application that the current customer requests can access the cache.
- page: Only the current JSP that any customer requests can access the cache.
- request: Only the current user request can access the cache. If a customer re-requests the page, the content selector re-runs the query and recreates the cache.

## Example

This example queries the content management system for an author and prints the title of the author's work.

    <pz:contentQuery 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

<es:forEachInArray> Tag

<cm:getProperty> Tag

<cm:getNode> Tag

<cm:search> Tag