Show TOC

Integrating External SearchLocate this document in the navigation structure

Use

To extend search capabilities of the portal, you can integrate external search providers and make them available in the Search box in the masthead of Ajax Framework Page. You do this with the help of the Search Provider API, contained in the com.sap.portal.search.service package.

Prerequisites
  • SAP NetWeaver Developer Studio is installed and started

  • In the Framework Page Configuration for Ajax Framework Page , the Enable Quick Launch option is selected.

    For more information about enabling this option, see Creating and Editing a Framework Page .

Procedure

The following procedure describes how to implement and integrate a basic search provider that activates an external search engine.

  1. In SAP NetWeaver Developer Studio, open the Enterprise Portal perspective and create a portal application project.

    For more information, see Creating a Portal Application Project .

  2. In portalapp.xml, set a sharing reference to com.sap.portal.search.service.

  3. In the portal application project, create a portal service, and add the startup property, setting it to true.

    For more information, see Creating a Portal Service .

  4. Create a resource bundle named L10N.properties, and add the following keys:

    Sample Code
    BASIC_SEARCH_NAME = "Basic Search"
    ADVANCED_SEARCH_NAME = "Advanced Search"
    DESCRIPTION = "This is a search provider"
    
                      

    For more information, see Using Resource Bundles .

  5. In the src.core folder, create a new class named MyHandler that implements the ISearchProviderHandler interface.

  6. Paste the following code into the getDescriptor method of the class:

    Sample Code
    SearchProviderDescriptor desc = new SearchProviderDescriptor("SEARCH_PROVIDER_KEY", locale);
    ResourceBundle bundle = ResourceBundle.getBundle("L10N", locale);
    desc.setBasicSearchName(bundle.getString("BASIC_SEARCH_NAME"));
    desc.setAdvancedSearchName(bundle.getString("ADVANCED_SEARCH_NAME"));
    desc.setDescription(bundle.getString("DESCRIPTION"));
    return desc;
    
                      
  7. Paste the following code into the getKey method:

    return "SEARCH_PROVIDER_KEY";

  8. Paste the following code into the getSearchTypes(IUser user, Locale locale) method:

    Sample Code
    SearchTypes searchTypes = new SearchTypes();
    // Define properties of basic search
    SearchProperties basicSearch = new SearchProperties();
    basicSearch.setNavigationType(SearchProviderNavigationType.EXTERNAL);
    basicSearch.setWinMode(INavigationConstants.SHOW_EXTERNAL_HEADERLESS);
    basicSearch.setTemplate("http://search.yahoo.com/search?p={searchTerms}");
    
    // Define search categories for basic search
    List <SearchCategory> basicCat = new ArrayList<SearchCategory>();   
    SearchCategory firstCategory = new SearchCategory();
    firstCategory.setID("images");
    firstCategory.setTitle("Images");
    firstCategory.setTemplate("http://images.search.yahoo.com/search/images?p={searchTerms}");
    firstCategory.setSubcategories(null);
    basicCat.add(firstCategory);
    SearchCategory secondCategory = new SearchCategory();
    secondCategory.setID("news");
    secondCategory.setTitle("News");
    secondCategory.setTemplate("http://images.search.yahoo.com/search/news?p={searchTerms}");
    secondCategory.setSubcategories(null);
    basicCat.add(secondCategory);
    basicSearch.setCategories(basicCat);
    
    // Define properties of advanced search
    SearchProperties advancedSearch = new SearchProperties();
    advancedSearch.setNavigationType(SearchProviderNavigationType.EXTERNAL);
    advancedSearch.setTemplate("http://search.yahoo.com//web/advanced?ei=UTF-8&p{searchTerms}");
    advancedSearch.setCategories(null);
    
    searchTypes.setBasic(basicSearch);
    searchTypes.setAdvanced(advancedSearch);
    return searchTypes;
    
                      
  9. In the deprecated getSearchTypes method, return null.

  10. To register the service, copy the following code to the init method of the service implementation class:

    Sample Code
    MyHandler myHandler = new MyHandler();
    ISearchService searchService = (ISearchService)PortalRuntime.getRuntimeResources().getService(ISearchService.KEY);
    searchService.register(myHandler.getKey(), myHandler);
    
                      
  11. To unregister the service, copy the following code to the destroy method of the service implementation class:

    Sample Code
    ISearchService searchService = (ISearchService)PortalRuntime.getRuntimeResources().getService(ISearchService.KEY);
    searchService.unregister("SEARCH_PROVIDER_KEY");
    
                      
  12. Build and deploy your application. For more information, see Deploying a Portal Application .

  13. In the Provider Configuration screen, add and enable your search provider. For more information, see Configuring Providers .

  14. Refresh the portal, and check that your provider is visible in the Search Options dropdown box.