on 06-16-2009 12:30 PM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
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
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.