package com.sensei.search.query.filters;

import org.apache.lucene.search.Filter;
import org.json.JSONObject;


public class RangeFilterConstructor extends FilterConstructor {
  public static final String FILTER_TYPE = "range";

  @Override
  protected Filter doConstructFilter(Object obj) throws Exception {
    // TODO Auto-generated method stub
    return null;
  }

}

@@ -46,69 +46,533 @@
 ort 
-org.apache.lucene.search.Filter;%0Aimport org.json.JSONObject;%0A
+java.io.IOException;%0Aimport java.util.Iterator;%0A%0Aimport org.apache.lucene.index.IndexReader;%0Aimport org.apache.lucene.search.DocIdSet;%0Aimport org.apache.lucene.search.DocIdSetIterator;%0Aimport org.apache.lucene.search.Filter;%0Aimport org.apache.lucene.search.TermRangeFilter;%0Aimport org.json.JSONObject;%0A%0Aimport com.browseengine.bobo.api.BoboIndexReader;%0Aimport com.browseengine.bobo.facets.FacetHandler;%0A%0Aimport com.browseengine.bobo.facets.filter.FacetRangeFilter;%0Aimport com.browseengine.bobo.query.MatchAllDocIdSetIterator;
 %0A%0Apu
@@ -630,17 +630,17 @@
 structor
- 
+%0A
 %7B%0A  publ
@@ -767,70 +767,2126 @@
 tion
+%0A 
  %7B%0A    
-// TODO Auto-generated method stub%0A    return null;%0A  %7D%0A
+JSONObject json = (JSONObject)obj;%0A%0A    Iterator%3CString%3E iter = json.keys();%0A    if (!iter.hasNext())%0A      return null;%0A%0A    final String field = iter.next();%0A%0A    JSONObject jsonObj = json.getJSONObject(field);%0A%0A    final String from          = jsonObj.optString(%22from%22);%0A    final String to            = jsonObj.optString(%22to%22);%0A    final boolean noOptimize   = jsonObj.optBoolean(%22_noOptimize%22, false);%0A%0A    return new Filter()%0A    %7B%0A      @Override%0A      public DocIdSet getDocIdSet(final IndexReader reader) throws IOException%0A      %7B%0A        if (!noOptimize)%0A        %7B%0A          if (reader instanceof BoboIndexReader)%0A          %7B%0A            BoboIndexReader boboReader = (BoboIndexReader)reader;%0A            FacetHandler facetHandler = boboReader.getFacetHandler(field);%0A            if (facetHandler != null)%0A            %7B%0A              StringBuilder sb = new StringBuilder(%22%5B%22);%0A              if (from == null)%0A                sb.append(%22*%22);%0A              else%0A                sb.append(from);%0A              sb.append(%22 TO %22);%0A              if (to == null)%0A                sb.append(%22*%22);%0A              else%0A                sb.append(to);%0A              sb.append(%22%5D%22);%0A%0A              FacetRangeFilter filter = new FacetRangeFilter(facetHandler, sb.toString());%0A              return filter.getDocIdSet(reader);%0A            %7D%0A          %7D%0A        %7D%0A        if (from == null)%0A          if (to == null)%0A            return new DocIdSet()%0A            %7B%0A              @Override%0A              public boolean isCacheable()%0A              %7B%0A                return true;%0A              %7D%0A%0A              @Override%0A              public DocIdSetIterator iterator() throws IOException%0A              %7B%0A                return new MatchAllDocIdSetIterator(reader);%0A              %7D%0A            %7D;%0A          else%0A            return new TermRangeFilter(field, from, to, false, true).getDocIdSet(reader);%0A        else if (to == null)%0A          return new TermRangeFilter(field, from, to, true, false).getDocIdSet(reader);%0A%0A        return new TermRangeFilter(field, from, to, true, true).getDocIdSet(reader);%0A      %7D%0A    %7D;%0A  %7D
 %0A%7D%0A

Range filter constructor.