使用货币和汇率

  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的时间按单位是分钟.所以这里是每隔一个小时更新一次.

最新文章

  1. 【Windows编程】系列第六篇:创建Toolbar与Statusbar
  2. shh简化
  3. 我的ORM之四--删除
  4. LINQ中的一些查询语句格式
  5. 【iCore2模块】VGA模块样板谍照!
  6. org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
  7. Codeforces Gym 100513F F. Ilya Muromets 线段树
  8. 正确使用STL-MAP中Erase函数
  9. Xamarin.Android 4.10.01068 &amp; Xamarin.iOS 1.8.361
  10. ARCI--做事情的重要方法论
  11. SCALA当的trait
  12. ecshop后台权限增加
  13. 获取本地的jvm信息,进行图形化展示
  14. XMind 8 pro update 7激活方法
  15. 腾讯的产品思维 VS 阿里的终局思维
  16. Lua 语言基本语法
  17. loj#2509. 「AHOI / HNOI2018」排列(思维题 set)
  18. JAVA操作字符串
  19. Python3入门(十一)——IO编程
  20. linux查看内存free

热门文章

  1. 使用google map v3 api 开发地图服务
  2. MSDN上面测试Window的方法(很好用)
  3. Android之旅 笔记总结(一)
  4. UVa 1312 Cricket Field (枚举+离散化)
  5. sql 无法识别的配置节 system.serviceModel
  6. ngTbale假分页实现排序、搜索、导出CSV等功能
  7. Js制作点击输入框时默认文字消失的效果
  8. 在类库中使用Session
  9. yum命令的使用
  10. cocos2d-x 2.2 资源更新AssetsManager例子代码