/**
   * Returns the item with weight calculation.
   *
   * @param item input item
   * @param ctx query context
   * @return item
   * @throws QueryException query exception
   */
  FTNode weight(final FTNode item, final QueryContext ctx) throws QueryException {

    // evaluate weight
    if (item == null) return null;
    final double d = checkDbl(weight, ctx);
    if (Math.abs(d) > 1000) FTWEIGHT.thrw(input, d);
    if (d == 0) item.all.size = 0;
    item.score(item.score() * d);
    return item;
  }
Beispiel #2
0
    @Override
    public Item ev(final InputInfo ii, final Item a, final Item b) throws QueryException {

      final Type ta = a.type, tb = b.type;
      if (ta == tb) {
        if (ta == YMD) {
          final BigDecimal bd = BigDecimal.valueOf(((YMd) b).ymd());
          if (bd.equals(BigDecimal.ZERO)) DATEZERO.thrw(ii, info());
          return Dec.get(
              BigDecimal.valueOf(((YMd) a).ymd()).divide(bd, 20, BigDecimal.ROUND_HALF_EVEN));
        }
        if (ta == DTD) {
          final BigDecimal bd = ((DTd) b).dtd();
          if (bd.equals(BigDecimal.ZERO)) DATEZERO.thrw(ii, info());
          return Dec.get(((DTd) a).dtd().divide(bd, 20, BigDecimal.ROUND_HALF_EVEN));
        }
      }
      if (ta == YMD) {
        if (!tb.isNumber()) errNum(ii, b);
        return new YMd((Dur) a, b.dbl(ii), false, ii);
      }
      if (ta == DTD) {
        if (!tb.isNumber()) errNum(ii, b);
        return new DTd((Dur) a, b.dbl(ii), false, ii);
      }

      checkNum(ii, a, b);
      final Type t = type(ta, tb);
      if (t == DBL) return Dbl.get(a.dbl(ii) / b.dbl(ii));
      if (t == FLT) return Flt.get(a.flt(ii) / b.flt(ii));

      final BigDecimal b1 = a.dec(ii);
      final BigDecimal b2 = b.dec(ii);
      if (b2.signum() == 0) DIVZERO.thrw(ii, a);
      final int s = Math.max(18, Math.max(b1.scale(), b2.scale()));
      return Dec.get(b1.divide(b2, s, BigDecimal.ROUND_HALF_EVEN));
    }