Searching For Pages in Specific Page Groups

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; Searching Portal Content 13-7 l_offset := 1; begin dbms_lob.openl_clob, dbms_lob.file_readonly; loop dbms_lob.readl_clob, l_amount, l_offset, l_text; utl_file.put file = l_file, buffer = l_text ; l_offset := l_offset + l_amount; exit when l_amount 32767; end loop; utl_file.new_linefile = l_file; dbms_lob.closel_clob; end; utl_file.fclosefile = l_file; exception ... end;

13.4.3 Generating Search Results in XML

Now, when you use the APIs to produce search results as XML, you can call the procedure in Example 13–4 to write the resulting CLOB to an XML file on the file system. Example 13–5 shows how you might do this. Example 13–5 Generating Search Results in XML get_all_items_xml API declare l_results wwsrc_api.items_result_array_type; l_scores wwsrc_api.number_list_type; l_count number; l_clob clob; begin l_results := wwsrc_api.item_search p_mainsearch = portal, p_out_count = l_count, p_out_scores = l_scores ; l_clob := wwsrc_api.get_all_items_xmll_results; results_xml_to_fileresults12.xml, l_clob; exception ... end; For information about the item_search API used in Example 13–5 , refer to Section 13.1, Searching For Items Across All Page Groups . You can use the XML file generated by this API as a data source for OmniPortlet. For an example of how you might do this, refer to Section 13.5.1, Displaying XML Search Results in OmniPortlet .

13.4.4 Workaround for get_item_xml

When you use get_item_xml to transform search results to XML, the API produces a ?xml version=1.0? element for each search result. This produces invalid