cancel
Showing results for 
Search instead for 
Did you mean: 

How to search with multiple constraints in the new java API?

Former Member
0 Kudos

I'm having a problem using the new MDM API to do searches with multiple constraints. Here are the classes I'm trying to use, and the scenario I'm trying to implement:

Classes:

SearchItem: Interface

SearchGroup: implements SearchItem, empty constructor,

addSearchItem (requires SearchDimension and SearchConstraint, or just a SearchItem),

setComparisonOperator

SearchParameter: implements SearchItem, constructor requires SearchDimension and SearchConstraint objects

Search: extends SearchGroup, constructor requires TableId object

RetrieveLimitedRecordsCommand: setSearch method requires Search object

FieldDimension: constructor requires FieldId object or FieldIds[] fieldPath

TextSearchConstraint: constructor requires string value and int comparisonOperator(enum)

BooleanSearchConstraint: constructor requires boolean value

Scenario:

Okay, so say we have a main table, Products. We want to search the table for the following:

field IsActive = true

field ProductColor = red or blue or green

So the question is how to build this search with the above classes? Everything I've tried so far results in the following error:

Exception in thread "main" java.lang.UnsupportedOperationException: Search group nesting is currently not supported.

at com.sap.mdm.search.SearchGroup.addSearchItem(Unknown Source)

I can do just the ProductColor search like this:

Search mySearch = new Search(<Products TableId>);

mySearch.setComparisonOperator(Search.OR_OPERATOR);

FieldDimension myColorFieldDim = new FieldDimension(<ProductColor FieldId>);

TextSearchConstraint myTextConRed = new TextSearchConstraint("red",TextSearchConstraint.EQUALS);

TextSearchConstraint myTextConBlue = new TextSearchConstraint("blue",TextSearchConstraint.EQUALS);

TextSearchConstraint myTextConGreen = new TextSearchConstraint("green",TextSearchConstraint.EQUALS);

mySearch.addSearchItem(myColorFieldDim,myTextConRed);

mySearch.addSearchItem(myColorFieldDim,myTextConBlue);

mySearch.addSearchItem(myColorFieldDim,myTextConGreen);

the question is how do I add the AND of the BooleanSearchConstraint?

FieldDimension myActiveFieldDim = new FieldDimension(<IsActive FieldId>);

BooleanSearchConstraint myBoolCon = new BooleanSearchConstraint(true);

I can't just add it to mySearch because mySearch is using OR operator, so it would return ALL of the Products records that match IsActive = true. I tried creating a higher level Search object like this:

Search topSearch = new Search(<Products TableId>);

topSearch.setComparisonOperator(Search.AND_OPERATOR);

topSearch.addSearchItem(mySearch);

topSearch.addSearchItem(myActiveFieldDim,myBoolCon);

But when I do this I get the above "Search group nesting is currently not supported" error. Does that mean this kind of search cannot be done with the new MDM API?

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

I haven't seen anything in my own limited experience that allows for embedding below one level of constraints. Have you heard anything that this might be in SP05?

Former Member
0 Kudos

I'm actually testing a pre-release of SP05 right now, and it still is not functional. The best that can be done is to use a PickListSearchConstraint to act as an OR within a field. But PickList is limited to lookup Id values, text attribute values, numeric attribute values and coupled attribute values. It works for me in some cases where I have lookup Id values, but not in other cases where the users want to search on multiple text values within a single field.