cancel
Showing results for 
Search instead for 
Did you mean: 

Keyword Search using the SOUNDS_LIKE modifier, Java API

Former Member
0 Kudos

Hello guys:

Does anyone have a piece of code that shows how can I do a search, using the keyword and the SOUNDS_LIKE mod, like on the Data Manager?

I've seen the blog "Performing Free Form Searches with MDM Java API" but I'm afraid this doesn't apply (it's about free-form, as the name says)

Thanks!

Alejandro

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Alejandro,

maybe this piece of code helps you a bit. The most important is the static attribute SOUNDS_LIKE of the TextSearchConstraint class.

Also try to find the MDM Java Example files @ service.sap.com/installMDM . There is a complete introduction on how to search against an MDM repository which is very useful.


		// assumption: 
		// you have connected to some repository which contains a field "Material Number" 
		// with a session and you have already read the MainTable properties to identify
		// the MainTableID, as well as some fields yo want to read.		

		// set search conditions
		Search search = new Search(<yourMainTableId>);
		String fieldname = "Material Number";

		ResultDefinition rd = new ResultDefinition(<yourMainTableId>);;
		
		FieldId field = <someFieldFromYourRepository>;
		rd.add(field); 
		// add some additional fields you want to select here ...
		
		FieldSearchDimension searchDimension = new FieldSearchDimension(field);
		TextSearchConstraint searchString =	new TextSearchConstraint(materialNumber, TextSearchConstraint.SOUNDS_LIKE);

		search.addSearchItem(searchDimension, searchString);

		RetrieveLimitedRecordsCommand limitingCommand = new RetrieveLimitedRecordsCommand(<yourConnection>);
		limitingCommand.setSession(<yourSession>);
		limitingCommand.setResultDefinition(rd);

		limitingCommand.setSearch(search);
		limitingCommand.setPageSize(10);
		try {
			limitingCommand.execute();
			RecordResultSet rs = limitingCommand.getRecords();
		catch(Exception e){
			e.printStackTrace();
		}

If you need more help, let me know

Best regards,

Martin

Former Member
0 Kudos

Thanks

Can it be done using the first MDM API MDM4J?

Thanks

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Alejandro,

although I thonk you should not use the old API anymore because it will most likely not be supported in future versions, I crawled through some old code and found this:


/* retrieve one record where the "name 2" field sounds like "Smith" */
  FreeFormTableParameter tableParam = search.GetParameters().NewFreeFormTableParameter(table);
  FreeFormParameterField field = tableParam.GetFields().New("Name 2");
  field.GetValues().NewString("Smith", FreeFormParameter.SoundsLikeSearchType );
/* go on and perform the search */

... the important part here is the FreeFormTableParameter.SoundsLikeSearchType ...

I hope this helps

Best Regards,

Martin

Former Member
0 Kudos

Hello Martin:

Actually, I ended up using the new API. It's just that it's not quite documented. At least, we have now the two options

Thanks a lot!

Alejandro