on 09-08-2008 11:57 AM
Hi experts!
We want to use TREX as our search engine.
The following link already show some results for our system:
[http://trexsourcesearch.wdf.sap.corp:31305/webkit/TREX/abapsearch/search.psp|http://trexsourcesearch.wdf.sap.corp:31305/webkit/TREX/abapsearch/search.psp] and also the RFC-connection check in SM59 for TREX_SOURCE_SE is ok. So it seems that TREX is already running and configured on our system.
-
Our aim is to write a simple (test)report where you can enter e.g. a string. TREX searchs (maybe) our whole component for this string. TREX returns the search results and our report shows all the results.
So my question is:
How can I do this? Which function modules/methods... should I call to solve this problem?
-
I've found the following link but I think it describes only how TREX works and how it is to administer.
[http://help.sap.com/saphelp_nw70/helpdata/EN/46/cbe4bb63a668dfe10000000a114a6b/frameset.htm|http://help.sap.com/saphelp_nw70/helpdata/EN/46/cbe4bb63a668dfe10000000a114a6b/frameset.htm]
Thanks and regards,
Christian
Edited by: Christian Honeder on Sep 8, 2008 12:58 PM
I've founde a solution:
Useful is the transaction "TREXADMIN". Here you can see if your index has been created and if you have feed it correctly. You can also search for the attributes which you have added to the index.
But this transaction requires a special permission. Therefore you can use the search-methods in CL_COM_SE_TREX instead. The mentioned class provides a lot of functions for TREX
The following example shows how to create and feed the TREX index with one document. The search attributes itself are contained in lt_doc_attr. In this internal table you will have the fieldname (later displayed in TREXADMIN) and the value (you can search for this).
Comment: After you've feed the index you might have to wait some time until the fields in TREXADMIN appear or the search routines find something.
Create the TREX index:
* Get trex instance
lr_trex = cl_com_se_trex=>if_com_se_trex~get_instance( ).
CHECK lr_trex IS BOUND.
* Prepare Index Attributes
l_trex_id = 'your_trex_id'. "unique
l_rfc_destination = 'your_rfc_destination.
CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT'
EXPORTING
input = sy-langu
IMPORTING
output = l_langu.
* Create index
CALL METHOD lr_trex->create_index
EXPORTING
iv_index_id = l_trex_id
iv_rfc_destination = l_rfc_destination
iv_language = l_langu
IMPORTING
ev_return_code = l_rc
EXCEPTIONS
conversion_error = 1
error = 2
OTHERS = 3.
Feed the TREX index:
The table lt_doc_attr has been filled in a subroutine.
DATA ls_doc_list TYPE trexs_index_doc.
DATA lt_doc_list TYPE trext_index_docs.
DATA lt_doc_attr TYPE trext_indexdoc_attrs.
* Feed Index
l_doc_key = ls_doc_key-doknr. "unique
ls_doc_list-doc_key = l_doc_key.
ls_doc_list-doc_langu = l_langu.
ls_doc_list-class_rel = 1.
ls_doc_list-doc_type = 'A'. "text ASCII
ls_doc_list-doc_action = 'I'. "index, alternative: D(index)
* some values for ls_doc_list-doc_type
* A text (ASCII); standard is A
* F file
* U url
* B binary
* Copy search attributes into the structure
ls_doc_list-doc_attr = lt_doc_attr.
APPEND ls_doc_list TO lt_doc_list.
* Now feed the index with the new document
CALL METHOD lr_trex->feed_index
EXPORTING
iv_index_id = l_trex_id
iv_rfc_destination = l_rfc_destination
* iv_use_queueserver = 'X'
it_index_document_list = lt_doc_list
* iv_flush_after_index = 'X'
IMPORTING
ev_return_code = l_rc
EXCEPTIONS
conversion_error = 1
error = 2
OTHERS = 3.
Delete the TREX index:
* Delete the Index
CHECK del_idx = abap_true.
CALL METHOD lr_trex->delete_index
EXPORTING
iv_index_id = l_trex_id
iv_rfc_destination = l_rfc_destination
EXCEPTIONS
conversion_error = 1
error = 2
OTHERS = 3.
How to search in the TREX index
You can use the trex instance instead of the function module to search the index.
* Search for a special fieldvalue
ls_query_entry-location = 'FIELDNAME'. "a fieldname which you have added with lt_doc_attr
ls_query_entry-value1 = l_txt. "maybe a text from the selection screen
ls_query_entry-rowtype = 'ATTRIBUTE'.
ls_query_entry-operator = 'EQ'.
APPEND ls_query_entry TO lt_query_entry.
* Search for a string
* Add the operator only if you've added a fieldname
ls_query_entry-value1 = 'AND'.
ls_query_entry-rowtype = 'OPERATOR'.
ls_query_entry-operator = 'EQ'.
APPEND ls_query_entry TO lt_query_entry.
ls_query_entry-value1 = l_string.
ls_query_entry-rowtype = 'TERM'.
ls_query_entry-operator = 'EQ'.
APPEND ls_query_entry TO lt_query_entry.
* All attributes are requested
ls_requ_attributes-attr_name = '*'.
APPEND ls_requ_attributes TO lt_requ_attributes.
* 1: DidYouMean, 2: Snippets 4: TitleSnippets or a bit combinaton
l_request_flag = 2.
* Search the index
CALL FUNCTION 'TREX_EXT_SEARCH_DOCUMENTS'
EXPORTING
i_indexes = lt_index "table with your index id
i_rfc_destination = l_rfc_destination
i_result_from = l_res_from "how many results should be found?
i_result_to = l_res_to
i_max_snippet_words = 30
i_request_flags = l_request_flag
i_query_entries = lt_query_entry
i_req_attributes = lt_requ_attributes
IMPORTING
e_result_docs = lt_result_doc.
e_no_of_hits = l_no_of_hits
e_no_of_all_hits = l_no_of_all_hits
e_index_size = l_index_size.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.