Examples of DateMathParser


Examples of org.apache.solr.util.DateMathParser

    // Test date math syntax
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    format.setTimeZone(TimeZone.getTimeZone("UTC"));

    assertU(delQ("*:*"));
    DateMathParser dmp = new DateMathParser(DateField.UTC, Locale.US);
    String largestDate = "";
    for (int i = 0; i < 10; i++) {
      // index 10 days starting with today
      String d = format.format(i == 0 ? dmp.parseMath("/DAY") : dmp.parseMath("/DAY+" + i + "DAYS"));
      assertU(adoc("id", String.valueOf(i), "tdate", d));
      if (i == 9) largestDate = d;
    }
    assertU(commit());
    assertQ("Range filter must match only 10 documents", req("q", "*:*", "fq", "tdate:[* TO *]"), "//*[@numFound='10']");
 
View Full Code Here

Examples of org.apache.solr.util.DateMathParser

    checkPrecisionSteps("tdate");

    // For tdate tests
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    DateMathParser dmp = new DateMathParser(DateField.UTC, Locale.US);

    for (int i = 0; i < 10; i++) {
      long l = Integer.MAX_VALUE + i*1L;
      // index 10 days starting with today
      String d = format.format(i == 0 ? dmp.parseMath("/DAY") : dmp.parseMath("/DAY+" + i + "DAYS"));
      assertU(adoc("id", String.valueOf(i), "tint", String.valueOf(i),
              "tlong", String.valueOf(l),
              "tfloat", String.valueOf(i * i * 31.11f),
              "tdouble", String.valueOf(i * 2.33d),
              "tdate", d));
    }
    for (int i = 0; i < 5; i++) {
      long l = Integer.MAX_VALUE + i*1L;
      String d = format.format(i == 0 ? dmp.parseMath("/DAY") : dmp.parseMath("/DAY+" + i + "DAYS"));
      assertU(adoc("id", String.valueOf((i+1)*10), "tint", String.valueOf(i),
              "tlong", String.valueOf(l),
              "tfloat", String.valueOf(i * i * 31.11f),
              "tdouble", String.valueOf(i * 2.33d),
              "tdate", d));
    }
    assertU(commit());

    SolrQueryRequest req = req("q", "*:*", "facet", "true", "rows", "15",
            "facet.field", "tint",
            "facet.field", "tlong",
            "facet.field", "tfloat",
            "facet.field", "tdouble",
            "facet.date", "tdate",
            "facet.date.start", "NOW/DAY",
            "facet.date.end", "NOW/DAY+6DAYS",
            "facet.date.gap", "+1DAY");
    testFacetField(req, "tint", "0", "2");
    testFacetField(req, "tint", "5", "1");
    testFacetField(req, "tlong", String.valueOf(Integer.MAX_VALUE), "2");
    testFacetField(req, "tlong", String.valueOf(Integer.MAX_VALUE+5L), "1");
    testFacetField(req, "tfloat", String.valueOf(31.11f), "2");
    testFacetField(req, "tfloat", String.valueOf(5*5*31.11f), "1");
    testFacetField(req, "tdouble", String.valueOf(2.33d), "2");
    testFacetField(req, "tdouble", String.valueOf(5*2.33d), "1");

    testFacetDate(req, "tdate", format.format(dmp.parseMath("/DAY")), "4");
    testFacetDate(req, "tdate", format.format(dmp.parseMath("/DAY+5DAYS")), "2");
  }
View Full Code Here

Examples of org.apache.solr.util.DateMathParser

   * @param now an optional fixed date to use as "NOW" in the DateMathParser
   * @param val the string to parse
   */
  public Date parseMath(Date now, String val) {
    String math = null;
    final DateMathParser p = new DateMathParser(MATH_TZ, MATH_LOCALE);
   
    if (null != now) p.setNow(now);
   
    if (val.startsWith(NOW)) {
      math = val.substring(NOW.length());
    } else {
      final int zz = val.indexOf(Z);
      if (0 < zz) {
        math = val.substring(zz+1);
        try {
          p.setNow(toObject(val.substring(0,zz)));
        } catch (ParseException e) {
          throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
                                   "Invalid Date in Date Math String:'"
                                   +val+'\'',e);
        }
      } else {
        throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
                                 "Invalid Date String:'" +val+'\'');
      }
    }

    if (null == math || math.equals("")) {
      return p.getNow();
    }
   
    try {
      return p.parseMath(math);
    } catch (ParseException e) {
      throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
                               "Invalid Date Math String:'" +val+'\'',e);
    }
  }
View Full Code Here

Examples of org.apache.solr.util.DateMathParser

   * @param now an optional fixed date to use as "NOW" in the DateMathParser
   * @param val the string to parse
   */
  public Date parseMath(Date now, String val) {
    String math = null;
    final DateMathParser p = new DateMathParser(MATH_TZ, MATH_LOCALE);
   
    if (null != now) p.setNow(now);
   
    if (val.startsWith(NOW)) {
      math = val.substring(NOW.length());
    } else {
      final int zz = val.indexOf(Z);
      if (0 < zz) {
        math = val.substring(zz+1);
        try {
          p.setNow(toObject(val.substring(0,zz)));
        } catch (ParseException e) {
          throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
                                   "Invalid Date in Date Math String:'"
                                   +val+'\'',e);
        }
      } else {
        throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
                                 "Invalid Date String:'" +val+'\'');
      }
    }

    if (null == math || math.equals("")) {
      return p.getNow();
    }
   
    try {
      return p.parseMath(math);
    } catch (ParseException e) {
      throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
                               "Invalid Date Math String:'" +val+'\'',e);
    }
  }
View Full Code Here

Examples of org.apache.solr.util.DateMathParser

                        "date facet 'end' comes before 'start': " + endS + " < " + startS,
                        JahiaException.PARAMETER_ERROR, JahiaException.ERROR_SEVERITY);
            }

            final String gap = required.getFieldParam(f, FacetParams.FACET_DATE_GAP);
            final DateMathParser dmp = new DateMathParser(DateField.UTC, Locale.US);
            dmp.setNow(NOW);
            try {

                Date low = start;
                while (low.before(end)) {
                    dmp.setNow(low);
                    final String lowI = JahiaQueryParser.DATE_TYPE.toInternal(low);
                    final String label = JahiaQueryParser.DATE_TYPE.indexedToReadable(lowI, true);
                    Date high = dmp.parseMath(gap);
                    if (end.before(high)) {
                        if (params.getFieldBool(f, FacetParams.FACET_DATE_HARD_END,
                                false)) {
                            high = end;
                        } else {
View Full Code Here

Examples of org.apache.solr.util.DateMathParser

   * @param now an optional fixed date to use as "NOW" in the DateMathParser
   * @param val the string to parse
   */
  public Date parseMath(Date now, String val) {
    String math = null;
    final DateMathParser p = new DateMathParser(MATH_TZ, MATH_LOCALE);
   
    if (null != now) p.setNow(now);
   
    if (val.startsWith(NOW)) {
      math = val.substring(NOW.length());
    } else {
      final int zz = val.indexOf(Z);
      if (0 < zz) {
        math = val.substring(zz+1);
        try {
          // p.setNow(toObject(val.substring(0,zz)));
          p.setNow(parseDate(val.substring(0,zz+1)));
        } catch (ParseException e) {
          throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
                                   "Invalid Date in Date Math String:'"
                                   +val+'\'',e);
        }
      } else {
        throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
                                 "Invalid Date String:'" +val+'\'');
      }
    }

    if (null == math || math.equals("")) {
      return p.getNow();
    }
   
    try {
      return p.parseMath(math);
    } catch (ParseException e) {
      throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
                               "Invalid Date Math String:'" +val+'\'',e);
    }
  }
View Full Code Here

Examples of org.apache.solr.util.DateMathParser

   * @param now an optional fixed date to use as "NOW" in the DateMathParser
   * @param val the string to parse
   */
  public Date parseMathLenient(Date now, String val, SolrQueryRequest req) {
    String math = null;
    final DateMathParser p = new DateMathParser(MATH_TZ, MATH_LOCALE);

    if (null != now) p.setNow(now);

    if (val.startsWith(NOW)) {
      math = val.substring(NOW.length());
    } else {
      final int zz = val.indexOf(Z);
      if (0 < zz) {
        math = val.substring(zz+1);
        try {
          // p.setNow(toObject(val.substring(0,zz)));
          p.setNow(parseDateLenient(val.substring(0,zz+1), req));
        } catch (ParseException e) {
          throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
                                   "Invalid Date in Date Math String:'"
                                   +val+'\'',e);
        }
      } else {
        throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
                                 "Invalid Date String:'" +val+'\'');
      }
    }

    if (null == math || math.equals("")) {
      return p.getNow();
    }

    try {
      return p.parseMath(math);
    } catch (ParseException e) {
      throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
                               "Invalid Date Math String:'" +val+'\'',e);
    }
  }
View Full Code Here

Examples of org.apache.solr.util.DateMathParser

        // delete anything too old, regardless of other policies
        try {
          if (maxCommitAge != null) {
            if (maxCommitAgeTimeStamp==-1) {
              DateMathParser dmp = new DateMathParser(DateField.UTC, Locale.US);
              maxCommitAgeTimeStamp = dmp.parseMath(maxCommitAge).getTime();
            }
            if (commit.getTimestamp() < maxCommitAgeTimeStamp) {
              commit.delete();
              continue;
            }
View Full Code Here

Examples of org.apache.solr.util.DateMathParser

          (SolrException.ErrorCode.BAD_REQUEST,
           "date facet 'end' comes before 'start': "+endS+" < "+startS);
      }

      final String gap = required.getFieldParam(f,FacetParams.FACET_DATE_GAP);
      final DateMathParser dmp = new DateMathParser(ft.UTC, Locale.US);
      dmp.setNow(NOW);
     
      try {
       
        Date low = start;
        while (low.before(end)) {
          dmp.setNow(low);
          String label = ft.toExternal(low);
         
          Date high = dmp.parseMath(gap);
          if (end.before(high)) {
            if (params.getFieldBool(f,FacetParams.FACET_DATE_HARD_END,false)) {
              high = end;
            } else {
              end = high;
View Full Code Here

Examples of org.apache.solr.util.DateMathParser

    int len=val.length();
    if (val.charAt(len-1)=='Z') {
      return val.substring(0,len-1);
    } else if (val.startsWith("NOW")) {
      /* :TODO: let Locale/TimeZone come from init args for rounding only */
      DateMathParser p = new DateMathParser(UTC, Locale.US);
      try {
        return toInternal(p.parseMath(val.substring(3)));
      } catch (ParseException e) {
        throw new SolrException(400,"Invalid Date Math String:'" +val+'\'',e);
      }
    }
    throw new SolrException(400,"Invalid Date String:'" +val+'\'');
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.