cancel
Showing results for 
Search instead for 
Did you mean: 

Searching with TREX

Former Member
0 Kudos

Hi all,

I am making a custom iView that perform search with TREX. At the time I want to add selection criteria on properties name, description, last modified etc. I don't know how to add such property in code. What property name and namespace should I use. Do any one have experience or code sample about that? I searched over the SDN and JavaDoc, but no related info talking about the property.

Thanks

Sam

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Sam,

if you whant to search into a property value, like those described by you, you need to create a new query entry for everyone of the property you'd like to include into your search request. For example you have to create a query entry like this one:

IQueryEntry qe = federatedSearch.getNewQueryEntry();

PropertyName propName = null;

try {

propName = new PropertyName(<property namespace>, <property id>);

qe.setPropertyName(propName);

qe.setRowType(IQueryEntry.ROW_TYPE_ATTRIBUTE);

qe.setValue(<property value>);

qe.setPropertyOperator(IQueryEntry.PROPERTY_OPERATOR_EQUAL);

qe.setPropertyType(<property type for example a date> IQueryEntry.PROPERTY_TYPE_STRING);

qe.setTermWeight(1.0F);

} catch (WcmException e) {

}

so you have to determine the property namespace and property id of the property to include into the search request. In order to do that you can, for example, use the "property metadata service" you can find under KM configuration.

After you have create all your query entry you need to "join" them using the search operators (AND, OR, ...)

a search operator is built as a query entry as well, below an example:

IQueryEntry oper = federatedSearch.getNewQueryEntry();

try {

oper.setRowType(IQueryEntry.ROW_TYPE_OPERATOR);

oper.setValue(<operator type for example AND>IQueryEntry.OPERATOR_AND);

} catch (WcmException e) {

}

You should have also a query entry which represent the search string, for example:

IQueryEntry text = federatedSearch.getNewQueryEntry();

try {

text.setRowType(IQueryEntry.ROW_TYPE_TERM);

text.setTermAction(IQueryEntry.TERM_ACTION_EXACT);

text.setTermWeight(1.0F);

text.setValue((String) currentHM.get(currentKey));

} catch (WcmException e) {

}

After that put all your query entries into a QueryEntryList, for example:

IFederatedSearch federatedSearch = (IFederatedSearch) indexService.getObjectInstance(IWcmIndexConst.FEDERATED_SEARCH_INSTANCE);

IQueryEntryList qel = federatedSearch.getNewQueryEntryList();

//pay attention to add into the qel the query entry in the right order

qel.add(text);

qel.add(oper);

qel.add(qe);

//and then perform a search with this query entry list, for example

ISearchSession ss = federatedSearch.searchWithSession(qel, (ICollection) folderRes, resourceContext);

with this query entry list you search the provided query string into documents name, documents description (by default) AND into for example a your own predefined property of type string.

Hope this help. If you need more info let me know.

Cheers

Roberto

Former Member
0 Kudos

Hi Roberto,

Thanks for your detail sample a lot.

I try to find out the property namespace and property id for my required field from "property metadata service" under KM configuration. However, I can't find it. Will it due to my EP version? I am now using the EP5.

Besides, I found that the search (method executeQuery) will not return error when there are no search result found. However, when I try to access the size of the returned ISearchResultList, an error "ArrayIndexOutOfBoundsException" occured.

How can I check any result returned?

Thanks

Sam

Former Member
0 Kudos

Hi Sam,

regarding how to find the property metadata service and how to manage property configuration try to use help guide to this page:

http://help.sap.com/saphelp_ep50sp6/helpdata/en/1a/9a4a3b80f2ec40aa7456bc87a94259/content.htm

unfortunately I don't have an EP5 in order to give you the right path where to find KM Configuration iview, maybe should be KM Admin -> Configuration

Regarding how you can check your result list I used the following code:

ISearchSession ss = federatedSearch.searchWithSession(qel, (ICollection) folderRes, resourceContext);

if (ss.getNumberResultKeys() > 0) {

srl = ss.getSearchResults(1, ss.getNumberResultKeys());

ISearchResultListIterator srlIt = srl.listIterator();

IResource currentResult = null;

while (srlIt.hasNext()) {

currentResult = srlIt.next().getResource();

...

here your code to print the resource info, for example into a log or into component's response

...

}

}

I'd like to tell you that I used this code with an EP6 SP2 installation. Anyhow if you are running on EP5 SP6 the code should be quite the same.

Ciao

Roberto

Former Member
0 Kudos

Hi Roberto,

Thanks for your solution. I can found the location where maintain the properties. In EP5, the location is "KM Admin > Configuration > Content Management > Global Services > Property Metadata > Properties".

And now I can find the property ID that I needed.

Thanks a lot

Sam

Answers (0)