Approving and Rejecting Items

13-2 Oracle Fusion Middleware Developers Guide for Oracle Portal For example, the results returned by the item_search API have the same structure as the WWSBR_ALL_ITEMS view. For information about the structure of the secure views, refer to Chapter F, Content Management APIs and Views . This chapter contains the following sections: ■ Section 13.1, Searching For Items Across All Page Groups ■ Section 13.2, Searching For Pages in Specific Page Groups ■ Section 13.3, Searching For Items By Attribute ■ Section 13.4, Transforming Search Results into XML ■ Section 13.5, Displaying Search Results For the examples in the following sections, you need to enable output in SQLPlus. To do this log on to SQLPlus as the portal schema owner and enter the following command: SQL SET SERVEROUTPUT ON For more information about the public search APIs, refer to the Oracle Portal PLSQL API Reference on Portal Center: http:portalcenter.oracle.com In the Portal Focus Areas section, click Portlet Development, and then click PLSQL API Reference APIs and References section.

13.1 Searching For Items Across All Page Groups

Example 13–1 uses the item_search API to search all the page groups in your portal for items that contain the term portal. Example 13–1 Searching Across All Page Groups item_search API declare l_results wwsrc_api.items_result_array_type; l_count number; l_scores wwsrc_api.number_list_type; begin l_results := wwsrc_api.item_search p_mainsearch = portal, p_out_count = l_count, p_out_scores = l_scores ; dbms_output.put_lineNumber of results: || l_count; exception ... end; ■ p_mainsearch is the keyword or term for which you want to search. This may be any value, including an Oracle Text query expression. ■ p_out_count is the number of search hits. Tip: Remember, if you are calling the APIs from a Web provider or external application, you need to set the session context first. For more information, refer to Section 10.1, Setting the Session Context . Searching Portal Content 13-3 ■ p_out_scores is an array of search results scores. This is the Oracle Text relevancy score, rating how well each result matches the search term or any other textual search criteria. The index of the array matches the index of the results array returned by the function. In Example 13–1 , the maximum number of search results that may be returned is determined by the wwsrc_api constant MAX_ROWS default is 1000. This avoids the possibility of a search query with many hits taking too long to run if a specific number of rows is not specified. For an example of how to specify the number of rows to return see Example 13–2 .

13.2 Searching For Pages in Specific Page Groups

Example 13–2 uses the page_search API to search in two specific page groups MyPageGroup and Shared for pages that contain the term Oracle. In this example, only the first ten results are returned. Example 13–2 Searching in Specific Page Groups page_search API declare l_results wwsrc_api.pages_result_array_type; l_count number; l_scores wwsrc_api.number_list_type; l_pggroups wwsrc_api.number_list_type; begin l_pggroups1 := 0; -- Page group 0 shared. l_pggroups2 := 33; -- Page group 33 mypagegroup. l_results := wwsrc_api.page_search p_mainsearch = Oracle, p_page_groups = l_pggroups, p_rows = 10, p_out_count = l_count, p_out_scores = l_scores ; dbms_output.put_lineNumber of results: || l_count; exception ... end; ■ p_mainsearch is the keyword or term for which you want to search. This may be any value, including an Oracle Text query expression. ■ p_page_groups is an array of the IDs of the page groups that you want to search. If you do not include this parameter, the value defaults to wwsrc_api.EMPTY_ NUMBER_LIST that is, all page groups. ■ p_rows is the maximum number of search results to return. This defaults to the wwsrc_api constant value MAX_ROWS. ■ p_out_count is the number of search hits. ■ p_out_scores is an array of search result scores. This is the Oracle Text relevancy score, rating how well each result matches the search term or any other textual search criteria. The index of the array matches the index of the results array returned by the function. 13-4 Oracle Fusion Middleware Developers Guide for Oracle Portal

13.3 Searching For Items By Attribute

Example 13–3 uses the specify_attributes and item_search APIs to search for all file items created by Joe Bloggs since 01-Jan-2004 that contain the term Oracle. Example 13–3 Searching Specific Attributes specify_attributes API declare l_results wwsrc_api.items_result_array_type; l_count number; l_scores wwsrc_api.number_list_type; l_attributes wwsrc_runtime_attr_varray; l_createdate_attrid wwsbr_attributes.idtype; l_createdate_caid wwsbr_attributes.caidtype; l_createdate_type wwsbr_attributes.data_typetype; begin -- Build up attribute object with author criteria. wwsrc_api.specify_attributes p_id = wwsbr_api.ATTRIBUTE_AUTHOR, p_siteid = wwsbr_api.SHARED_OBJECTS, p_value = Joe Bloggs, p_operator = wwsrc_api.CONTAINS_ALL, p_datatype = wwsrc_api.DATA_TYPE_TEXT, p_in_out_attr_varray = l_attributes ; -- Build up attribute object with create date criteria -- using wwsbr_attributes view. select id, caid, data_type into l_createdate_attrid, l_createdate_caid, l_createdate_type from wwsbr_attributes where name = createdate and rownum = 1; -- Ignore translations. wwsrc_api.specify_attributes p_id = l_createdate_attrid, p_siteid = l_createdate_caid, p_value = 01-JAN-2004, p_operator = wwsrc_api.GREATER_THAN, p_datatype = l_createdate_type, p_in_out_attr_varray = l_attributes ; -- Perform the search. l_results := wwsrc_api.item_search p_mainsearch = Oracle, p_itemtypeid = wwsbr_api.ITEM_TYPE_FILE, p_itemtypesiteid = wwsbr_api.SHARED_OBJECTS, p_attributes = l_attributes, p_out_count = l_count, p_out_scores = l_scores ; dbms_output.put_lineNumber of results: || l_count; exception ... end; The following are parameters for specify_attributes: ■ p_id is the ID of the attribute. Use the wwsbr_api constants or query the WWSBR_ATTRIBUTES view to find this ID. ■ p_siteid is the ID of the page group to which the attribute belongs. Searching Portal Content 13-5 ■ p_value is the attribute value to include as search criteria. This must be a text value. ■ p_operator is the search operator that you want to use. ■ p_datatype is the datatype of the attribute value. ■ p_in_out_attr_varray is the existing varray of attributes if any. The following are parameters for item_search: ■ p_mainsearch is the keyword or term for which you want to search. This may be any value, including an Oracle Text query expression. ■ p_itemtypeid is the ID of the type of item for which you want to search. Use the wwsbr_api constants or query the WWSBR_ITEM_TYPES view to find this ID. Note that this is the actual subtype of the item, not the base type. ■ p_itemtypesiteid is the ID of the page group to which the item type belongs. ■ p_attributes is an array of attributes to search together with their operators and values. You can build up the values for this parameter by calling the specify_ attributes API. ■ p_out_count is the number of search hits. ■ p_out_scores is an array of search result scores. This is the Oracle Text relevancy score, rating how well each result matches the search term or any other textual search criteria. The index of this array matches the index of the results array returned by the function.

13.4 Transforming Search Results into XML

The APIs mentioned so far return search results in an array. To provide you with more flexibility about how to display your search results, Oracle Portal also provides several APIs that return search results as XML. These APIs return the XML results as a CLOB. The following sections describe how you can generate a physical XML file from a CLOB produced by the search APIs and store the XML file in a directory on the Oracle Portal middle tier: 1. Section 13.4.1, Creating a Directory for the XML File . 2. Section 13.4.2, Creating an XML File from a CLOB 3. Section 13.4.3, Generating Search Results in XML These examples assume that the database is on the same machine as the Oracle Portal middle tier.

13.4.1 Creating a Directory for the XML File

If you decide to transform your search results into an XML file, you must first perform some set up tasks to define the physical directory in which to write the file. To create a directory on the Oracle Portal middle tier, perform the following steps: 1. In SQLPlus, connect as SYSTEM or SYS and enter the following command: create directory dirname as physical_location; For example: create directory RESULTDIR as u02oraOraHome_101202_ PortalMFApacheApachehtdocssearchapi;