Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-14500

currency function doesn't work for asymmetric rates

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      Given a currency field of CurrencyFieldType, the following asymmetric rates:

      <rate from="SGD" to="USD" rate="0.72204658296750000000" />
      <rate from="USD" to="SGD" rate="1.45506540000000000000" /> 

      and a price field with a value of "24.500000,SGD"

      The following usage of the currency function as a pseudo-field in a query returns incorrect values:

      curl -s 'http://10.43.41.81:32080/solr/product_details/select?fl=price,price_sgd%3Acurrency(price,SGD)&fq=id%3A57373P16&q=*%3A*&rows=1'
      {
        "responseHeader":{
          "zkConnected":true,
          "status":0,
          "QTime":0,
          "params":{
            "q":"*:*",
            "fl":"price,price_sgd:currency(price,SGD)",
            "fq":"id:57373P16",
            "rows":"1"}},
        "response":{"numFound":1,"start":0,"docs":[
            {
              "price":"24.500000,SGD",
              "price_sgd":25.74}]
        }} 

      I have traced this to the fact that CurrencyFieldType.getValueSource returns a value that is first converted to the default currency.  When dealing with asymmetric rates this always risks introducing conversion errors.

      Attachments

        1. test.patch
          3 kB
          Murray Johnston
        2. solr14500.patch
          5 kB
          Murray Johnston

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mjohnston Murray Johnston
              Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: