コード例 #1
0
  public void fromXContent(XContentParser parser) throws IOException {
    DateMathParser dateParser =
        new DateMathParser(Joda.forPattern("dateOptionalTime"), TimeUnit.MILLISECONDS);
    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != END_OBJECT) {
      if (token == null) {
        break;
      } else if (token == FIELD_NAME) {
        currentFieldName = parser.currentName();
      } else if (token == VALUE_NULL
          || token == VALUE_STRING
          || token == VALUE_BOOLEAN
          || token == VALUE_NUMBER) {
        if (currentFieldName.equals("name")) {
          setName(parser.text());

        } else if (currentFieldName.equals("type")) {
          setType(parser.text());

        } else if (currentFieldName.equals("started")) {
          try {
            this.started = new Date(dateParser.parse(parser.text(), 0));
          } catch (Exception e) {
            // ignore
          }

        } else if (currentFieldName.equals("timestamp")) {
          try {
            setTimestamp(new Date(dateParser.parse(parser.text(), 0)));
          } catch (Exception e) {
            // ignore
          }

        } else if (currentFieldName.equals("counter")) {
          try {
            setCounter(parser.longValue());
          } catch (Exception e) {
            // ignore
          }

        } else if (currentFieldName.equals("enabled")) {
          setEnabled(parser.booleanValue());

        } else if (currentFieldName.equals("active")) {
          setActive(parser.booleanValue());
        }
      } else if (token == START_OBJECT) {
        if ("custom".equals(currentFieldName)) {
          setCustom(parser.map());
        }
      }
    }
  }
コード例 #2
0
 public long parseToMilliseconds(
     String value,
     boolean inclusive,
     @Nullable DateTimeZone zone,
     @Nullable DateMathParser forcedDateParser) {
   SearchContext sc = SearchContext.current();
   long now = sc == null ? System.currentTimeMillis() : sc.nowInMillis();
   DateMathParser dateParser = dateMathParser;
   if (forcedDateParser != null) {
     dateParser = forcedDateParser;
   }
   return dateParser.parse(value, now, inclusive, zone);
 }
コード例 #3
0
 @Override
 public Query fuzzyQuery(
     String value,
     Fuzziness fuzziness,
     int prefixLength,
     int maxExpansions,
     boolean transpositions) {
   long iValue = dateMathParser.parse(value, System.currentTimeMillis());
   long iSim;
   try {
     iSim = fuzziness.asTimeValue().millis();
   } catch (Exception e) {
     // not a time format
     iSim = fuzziness.asLong();
   }
   return NumericRangeQuery.newLongRange(
       names.indexName(), precisionStep, iValue - iSim, iValue + iSim, true, true);
 }