Creating an XML File from a CLOB

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. 13-10 Oracle Fusion Middleware Developers Guide for Oracle Portal 7. On the Layout page, choose the columns you want to display in the portlet and how you want them to appear.

8. Click Finish to create the OmniPortlet instance.

13.5.2 Displaying Search Results in a Dynamic Page

The following two examples show how to display search results in a dynamic page portlet. Users can then add this portlet to any page within your portal. To do this, perform the following steps: 1. Create a procedure that the dynamic page can call to perform the search. The procedure in Example 13–7 uses the item_search API to search for a specified term searchterm and displays only those results with a score higher than a specified value score. Example 13–7 Procedure to Perform the Search create or replace procedure search_resultssearchterm varchar2, score number as x varchar2100; y number; l_results wwsrc_api.items_result_array_type; l_count number; l_scores wwsrc_api.number_list_type; begin x := searchterm; y := score; l_results := wwsrc_api.item_search p_mainsearch = x, p_out_count = l_count, p_out_scores = l_scores ; htp.pNumber of total hits: || l_count; htp.pbr; htp.pbr; for i in 1..l_results.count loop if l_scoresi y then htp.pb || i || b - a href= || l_resultsi.url || || l_resultsi.display_name || a; htp.pbr; htp.pscore = || l_scoresi; htp.pbr; end if; end loop; exception ... end; grant execute on search_results to public; For information about the item_search API used in Example 13–7 , refer to Section 13.1, Searching For Items Across All Page Groups .

2. Create the dynamic page.

Note: You must create the procedure in the database in which your portal resides.