ibexa

Caution: This documentation is for eZ Publish legacy, from version 3.x to 5.x.

keyword

Summary

Fetches nodes that use keywords starting with a given sequence.

Usage

fetch( 'content',  'keyword',  hash( 'alphabet', alphabet,
                                   [ 'classid',  classid, ]
                                   [ 'limit',    limit,   ]
                                   [ 'offset',   offset,  ]
                                   [ 'owner',    owner,   ]
                                   [ 'sort_by',  sort_by, ] ) )

Parameters

NameTypeDescriptionRequired
alphabet string The sequence that should be matched. Yes.
classid array Filtering: the ID number of the class or an array of the ID numbers. No.
offset integer The offset to start at. No.
limit integer The number of elements that should be returned. No.
owner integer Filtering by owner: the ID number of the object representing the user. No.
sort_by array The sorting mechanism that should be used. No.

Returns

An array of hashes (see below) or FALSE.

Description

This function fetches nodes that encapsulate objects which make use of certain keywords. The keyword must be prodived using the "alphabet" parameter. This parameter can be a letter, a part of a word or an entire word - the function will look for keywords that start with the specified sequence. By default, the function will fetch nodes that encapsulate objects of all types created by any user. However, it is possible to only fetch objects of a certain type that are initially created by a certain user, this can be achieved by using the optional "classid" and "owner" parameters. The "offset" and "limit" parameters can be used to limit the result.

The "sort_by" parameter makes it possible to sort the result in different ways. This parameter must be provided as an array. The first element of the array must be the desired sorting method. The second element of the array must be the sorting direction, it can be either true() or false() - ascending or descending. Please note that this parameter works in the very same way as the "sort_by" parameter of the list fetch function. However, it currently only supports the following sorting methods:

  • class_identifier
  • class_name
  • modified
  • name
  • published
  • section

Please note that using other sort methods will lead to an error.

The function returns an array of hashes. Each hash consists of the following elements:

Key

Type

Description

keyword

string

The keyword that was matched.

link_object

object

The node (as a ezcontentobjecttreenode object) that encapsulates an object which uses the matched keyword.

If no match is found, the function will return FALSE.

Examples

Example 1

 

{def $list=fetch( 'content', 'keyword',
                  hash( alphabet, 'computer',
                        classid,   3 ) )}
 
{foreach $list as $element}
    {$element.link_object.name|wash} ({$element.keyword|wash}) <br />
{/foreach}


Outputs the names of nodes that encapsulate objects which make use of keywords starting with the string "computer". In addition, the matched keywords are also printed.

Example 2

 

{def $list=fetch( 'content', 'keyword',
                  hash( alphabet, 'computer',
                        classid, array( 1, 3 ) ) )}


Only nodes that encapsulate objects of the specified two classes will be fetched.

Example 3

 

{def $list=fetch( 'content', 'keyword',
                  hash( alphabet, 'computer',
                        classid, array( 1, 3 ),
                        owner, 14,
                        sort_by, array( 'modified', false() ) ) )}


Only the nodes/objects that are created by the user that has ID number 14 will be included in the result. The nodes will be sorted by the modification time of the objects; the node that encapsulates the most recently modified object will be the first element in the collection.

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

Svitlana Shatokhina (17/01/2007 1:33 pm)

Balazs Halasy, Svitlana Shatokhina


Comments

  • sorting by name and class_name didn't work in 3.9.0

    The problem was fixed in 3.9.1, see http://issues.ez.no/10033
  • no keyword but result fetched

    Hi!
    I use this to get all the articles in relation to a keyword. Here is the eZ code:

    {def $related = fetch( 'content',  'keyword',  hash( 'alphabet', 'fashion',
                                        'sort_by',  array('published', false()) ) )}
    {if ne($related, false)}
    <ul>  Articles related to {$designer}
    {foreach $related as $element}
        <li>{$element.link_object.name|wash}
        	{if ne($element.keyword, '')}
        		({$element.keyword|wash})
        	{/if}
       </li><br />
    {/foreach}
    </ul>
    


    And this is my result
    Articles related to fashion In store this week, 16 January 2008 (fashion)
    # Global Traveller
    # Global Traveller (fashion forward)
    # In store this week, 9 January 2008 (Fashion)
    # Home
    


    I'm happy with it, but a bit surprised to see that if there is no keyword (ie when I get no "(fashion something)" an article can still be fetched. How comes?
    It's not really a problem because I can change my code easily to have the title in the {if ne($element.keyword, '')} as well but I was really puzzled by the result.

    Thanks if you can give me a clue
    • Re: no keyword but result fetched

      Here is an error:

      {if ne($related, false)}

      right:

      {if ne($related, false())}

      greets