cancel
Showing results for 
Search instead for 
Did you mean: 

Usage of Java API

Former Member
0 Kudos

Hi All,

Im in need of searching for multiple values in a field (Using Java API) like using the 'in' keyword in SQL .

Can anyone help me with the code snippet.

Thanks & Regards,

Nimal

Accepted Solutions (0)

Answers (1)

Answers (1)

Greg_Austin
Active Participant
0 Kudos

When setting up your search use a TextSearchConstraint. The second parameter of the constructor is the comparison operator. These operators are static variables on the TextSearchConstraint class. Use TextSearchConstraint.CONTAINS.

Former Member
0 Kudos

Hi Austin,

My search selection is of this nature...

SELECT * FROM Persons

WHERE LastName IN ('Anderson','Pietersen')

Regards,

Nimal

Greg_Austin
Active Participant
0 Kudos

Ah sorry I misunderstood. For this case add a TextSearchConstraint to your search with the addSearchItem method for each last name and set the search's comparison operator to OR. That would make it say LastName == 'Anderson' or LastName == 'Pietersen'. You can do it in a loop if you don't know how many names to limit by.

Former Member
0 Kudos

Can you please sent me the code snippet .....

Greg_Austin
Active Participant
0 Kudos

I assume you know how to get the connection to MDM and get FieldIds and TableIds.


        //create a Search object
	Search search = new Search(tableID);
		
	//create a FieldSearchDimension to the MDM field to limit by
	FieldSearchDimension fsd = new FieldSearchDimension(lastNameFieldID);
		
	//create TextSearchConstraint objects for each last name
	TextSearchConstraint tsc = new TextSearchConstraint("Anderson", TextSearchConstraint.EQUALS);		
	TextSearchConstraint tsc2 = new TextSearchConstraint("Pieterson", TextSearchConstraint.EQUALS);
		
	//add the constraints to the search object		
	search.addSearchItem(fsd,tsc);
	search.addSearchItem(fsd,tsc2);
		
	//set the comparison operator to OR
	search.setComparisonOperator(Search.OR_OPERATOR);
		
	//this search will now find all MDM records with last name Anderson or Pieterson

Use this search object in a RetrieveLimitedRecordsCommand and you will get what you need.

nitin_mahajan2
Contributor
0 Kudos

Absolutely correct answer, just that i would advice you to add two things.

while declaring the text search constraints, you should do a case insensitive search, i would advise use the constraint type CONTAINS instead of EQUALS.


TextSearchConstraint tsc = 
          new TextSearchConstraint( "Anderson", TextSearchConstraint.CONTAINS) ;

Regards,

Nitin

Edited by: Nitin Mahajan on Jun 16, 2009 5:32 PM

Edited by: Nitin Mahajan on Jun 16, 2009 5:33 PM