Creating a Directory for the XML File

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. Searching Portal Content 13-9 end loop; utl_file.put file = l_file, buffer = ResultSet ; utl_file.fclosefile = l_file; exception ... end;

13.5 Displaying Search Results

For your search query to be useful, you need to display the results somewhere. You can choose to display the results of the search directly from the array, for example, in a dynamic page. For more flexibility, you can transform the search results into XML first and then display the XML, for example in OmniPortlet.

13.5.1 Displaying XML Search Results in OmniPortlet

The steps in this section provide an example of how to use the XML generated by the search APIs as the data source for OmniPortlet. For example, you could schedule a job to regularly execute an API to produce search results as XML and then automatically display those results in an OmniPortlet. For more information about OmniPortlet, refer to Chapter 3, Creating Portlets with OmniPortlet . To display XML search results in OmniPortlet, perform the following steps:

1. First you need to add a new OmniPortlet instance to a page.

2. Click the Define link to launch the OmniPortlet Wizard.

3. On the Type page of the wizard, select XML, then click Next.

4. On the Source page, in the XML URL field, enter the URL of your XML file, for

example: http:my.portal.com:7778searchapiresults.xml Because the XML data produced by the search APIs uses a ROWSETROW structure, you do not need to specify an XSL filter.

5. Click Next.

6. On the View page, select Tabular for the Layout Style, then click Next.

Note: The XML produced by the search APIs is returned in a CLOB. Therefore, if you want to use the XML as a data source for OmniPortlet, you must first write the CLOB to a file. For an example of how to do this, refer to Section 13.4, Transforming Search Results into XML . Tip: OmniPortlet is usually available in the Portlet Builders area of the Portlet Repository.