Searching For Items Across All Page Groups

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; 13-6 Oracle Fusion Middleware Developers Guide for Oracle Portal In this example, we use the htdocs directory of the Oracle Portal middle tier. This is a good location to use as you can then access the XML results file through HTTP, in the format: http:Portal_Mid_Tier:PortdirectoryXML_Output_File For example: http:my.portal.com:7778searchapiresults.xml You can then use this to specify the XML file as the data source for OmniPortlet. For an example of how to do this, refer to Section 13.5.1, Displaying XML Search Results in OmniPortlet . 2. Still in SQLPlus, grant write privileges to the directory from PLSQL programs. In our example, we would do this by entering the following command: grant write on directory RESULTDIR to public; 3. Check that you can write files to the new directory by running the following procedure: declare 2 v_output_file1 utl_file.file_type; 3 begin 4 v_output_file1 := utl_file.fopenRESULTDIR, NEW.txt, a; 5 utl_file.put_linev_output_file1, NATURE and Beauty; 6 utl_file.fclose_all; 7 end; 8 PLSQL procedure successfully completed. Now, when you go to the directory on the file system, you should see the NEW.txt file.

13.4.2 Creating an XML File from a CLOB

When you have specified the location for the XML output, you can write the procedure that creates it. Example 13–4 shows a generic procedure that takes the CLOB produced by the get_all_items_xml API and writes an XML file to a specific location. It takes two input parameters: the file name and the CLOB. Example 13–4 Writing an XML File to a Specific File System Location create or replace procedure results_xml_to_filexml_filename varchar2, result_xml clob as l_amount binary_integer; l_offset number := 1; l_text varchar232767; l_file utl_file.file_type; l_clob clob; begin l_clob := result_xml; l_file := utl_file.fopen location = RESULTDIR, -- Directory name is case-sensitive. filename = xml_filename, open_mode = w ; l_amount := 32767;