Difference between revisions of "Core/find"
(New page: __NOTOC__ ==== PCMS_Client->find(query, [filters], [exact], [allowedTypes]) ==== === Overview === Search through the content of the CMS using filters and types. === Arguments === '''query'...) |
(→Arguments) |
||
Line 10: | Line 10: | ||
Filters are used to indicate one or more starting points for the search. <br> | Filters are used to indicate one or more starting points for the search. <br> | ||
Possible filters are: <br> | Possible filters are: <br> | ||
− | Element with API name "Shops": "element.Shops" <br> | + | * Element with API name "Shops": "element.Shops" <br> |
− | Nested Elements with template "Banner": "template.HomePage > element.Misc > templates.Banner" <br> | + | * Nested Elements with template "Banner": "template.HomePage > element.Misc > templates.Banner" <br> |
− | Element with id 2399: "element:2399" | + | * Element with id 2399: "element:2399" |
You can combine multiple starting points as items in an array. | You can combine multiple starting points as items in an array. | ||
Line 21: | Line 21: | ||
'''allowedTypes''' [array, ''optional'']<br> | '''allowedTypes''' [array, ''optional'']<br> | ||
Array with allowed return elements. This way a search result can be filtered to return only Elements based on a specific template or with a specific API name. Syntax is the same as for filters. | Array with allowed return elements. This way a search result can be filtered to return only Elements based on a specific template or with a specific API name. Syntax is the same as for filters. | ||
+ | |||
=== Returns === | === Returns === | ||
If Elements are found matching the criteria this method returns a valid [[SearchResults|SearchResults ]] object. Otherwise an empty collection. <br> | If Elements are found matching the criteria this method returns a valid [[SearchResults|SearchResults ]] object. Otherwise an empty collection. <br> |
Revision as of 22:24, 25 December 2008
PCMS_Client->find(query, [filters], [exact], [allowedTypes])
Overview
Search through the content of the CMS using filters and types.
Arguments
query [string]
The keywords used in the search. Can be one or more words, separated by spaces.
filters [array, optional]
Filters are used to indicate one or more starting points for the search.
Possible filters are:
- Element with API name "Shops": "element.Shops"
- Nested Elements with template "Banner": "template.HomePage > element.Misc > templates.Banner"
- Element with id 2399: "element:2399"
You can combine multiple starting points as items in an array.
exact [boolean, optional]
Indicate if you want to search for the exact words in the query. Default is FALSE.
allowedTypes [array, optional]
Array with allowed return elements. This way a search result can be filtered to return only Elements based on a specific template or with a specific API name. Syntax is the same as for filters.
Returns
If Elements are found matching the criteria this method returns a valid SearchResults object. Otherwise an empty collection.
That way you can test if you get a valid return using the count() method.
Example
$objCms = PCMS_Client::getInstance(); /* Find all Elements that have the words "cool" or "example" in * there text fields. */ $strQuery = "cool example"; // Start the search on News items and Newsletters. $arrFilters = array("element:Pages > templates:NewsItems", "element:Pages > templates:NewsLetters"); // Return only Elements with template "News" and "Newsletter". $arrAllowed = array("template:News", "template:NewsLetter"); $objResults = $objCms->find($strQuery, $arrFilters, FALSE, $arrAllowed); foreach ($objResults as $objResult) { // Loop through the results. $objElement = $objCms->getElementById($objResult->id); }