Thank you for your input. With your help I was able to solve my problem.
Although I could find no good example of how to handle multivalued fields
with a custom transformer online your comments helped me to find a solution.

Here is the code that handles both multi-valued and single valued fields.


package org.build.com.solr;

/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.apache.solr.handler.dataimport.Context;
import org.apache.solr.handler.dataimport.Transformer;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class FacetsTransformer extends Transformer {
  
  public Object transformRow(Map<String, Object> row, Context context) {
    Object tf = row.get("facets");
        if (tf != null) {
          if (tf instanceof List) {
            List list = (List) tf;
            String tempKey = "";
            for (Object o : list) {
              String[] arr = ((String) o).split("=");
              if (arr.length == 3) {
                tempKey = arr[0].replaceAll("[^A-Za-z0-9]", "") + "_" +
arr[1];
                if (row.containsKey(tempKey))
                {
                  List<String> tempArrayList =
(ArrayList<String>)row.get(tempKey);
                  tempArrayList.add(arr[2]);
                  row.put(tempKey, tempArrayList );
                } else {
                  List<String> tempArrayList = new ArrayList<String>();
                  tempArrayList.add(arr[2]);
                  row.put(tempKey, tempArrayList);
                }
              }
            }
          } else {
            String[] arr = ((String) tf).split("=");
            if (arr.length == 3) row.put(arr[0].replaceAll("[^A-Za-z0-9]",
"") + "_" + arr[1], arr[2]);
          }
          row.remove("facets");
        }
        return row;
  }
}


--
View this message in context: 
http://lucene.472066.n3.nabble.com/Solr-Import-Handler-Custom-Transformer-not-working-tp3978746p3983704.html
Sent from the Solr - User mailing list archive at Nabble.com.

Reply via email to