1.4.2 solr字段类型--(1.4.2.3)使用货币和汇率

1.4.2 solr字段类型

  (1.4.2.1) 字段类型定义和字段类型属性.

  (1.4.2.2) solr附带的字段类型

  (1.4.2.3) 使用货币和汇率

  (1.4.2.4) 使用Dates(日期)

  (1.4.2.5) 使用枚举字段

  (1.4.2.6) 使用外部文件和程序

  (1.4.2.7) 字段属性使用案例

使用货币和汇率

  currency字段支持solr/lucene查询货币--一次货币转换和汇率.支持以下功能:

  定点查询

  范围查询

  函数范围查询(4.2版本以后)

  排序

  通过货币代码或者符号解析货币

  对称与不对称汇率(不对称的汇率交换是很有用的,如果有费用规定关联货币的话.)

 配置货币

  货币字段类型在schema.xml中定义,默认配置如下:

<fieldType name="currency" class="solr.CurrencyField"
    precisionStep="8" defaultCurrency="USD" currencyConfig="currency.xml" />

  在这个例子中,我们定义了name,class, defaultCurrency使用USD,用于美元.同样还使用currency.xml定义了一个货币配置.

  在索引的时候,money字段可以索引成一个本地的货币.例如,如果一个电子商务网站上的产品是用欧元罗列的,那么索引这个字段为 "1000,EUR",这个价格应该用逗号分割开货币记号.同时这个数字应该是float的.

汇率变更

  通过指定一个供应商来变更汇率,目前支持两种:FileExchangeRateProvider和OpenExchangeRatesOrgProvider.

FileExchangeRateProvider

  提供一个汇率变更的文件,这也是默认的.也就是说使用这个provide,你只需要指定路径即可,例子:

<?xml version="1.0" ?>
<currencyConfig version="1.0">
    <rates>
        <!-- Updated from http://www.exchangerate.com/ at 2011-09-27 -->
        <rate from="USD" to="ARS" rate="4.333871" comment="ARGENTINA Peso" />
        <rate from="USD" to="AUD" rate="1.025768" comment="AUSTRALIA Dollar" />
        <rate from="USD" to="EUR" rate="0.743676" comment="European Euro" />
        <rate from="USD" to="BRL" rate="1.881093" comment="BRAZIL Real" />
        <rate from="USD" to="CAD" rate="1.030815" comment="CANADA Dollar" />
        <rate from="USD" to="CLP" rate="519.0996" comment="CHILE Peso" />
        <rate from="USD" to="CNY" rate="6.387310" comment="CHINA Yuan" />
        <rate from="USD" to="CZK" rate="18.47134" comment="CZECH REP. Koruna" />
        <rate from="USD" to="DKK" rate="5.515436" comment="DENMARK Krone" />
        <rate from="USD" to="HKD" rate="7.801922" comment="HONG KONG Dollar" />
        <rate from="USD" to="HUF" rate="215.6169" comment="HUNGARY Forint" />
        <rate from="USD" to="ISK" rate="118.1280" comment="ICELAND Krona" />
        <rate from="USD" to="INR" rate="49.49088" comment="INDIA Rupee" />
        <rate from="USD" to="XDR" rate="0.641358" comment="INTNL MON. FUND SDR" />
        <rate from="USD" to="ILS" rate="3.709739" comment="ISRAEL Sheqel" />
        <rate from="USD" to="JPY" rate="76.32419" comment="JAPAN Yen" />
        <rate from="USD" to="KRW" rate="1169.173" comment="KOREA (SOUTH) Won" />
        <rate from="USD" to="KWD" rate="0.275142" comment="KUWAIT Dinar" />
        <rate from="USD" to="MXN" rate="13.85895" comment="MEXICO Peso" />
        <rate from="USD" to="NZD" rate="1.285159" comment="NEW ZEALAND Dollar" />
        <rate from="USD" to="NOK" rate="5.859035" comment="NORWAY Krone" />
        <rate from="USD" to="PKR" rate="87.57007" comment="PAKISTAN Rupee" />
        <rate from="USD" to="PEN" rate="2.730683" comment="PERU Sol" />
        <rate from="USD" to="PHP" rate="43.62039" comment="PHILIPPINES Peso" />
        <rate from="USD" to="PLN" rate="3.310139" comment="POLAND Zloty" />
        <rate from="USD" to="RON" rate="3.100932" comment="ROMANIA Leu" />
        <rate from="USD" to="RUB" rate="32.14663" comment="RUSSIA Ruble" />
        <rate from="USD" to="SAR" rate="3.750465" comment="SAUDI ARABIA Riyal" />
        <rate from="USD" to="SGD" rate="1.299352" comment="SINGAPORE Dollar" />
        <rate from="USD" to="ZAR" rate="8.329761" comment="SOUTH AFRICA Rand" />
        <rate from="USD" to="SEK" rate="6.883442" comment="SWEDEN Krona" />
        <rate from="USD" to="CHF" rate="0.906035" comment="SWITZERLAND Franc" />
        <rate from="USD" to="TWD" rate="30.40283" comment="TAIWAN Dollar" />
        <rate from="USD" to="THB" rate="30.89487" comment="THAILAND Baht" />
        <rate from="USD" to="AED" rate="3.672955" comment="U.A.E. Dirham" />
        <rate from="USD" to="UAH" rate="7.988582" comment="UKRAINE Hryvnia" />
        <rate from="USD" to="GBP" rate="0.647910" comment="UNITED KINGDOM Pound" />

        <!-- Cross-rates for some common currencies -->
        <rate from="EUR" to="GBP" rate="0.869914" />
        <rate from="EUR" to="NOK" rate="7.800095" />
        <rate from="GBP" to="NOK" rate="8.966508" />
    </rates>
</currencyConfig>

OpenExchangeRatesOrgProvider

  使用solr4,你可以配置solr从  OpenExchangeRates.Org 下载汇率变更,每隔一段时间,更新一个USD和158种货币的汇率.这个是同步的.

这里你需要指定一个providerClass:

<fieldType name="currency" class="solr.CurrencyField"
    precisionStep="8" providerClass="solr.OpenExchangeRatesOrgProvider"
    refreshInterval="60" ratesFileLocation="http://internal.server/rates.json" />

 refreshInterval的时间按单位是分钟.所以这里是每隔一个小时更新一次.

原文地址:https://www.cnblogs.com/a198720/p/4283976.html