CL_ESH_IF_SEARCH_REQUEST - Search Request

Addresses (Business Address Services)   CPI1466 during Backup  
This documentation is copyright by SAP AG.

Functionality

This is the main API class for using Enterprise Search.

To prepare your search request, call the following methods:

  • CL_ESH_IF_SEARCH_REQUEST-> SET_SEARCH_TEXT
  • CL_ESH_IF_SEARCH_REQUEST ->SET_SEARCH_SCOPE
  • CL_ESH_IF_SEARCH_REQUEST ->SET_START_INDEX
  • CL_ESH_IF_SEARCH_REQUEST ->SET_MAX_NUMBER_OF_RESULTS
  • CL_ESH_IF_SEARCH_REQUEST ->SET_TIMEOUT

To build more complex queries, you can:

  • CL_ESH_IF_SEARCH_REQUEST ->ADD_SEARCH_ATTRIBUTE

Additionally we provide the option to build complex queries via so called Query Parts. A complex querycan be seen as a logical formula of atomic conditions and joining operators. This can be representedby Query Parts via build a query tree of nodes representing either the conditions or the operators. See method CL_ESH_IF_SEARCH_REQUEST->SET_QUERY_PARTS.

To process the search request, call method ESH_IF_SEARCH_REQUEST ->SEARCHfor a grouped response, meaning response objects per search connector.

To get a merged result list use the method CL_ESH_IF_SEARCH_REQUEST ->SEARCH_FEDERATED.

You can also call the methods of interface IF_ESH_IF_ASYNCHRONOUS_SEARCH if you needto retrieve the search results asynchronously (see methods SEARCH_ASYNCHRONOUS, HAS_NEW_RESPONSES, GET_RESPONSES, and IS_FINISHED).

All search methods return a responses object (see the documentation for class CL_ESH_IF_SEARCH_RESPONSES ->CL_ESH_IF_SEARCH_RESPONSES).

The method GET_CONNECTOR_STATISTICS of the responses object instance provides details such as errormessages, timeouts, and runtime statistics and thus is helpful during the implementation phase and when analyzing issues.

Besides Search it is possible to implement value helps for request attributes via CL_ESH_IF_SEARCH_REQUEST GET_ATTRIBUTE_VALUE_LIST -> GET_ATTRIBUTE_VALUE_LIST and type-ahead functionality via CL_ESH_IF_SEARCH_REQUEST ->GET_SUGGESTIONS.

Relationships

  • Enterprise Search Cockpit
  • Enterprise Search (Generic UI)

Example

The report below shows how to process a search for all searchable search connectors (see transaction ESH_COCKPIT) of SAP Enterprise Search.

REPORT  zesh_search_hello_world.

PARAMETERS text     TYPE esh_e_if_search_string DEFAULT '*'. "search text / query -> wildcard '*' supported
PARAMETERS cat_id   TYPE esh_e_om_category.                 "search connector category ( all -> cl_esh_if_mdata_category=>sc_category_id_all )
PARAMETERS idxstart TYPE int4 DEFAULT 1.                     "start index (default = 1)
PARAMETERS results  TYPE int4 DEFAULT 20.                    "number of results
PARAMETERS timeout  TYPE esh_e_if_timeout DEFAULT 10.        "seconds

DATA lo_search_request    TYPE REF TO cl_esh_if_search_request.
DATA lo_responses        TYPE REF TO cl_esh_if_search_responses.
DATA lo_conn_resp_connect TYPE REF TO cl_esh_if_search_resp_connect.
DATA lr_conn_data         TYPE REF TO data.
DATA lv_category_id       TYPE esh_e_om_category.
DATA lx_root              TYPE REF TO cx_root.
DATA lv_error_message     TYPE string.
DATA lo_alv_table         TYPE REF TO cl_salv_table.

FIELD-SYMBOLS TYPE ANY TABLE.



CREATE OBJECT lo_search_request.

* _______________________________________________________________________________________
* prepare search

* search text
lo_search_request->set_search_text( iv_text = text ).

IF cat_id IS INITIAL.
  lv_category_id = cl_esh_if_mdata_category=>sc_category_id_all.
ENDIF.
lo_search_request->add_search_scope( EXPORTING  iv_connector_id = ''
                                              iv_template_id  = ''
                                              iv_category_id  = lv_category_id
                                    EXCEPTIONS not_searchable  = 1 ).

* start index (first recod has index 1)
lo_search_request->set_start_index( iv_start_index = idxstart ).

* max number of results
IF results IS NOT INITIAL.
  lo_search_request->set_max_number_of_results( iv_number_of_results = results ).
ENDIF.

* timeout
IF timeout IS NOT INITIAL.
  lo_search_request->set_timeout( iv_timeout = timeout ).
ENDIF.


* _______________________________________________________________________________________
* process search
lo_responses = lo_search_request->search( iv_count_only = abap_false ).


* _______________________________________________________________________________________
* display results

* -> get results
IF lo_responses IS NOT INITIAL.
  WHILE lo_responses->has_next_response( ) = abap_true.
    lo_conn_resp_connect ?= lo_responses->get_next_response( ).
    TRY.
        lo_conn_resp_connect->get_exception( ) .
      CATCH cx_root INTO lx_root.
        lv_error_message = lx_root->get_text( ).
    ENDTRY.
    lo_conn_resp_connect->get_results_data_raw( IMPORTING er_raw_data = lr_conn_data ).
    CHECK lr_conn_data IS BOUND.
    ASSIGN: lr_conn_data->* TO .
    CHECK IS ASSIGNED.
*   -> display via ALV grid  -->> use back button (F3) to get the next result
    cl_salv_table=>factory( IMPORTING r_salv_table = lo_alv_table
                          CHANGING  t_table      = ).
    lo_alv_table->get_columns( )->set_optimize( abap_true ).
    lo_alv_table->display( ).
  ENDWHILE.
ENDIF.

For more sophisticated examples have a look at report ESH_TEST_SEARCH or the User Interface assistant classes CL_ESH_SEARCH_UI_ASSIST and CL_ESH_RESULT_UI_ASSIST (method SEARCH).

Notes

SAP Enterprise Search can also be accessed via the OpenSearch interface.

Further information

...


Addresses (Business Address Services)   ROGBILLS - Synchronize billing plans  
This documentation is copyright by SAP AG.


Length: 8756 Date: 20120526 Time: 120745     triton ( 282 ms )