package org.clarksnut.models.jpa;

import org.clarksnut.models.FacetModel;
import org.clarksnut.models.RangeModel;
import org.hibernate.search.query.facet.Facet;

public class NumericRangeFacetAdapter implements FacetModel<RangeModel<Long>> {

    private final Facet facet;

    public NumericRangeFacetAdapter(Facet facet) {
        this.facet = facet;
    }

    @Override
    public RangeModel<Long> getValue() {
        String[] split = facet.getValue()
                .replaceAll("\"", "")
                .replaceAll("[\\[\\]()]", "")
                .split(",");
        Long from = Long.parseLong(split[0]);
        Long to = Long.parseLong(split[1]);

        return new RangeModel<Long>() {
            @Override
            public Long getFrom() {
                return from;
            }

            @Override
            public Long getTo() {
                return to;
            }
        };
    }

    @Override
    public int getCount() {
        return facet.getCount();
    }
}

@@ -456,46 +456,8 @@
 e()%0A
-                .replaceAll(%22%5C%22%22, %22%22)%0A
     
@@ -546,16 +546,45 @@
 g from =
+ !split%5B0%5D.trim().isEmpty() ?
  Long.pa
@@ -599,17 +599,28 @@
 split%5B0%5D
-)
+.trim()) : 0
 ;%0A      
@@ -630,16 +630,45 @@
 ong to =
+ !split%5B1%5D.trim().isEmpty() ?
  Long.pa
@@ -683,17 +683,28 @@
 split%5B1%5D
-)
+.trim()) : 0
 ;%0A%0A     

solve bug on facet range