Searching For Items By Attribute

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 13-8 Oracle Fusion Middleware Developers Guide for Oracle Portal XML. Example 13–6 shows a workaround that removes these tags and also adds opening and closing ResultSet tags to produce an XML file with the ROWSETROW structure. If you want to use the XML file as a data source for OmniPortlet, you should do something similar. Example 13–6 Using get_item_xml to Write Search Results to a File declare l_amount binary_integer; l_offset number := 1; l_text varchar232767; l_file utl_file.file_type; l_clob clob; l_results wwsrc_api.items_result_array_type; l_scores wwsrc_api.number_list_type; l_count number; begin l_results := wwsrc_api.item_search p_mainsearch = portal, p_out_count = l_count, p_out_scores = l_scores ; l_file := utl_file.fopen location = RESULTDIR, -- Directory name is case-sensitive. filename = results14.xml, open_mode = w ; utl_file.put file = l_file, buffer = ResultSet ; for i in 1..l_results.count loop l_amount := 32767; l_offset := 1; begin l_clob := wwsrc_api.get_item_xmll_resultsi; dbms_lob.openl_clob, dbms_lob.file_readonly; loop dbms_lob.readl_clob, l_amount, l_offset, l_text; -- Workaround for XML generated with get_item_xml. if instrl_text, ? = 0 then l_text := substrl_text, instrl_text, ? + 2; end if; -- End of workaround. 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; Note: Example 13–6 loops through the search results and writes them all to XML producing the same results as using get_all_ items_xml. Typically, you would use get_item_xml to filter the search results somehow.