-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
agazzarini
committed
Apr 1, 2015
1 parent
b583c99
commit 660c31f
Showing
6 changed files
with
381 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...n/java/org/gazzax/labs/solrdf/handler/search/faceting/rq/DateRangeEndpointCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.gazzax.labs.solrdf.handler.search.faceting.rq; | ||
|
||
import java.text.ParseException; | ||
import java.util.Date; | ||
|
||
import org.apache.solr.common.SolrException; | ||
import org.apache.solr.common.SolrException.ErrorCode; | ||
import org.apache.solr.schema.DateField; | ||
import org.apache.solr.schema.SchemaField; | ||
import org.apache.solr.util.DateMathParser; | ||
|
||
@SuppressWarnings("deprecation") | ||
public class DateRangeEndpointCalculator extends RangeEndpointCalculator<Date> { | ||
|
||
public DateRangeEndpointCalculator(final SchemaField f) { | ||
super(f); | ||
} | ||
|
||
@Override | ||
public String format(Date value) { | ||
return ((DateField)field.getType()).toExternal(value); | ||
} | ||
|
||
@Override | ||
public Date getValue(String rawval) { | ||
return ((DateField) field.getType()).parseMath(null, rawval); | ||
} | ||
|
||
@Override | ||
public Date addGap(Date value, String gap) { | ||
final DateMathParser dmp = new DateMathParser(); | ||
dmp.setNow(value); | ||
try { | ||
return dmp.parseMath(gap); | ||
} catch (final ParseException exception) { | ||
throw new SolrException(ErrorCode.BAD_REQUEST, "Unable to parse date expression " + gap); | ||
} | ||
} | ||
} |
Oops, something went wrong.