On Thu, Oct 29, 2009 at 9:48 PM, Joel Nylund <[email protected]> wrote:
> Hi, I have been reading the solr book and wiki, but I cant find any similar
> examples to what Im looking for.
>
> I have a database field called category, this field needs some text
> manipulation before it goes in the index
>
> here is the java code for what im trying to do:
>
> // categories look like this "prefix category suffix"
> // I want to turn them into "category" remove prefix and suffix and spaces
> before and after
> public static String getPrettyCategoryName(String categoryName)
> {
> String result;
>
> if (categoryName == null || categoryName.equals(""))
> {
> // nothing to do; just return what was passed in.
> result = categoryName;
> }
> else
> {
> result = categoryName.toLowerCase();
>
> if (result.startsWith(startString))
> {
> result = result.substring(startString.length());
> }
>
> if (result.endsWith(endString))
> {
> result = result.substring(0, (result.length() - endString
> .length()));
> }
>
> if (result.length() > 0)
> {
> result = Character.toUpperCase(result.charAt(0))
> + result.substring(1);
> }
> }
>
> return result;
> }
>
>
> Can I have a transformer call a java method?
>
> It seems like I can, but how do I transform must one column. If someone can
> point me to a complete example that transforms a column using java or
> javascript im sure I can figure this out
>
>
Sure, why not. You can either copy this method to your transformer or put
the jar into solr_home/lib and call it from your transformer. The row to be
transformer is a Map<String, Object>. So just lookup the "category" in the
map, transform its value and put it back in the Map.
--
Regards,
Shalin Shekhar Mangar.