Ejemplo n.º 1
0
  @Override
  public Item item(final QueryContext qc, final InputInfo ii) throws QueryException {
    // compute scoring
    if (qc.scoring) {
      double s = 0;
      boolean f = false;
      for (final Expr expr : exprs) {
        final Item it = expr.ebv(qc, info);
        f |= it.bool(ii);
        s += it.score();
      }
      return Bln.get(f, Scoring.avg(s, exprs.length));
    }

    // standard evaluation
    for (final Expr expr : exprs) {
      if (expr.ebv(qc, info).bool(ii)) return Bln.TRUE;
    }
    return Bln.FALSE;
  }
Ejemplo n.º 2
0
 /**
  * Checks if the specified item is a boolean. Returns the boolean or throws an exception.
  *
  * @param it item be checked
  * @return boolean
  * @throws QueryException query exception
  */
 protected final boolean toBoolean(final Item it) throws QueryException {
   final Type ip = checkNoEmpty(it, AtomType.BLN).type;
   if (ip == AtomType.BLN) return it.bool(info);
   if (ip.isUntyped()) return Bln.parse(it.string(info), info);
   throw castError(it, AtomType.BLN, info);
 }
Ejemplo n.º 3
0
 /**
  * Evaluates the match function.
  *
  * @param val input value
  * @param ctx query context
  * @return function result
  * @throws QueryException query exception
  */
 private Item matches(final byte[] val, final QueryContext ctx) throws QueryException {
   final Pattern p = pattern(expr[1], expr.length == 3 ? expr[2] : null, ctx);
   return Bln.get(p.matcher(string(val)).find());
 }