SearchCriteriaFormatter
The SearchCriteriaFormatter delegate can be configured for each of the search query parameters (SearchQueryParams) to format the input before sending the criteria to E3C. If the formatter is not configured the default formatter(com.ptc.sc.services.plugins.DefaultKeyWordFormatter)is used.
<Service context="default"
name="com.ptc.sc.services.plugins.SearchInputFormatter">
<Option serviceClass=
"com.ptc.sc.services.plugins.DefaultKeyWordFormatter"
requestor="null" selector= "DEFAULT"/>
<Option serviceClass=
"com.ptc.sc.services.plugins.DefaultKeyWordFormatter"
requestor="null" selector= "keyword"/>
<Option serviceClass=
"com.ptc.sc.services.plugins.MultiValueSearchInputFormatter"
requestor="null" selector= "infotype"/>
<Option serviceClass=
"com.ptc.sc.services.plugins.MultiValueSearchInputFormatter"
requestor="null" selector= "publicationtype"/>
<Option serviceClass=
"com.ptc.sc.services.plugins.SearchTypeSearchInputFormatter"
requestor="null" selector= "searchtype"/>
</Service>
public interface SearchInputFormatter {
/**
* Method to parse and format search input
* <BR><BR><B>Supported API: </B>true
* <BR><BR><B>Extendable: </B>true
*
* @param keyword - String
* @throws Exception
*/
public String formatInput (String keyword) throws Exception;
}
The default formatter(com.ptc.sc.services.plugins.DefaultKeyWordFormatter) does not do any formatting rather it preserves the input received from the UI.
The multi-value formatter(com.ptc.sc.services.plugins.MultiValueSearchInputFormatter) formats the input received in the format of value1,value2,value3 to value1|value2|value3.
The search type formatter(com.ptc.sc.services.plugins.SearchTypeSearchInputFormatter) omits the “any” value received from the UI and does not send the “searchType” to the E3C. Any other value received is sent automatically.
Customization
New formatters can be added and configured to the input parameters such as formatting a date value before sending to the E3C or formatting the keyword received from the client e.t.c
Implement a new custom formatter as needed and implement the logic needed to format the input value such as below. The formatter below parses the input based on a regular expression and formats the key word input.


import wt.util.WTProperties;

public class KeywordInputFormatter implements SearchInputFormatter {

@Override
public String formatInput(String keyword) throws Exception {

// custom parser that uses regular expressions to expand
// search terms (preserve original but include additional terms)

WTProperties wtProperties = WTProperties.getServerProperties();
String searchTerm =
wtProperties.getProperty("com.ptc.sc.search.searchTerm");

String searchTerms<] = searchTerm.split(" ");

// if the keyword has double quotes , don't format the input

if (!keyword.contains("\"") &&
keyword.matches(searchTerms<0])) {
keyword = keyword + " OR " +
keyword.replaceAll(searchTerms<1], searchTerms<2]);
}

return keyword;
}

}