
Untitled
By: a guest on
May 10th, 2012 | syntax:
None | size: 2.32 KB | hits: 35 | expires: Never
<entity name="mainProductData" transformer="RegexTransformer,org.build.com.solr.FacetsTransformer" query="select facets from y">
<field column="facets" splitBy="|"/>
</entity>
Here is the format of the facets field:
ADA=boolean=Yes|Category=string=Kitchen Faucets|Category=string=Pullout Kitchen Faucets|Country of Origin=string=USA|Eco Friendly=boolean=No|Escutcheon Included=boolean=Yes|Faucet Centers=numeric=0|Faucet Holes=numeric=1|Filtering=boolean=No|Flow Rate (GPM)=numeric=2.20|Handle Style=string=Metal Lever|Handles Included=boolean=Yes|Height=numeric=16.63|Hose Length=numeric=33|Installation Type=string=Deck Mounted|Low Lead Compliant=Boolean=Yes|MasterFinish=String=Bronze Tones|MasterFinish=String=Chromes|MasterFinish=String=Nickel Tones|Material=string=Metal|Max Deck Thickness=numeric=1.38|Number Of Handles=numeric=1|Pre Rinse=boolean=No|Pullout Spray=boolean=Yes|Sidespray=boolean=No|Soap Dispenser Included=boolean=No|Spout Height=numeric=10.00|Spout Reach=numeric=9.50|Spout Swivel=numeric=360|Spout Type=string=Swivel|Sub Category=string=Pullout Spray Faucets
|Theme=string=Traditional / Classic|Valve Type=string=Ceramic Disc|Width=numeric=10.5|
Here is my custom transformer code:
package org.build.com.solr;
import org.apache.solr.handler.dataimport.Context;
import org.apache.solr.handler.dataimport.Transformer;
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;
for (Object o : list) {
String[] arr = ((String) o).split("=");
if (arr.length == 3) row.put(arr[0].replaceAll("[^A-Za-z0-9]", "") + "_" + arr[1], arr[2]);
}
} 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;
}
}
Here is my schema:
<dynamicField name="*_string" type="facetstring" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*_numeric" type="tfloat" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*_boolean" type="boolean" indexed="true" stored="true"/>