You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ja...@apache.org on 2012/03/12 10:56:55 UTC
svn commit: r1299602 - in /lucene/dev/trunk/solr:
core/src/java/org/apache/solr/schema/CurrencyField.java
example/solr/conf/schema.xml
Author: janhoy
Date: Mon Mar 12 09:56:55 2012
New Revision: 1299602
URL: http://svn.apache.org/viewvc?rev=1299602&view=rev
Log:
SOLR-2202: Avoid dependency on "tlong" and "string" in schema, add precisionStep param
Modified:
lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/CurrencyField.java
lucene/dev/trunk/solr/example/solr/conf/schema.xml
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/CurrencyField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/CurrencyField.java?rev=1299602&r1=1299601&r2=1299602&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/CurrencyField.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/CurrencyField.java Mon Mar 12 09:56:55 2012
@@ -61,14 +61,16 @@ import java.util.Map;
public class CurrencyField extends FieldType implements SchemaAware, ResourceLoaderAware {
protected static final String PARAM_DEFAULT_CURRENCY = "defaultCurrency";
protected static final String PARAM_RATE_PROVIDER_CLASS = "providerClass";
+ protected static final Object PARAM_PRECISION_STEP = "precisionStep";
protected static final String DEFAULT_RATE_PROVIDER_CLASS = "org.apache.solr.schema.FileExchangeRateProvider";
protected static final String DEFAULT_DEFAULT_CURRENCY = "USD";
+ protected static final String DEFAULT_PRECISION_STEP = "0";
protected static final String FIELD_SUFFIX_AMOUNT_RAW = "_amount_raw";
protected static final String FIELD_SUFFIX_CURRENCY = "_currency";
- protected static final String FIELD_TYPE_CURRENCY = "string";
- protected static final String FIELD_TYPE_AMOUNT_RAW = "tlong";
private IndexSchema schema;
+ protected FieldType fieldTypeCurrency;
+ protected FieldType fieldTypeAmountRaw;
private String exchangeRateProviderClass;
private String defaultCurrency;
private ExchangeRateProvider provider;
@@ -93,9 +95,27 @@ public class CurrencyField extends Field
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid currency code " + this.defaultCurrency);
}
+ String precisionStepString = args.get(PARAM_PRECISION_STEP);
+ if (precisionStepString == null) {
+ precisionStepString = DEFAULT_PRECISION_STEP;
+ }
+
+ // Initialize field type for amount
+ fieldTypeAmountRaw = new TrieLongField();
+ fieldTypeAmountRaw.setTypeName("amount_raw_type_tint");
+ Map<String,String> map = new HashMap<String,String>(1);
+ map.put("precisionStep", precisionStepString);
+ fieldTypeAmountRaw.init(schema, map);
+
+ // Initialize field type for currency string
+ fieldTypeCurrency = new StrField();
+ fieldTypeCurrency.setTypeName("currency_type_string");
+ fieldTypeCurrency.init(schema, new HashMap<String,String>());
+
args.remove(PARAM_RATE_PROVIDER_CLASS);
args.remove(PARAM_DEFAULT_CURRENCY);
-
+ args.remove(PARAM_PRECISION_STEP);
+
try {
// TODO: Are we using correct classloader?
Class<?> c = Class.forName(exchangeRateProviderClass);
@@ -145,13 +165,13 @@ public class CurrencyField extends Field
return schema.getField(field.getName() + POLY_FIELD_SEPARATOR + FIELD_SUFFIX_CURRENCY);
}
- private void createDynamicCurrencyField(String suffix, String fieldType) {
+ private void createDynamicCurrencyField(String suffix, FieldType type) {
String name = "*" + POLY_FIELD_SEPARATOR + suffix;
Map<String, String> props = new HashMap<String, String>();
props.put("indexed", "true");
props.put("stored", "false");
props.put("multiValued", "false");
- org.apache.solr.schema.FieldType type = schema.getFieldTypeByName(fieldType);
+ props.put("omitNorms", "true");
int p = SchemaField.calcProps(name, type, props);
schema.registerDynamicField(SchemaField.create(name, type, p, null));
}
@@ -162,9 +182,8 @@ public class CurrencyField extends Field
* @param indexSchema The index schema.
*/
public void inform(IndexSchema indexSchema) {
- // TODO: Should we allow configurable field-types or in another way not be dependent on static type names types in schema?
- createDynamicCurrencyField(FIELD_SUFFIX_CURRENCY, FIELD_TYPE_CURRENCY);
- createDynamicCurrencyField(FIELD_SUFFIX_AMOUNT_RAW, FIELD_TYPE_AMOUNT_RAW);
+ createDynamicCurrencyField(FIELD_SUFFIX_CURRENCY, fieldTypeCurrency);
+ createDynamicCurrencyField(FIELD_SUFFIX_AMOUNT_RAW, fieldTypeAmountRaw);
}
/**
Modified: lucene/dev/trunk/solr/example/solr/conf/schema.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/example/solr/conf/schema.xml?rev=1299602&r1=1299601&r2=1299602&view=diff
==============================================================================
--- lucene/dev/trunk/solr/example/solr/conf/schema.xml (original)
+++ lucene/dev/trunk/solr/example/solr/conf/schema.xml Mon Mar 12 09:56:55 2012
@@ -458,11 +458,12 @@
<!-- Money/currency field type. See http://wiki.apache.org/solr/MoneyFieldType
Parameters:
defaultCurrency: Specifies the default currency if none specified. Defaults to "USD"
+ precisionStep: Specifies the precisionStep for the TrieLong field used for the amount
providerClass: Lets you plug in other exchange backend. Defaults to FileExchangeRateProvider
The FileExchangeRateProvider takes one parameter:
currencyConfig: name of an xml file holding exhange rates
-->
- <fieldType name="currency" class="solr.CurrencyField" currencyConfig="currency.xml" defaultCurrency="USD"/>
+ <fieldType name="currency" class="solr.CurrencyField" precisionStep="8" defaultCurrency="USD" currencyConfig="currency.xml" />
<!-- some examples for different languages (generally ordered by ISO code) -->