Caution: This documentation is for eZ Publish legacy, from version 3.x to 6.x.
For 5.x documentation covering Platform see eZ Documentation Center, for difference between legacy and Platform see 5.x Architecture overview.

search

Summary

Fetches nodes containing data that match a certain criteria.

Usage

fetch( content, search,
       hash( text, text,
           [ offset,             offset, ]
           [ limit,              limit,  ]
           [ section_id,         id,     ]
           [ subtree_array,      array,  ]
           [ publish_timestamp,  time,   ]
           [ publish_date,       date,   ]
           [ class_id,           id,     ]
           [ class_attribute_id, id,     ]
           [ sort_by,            sort_by ] ) )

Parameters

NameTypeDescriptionRequired
text string The text that should be matched. Yes.
subtree_array mixed Array node ID number under which the system should search. No.
offset integer The offset to start at. No.
limit integer The number of nodes that should be returned. No.
publish_timestamp integer Only search objects with the specified publishing date/time (as a UNIX timestamp). No.
publish_date integer Only search objects published during the last day / week / month / three months / one year. No.
section_id integer Only match objects that are in this section. No.
class_id integer Only match objects that are instances of this class. This parameter can also be an array of class ID numbers. No.
class_attribute_id integer Only search within this attribute. This parameter can also be an array of attribute ID numbers. No.
sort_by mixed Sort the result. See description below. No.

Returns

An array of hashes (see below) or FALSE.

Description

This function will perform a search and it will return the hits that the current user has read access to. The function returns an array of hashes. The hashes consist of the following elements:

SearchResult

array

An array of the nodes (as ezcontentobjecttreenode objects) that matched the search conditions.

SearchCount

integer

The total number of nodes that matched the search conditions.

StopWordArray

array

An array of strings containing words that were excluded from the search.

Sorting

The "sort_by" parameter makes it possible to sort the result in different ways. This parameter behaves exactly in the same way as it does for the "list" function. Please refer to the documentation page of the "list" function for a complete explanation of this parameter.

Searching by the date of publishing

The "publish_date" parameter makes it possible to search objects published during the specified period. The following table reveals the possible values of this parameter.

1

one day

2

one week

3

one month

4

three months

5

one year

The "publish_timestamp" parameter makes it possible to search objects with the specified publishing date/time. This value must be a UNIX timestamp. You can also use an array of two elements in order to search withing the given range.

Please note that you can not use both "publish_timestamp" and "publish_date" at the same time. If you use "publish_timestamp" then "publish_date" will be ignored.

Examples

Example 1

{def $search=fetch( 'content', 'search',
                    hash( 'text',     'example',
                          'class_id', array( '2', '5' ) ) )}
 
The search returned {$search.SearchCount} matches. <br />
 
{foreach $search.SearchResult as $matched_node}
    {$matched_node.name|wash} <br />
{/foreach}

Outputs the names of all nodes which encapsulte objects of classes 2 and 5 containing the word "example".

Example 2

{def $search=fetch( 'content', 'search',
                    hash( 'text',     'example',
                          'publish_timestamp', array( '1033920746', '1033920789' ) ) )}
 
The search returned {$search.SearchCount} matches. <br />
 
{foreach $search.SearchResult as $matched_node}
    {$matched_node.name|wash} <br />
{/foreach}

Outputs the names of all nodes which encapsulte objects published between the specified date/time values.

Balazs Halasy (06/02/2004 12:12 pm)

Svitlana Shatokhina (14/06/2006 1:45 pm)

Balazs Halasy, Svitlana Shatokhina


Comments

  • addendum to the doc

    A good addendum to the doc would be that class_id and class_attribute_id should be thought as mutually dependent/exclusive for obvious reasons.