pub.cache:search
WmPublic. Searches through an indexed cache and returns the results. The pub.cache:search service accepts the selection criteria as an IData object and performs the search by converting the IData object to a search query of Ehcache.
Note: | Before using this service, you must make the cache searchable. For more information about making a cache searchable, see webMethods Integration Server Administrator’s Guide. |
Input Parameters
cacheManagerName | String Name of the cache manager that manages the cache. This parameter is case sensitive. |
cacheName | String Name of the cache from which the search results are to be returned. This parameter is case sensitive. |
includeAttributes | String Optional. List of attributes that should be included in the search results. |
includeKey | String Optional. Indicates whether or not the keys should be returned as part of the search results. true indicates that the keys should be returned as part of the search results. false indicates that the keys should not be returned as part of the search results. This is the default. Note: | You should set this parameter to true only if the value is required for your programming logic. |
|
includeValue | String Optional. Indicates whether or not the values should be returned as part of the search results. true indicates that the values should be returned as part of the search results. false indicates that the values should not be returned as part of the search results. This is the default. Note: | You should set this parameter to true only if the value is required for your programming logic. |
|
criteria | Document A document (IData) that specifies the conditions based on which the data in the cache is to be queried. |
| Value | Description |
| OP1 | String or Document A string operand or a nested document type that can be evaluated by a logical operator. |
| OPR | String A logical (and, or, and not) or comparison operator (between, gt (greater than), eq (equal to), and so on). For a complete list of operators that Integration Server supports as the value for the criteria\OPR parameter, see the Usage Notes for this service. |
| OP2 | String, Document, Object, or Object List A string operand, nested document type, object, or object list that can be evaluated by a logical operator. |
maxResults | String Optional. The maximum number of results to return. If maxResults is not specified, Integration Server returns all the results. |
groupBy | String List Optional. The unique values of specified attributes based on which the search results are to be grouped. The attributes that you specify for grouping the results must be included in the list of attributes specified for the includeAttributes parameter. |
orderBy | String Table Optional. Whether the service results are to be returned in ascending or descending order. Values for this parameter must be specified as a two-dimensional string array comprising the field name and whether DESCENDING or ASCENDING (case sensitive) in the following format: {{"fieldName","order"},{"fieldName","order"}} Where order is ASCENDING or DESCENDING. For example, if you have configured name and age as the search attributes for the personCache cache that stores name, age, and address, the orderBy parameter can be specified as shown below: {{"name","ASCENDING"}} -or- {{"name","ASCENDING"},{"age","DESCENDING"}} |
aggregator | String Table Aggregator function such as average, count, max, min, or sum that you want to be applied on the search results. Values for this parameter should be specified as a two-dimensional string array in the following format: {{"fieldName","aggregator"}, {"fieldName","aggregator"}} Where aggregator can be average, count, max, min, or sum (case-insensitive). For example, {{"age","Max"}} or {{"income","Average"}}. If you want to use the aggregator function, you must: ![*](bullet.gif) Specify a value for the groupBy parameter. ![*](bullet.gif) Set the includeKey and includeValue parameters to false. |
Output Parameters
result | Object List The returned results of the search. Each object in the result parameter is of type com.wm.app.b2b.client.cache.config.SearchResult. For more information about com.wm.app.b2b.client.cache.config.SearchResult type, see webMethods Integration Server Java API Reference. Each object contains information about the cache element, key, value, search attribute values, and aggregator results, if any. |
Usage Notes
A sample IData that you can specify as the criteria input parameter is given below. The following input searches the personCache cache for entries, where age is greater than 60 and gender is female.
IData idata = IDataFactory.create();
//Cache information
IDataMap map = new IDataMap(idata) ;
map.put("cacheManagerName", "SearchTestManager") ;
map.put("cacheName", "personCache") ;
map.put("includeKey", "true") ;
map.put("includeValue", "true") ;
//Condition 1 - Age > 60
IData input1 = IDataFactory.create() ;
IDataCursor cursor1 = input1.getCursor() ;
IDataUtil.put(cursor1, "OP1", "age") ;
IDataUtil.put(cursor1, "OPR", "gt") ;
IDataUtil.put(cursor1, "OP2", 60) ;
//Condition 2 - Gender == Female
IData input2 = IDataFactory.create() ;
IDataCursor cursor2= input2.getCursor() ;
IDataUtil.put(cursor2, "OP1", "gender") ;
IDataUtil.put(cursor2, "OPR", "eq") ;
IDataUtil.put(cursor2, "OP2", Person.Gender.FEMALE) ;
//Joining conditions, condition 1 && condition 2
IData input3 = IDataFactory.create() ;
IDataCursor cursor3 = input3.getCursor() ;
IDataUtil.put(cursor3, "OP1", input1) ;
IDataUtil.put(cursor3, "OPR", "AND") ;
IDataUtil.put(cursor3, "OP2", input2) ;
map.put("criteria", input3) ;
//Run the search
IData result = invoke(NSName.create("pub.cacheimpl:search"),
idata);
Object[] objectList = (Object[]) IDataUtil.get(result.getCursor(),
"result");
for (int i = 0; i < objectList.length; i++) {
Person value = (Person) ((SearchResult) objectList[i]).getValue();
System.out.println(value.getGender());
System.out.println( value.getAge());
}
When using the between operator for the criteria\OPR parameter, you must specify start and end values. That is, you must specify a two-element Object List with the 0 element as the start value and the first element as the end value. For example:
//Condition 1 < age <10
IData input1 = IDataFactory.create() ;
IDataCursor cursor1 = input1.getCursor() ;
IDataUtil.put(cursor1, "OP1", "age") ;
IDataUtil.put(cursor1, "OPR", "between") ;
IDataUtil.put(cursor1, "OP2", {1,10}) ;
Integration Server supports the following operators as the value for criteria\OPR parameter:
Operators | Description |
and | AND logical operator |
between | Comparison between two values. |
eq | Equals |
gt | Greater than |
ge | Greater than or equal to |
ilike | Regular expression matcher using '?' and "*". |
in | Comparison operator meaning in the collection given as an argument. |
isNull | Checks whether the value of an attribute is null. |
lt | Less than. |
le | Less than or equal to |
not | NOT logical operator |
ne | Not equal to |
notNull | Checks whether the value of an attribute with given name is NOT null. |
or | OR logical operator |
Because the state of the cache can change between search executions, include all of the aggregators to the search query at the same time, so that the returned aggregators are of the same iteration of the cache.
By default a search will return an unlimited number of results. If too many results are returned, Integration Server might issue an OutOfMemoryError and become unresponsive. Limit the size of the results using the maxResults parameter.
To ensure that Integration Server does not issue an OutOfMemoryError while invoking the service using Designer, do the following:
1. Copy the ehcache-ee.jar from Software AG_directory /common/lib/ to the Software AG_directory /Designer/eclipse/plugins/com.softwareag.is.runtimejars folder.
2. Edit the Software AG_directory /Designer/eclipse/plugins/com.softwareag.is.runtimejars/META-INF/MANIFEST.MF file by appending ehcache-ee.jar to the "Bundle-ClassPath:" property. Maintain the characters per line in the MANIFEST.MF file while editing.
3. Restart Designer using the -clean option:
Software AG_directory
/Designer/eclipse/ eclipse.exe -clean
This cleans the folders in the following directory:
<workspace_location>\.metadata\.plugins\com.softwareag.is.runtimejars.