Esempio n. 1
0
 @Override
 public Value value(final QueryContext qc) throws QueryException {
   final ArrayList<User> users = qc.context.users.users(null, qc.context);
   final TokenList tl = new TokenList(users.size());
   for (final User user : users) tl.add(user.name());
   return StrSeq.get(tl);
 }
Esempio n. 2
0
 /**
  * Returns all tokens of the query.
  *
  * @param qc query context
  * @return token list
  * @throws QueryException query exception
  */
 private TokenList tokens(final QueryContext qc) throws QueryException {
   final TokenList tl = new TokenList();
   final Iter ir = qc.iter(query);
   for (byte[] qu; (qu = nextToken(ir)) != null; ) {
     // skip empty tokens if not all results are needed
     if (qu.length != 0 || mode == FTMode.ALL || mode == FTMode.ALL_WORDS) tl.add(qu);
   }
   return tl;
 }
Esempio n. 3
0
  /**
   * Recursively collects relevant thesaurus terms.
   *
   * @param list result list
   * @param node input node
   * @param level current level
   */
  private void find(final TokenList list, final ThesNode node, final long level) {
    if (level > max || node == null) return;

    for (int n = 0; n < node.size; ++n) {
      if (rel.length == 0 || eq(node.rs[n], rel)) {
        final byte[] term = node.nodes[n].term;
        if (!list.contains(term)) {
          list.add(term);
          find(list, node.nodes[n], level + 1);
        }
      }
    }
  }
Esempio n. 4
0
  /**
   * Evaluates the tokenize function.
   *
   * @param ctx query context
   * @return function result
   * @throws QueryException query exception
   */
  private Value tokenize(final QueryContext ctx) throws QueryException {
    final byte[] val = checkEStr(expr[0], ctx);
    final Pattern p = pattern(expr[1], expr.length == 3 ? expr[2] : null, ctx);
    if (p.matcher("").matches()) REGROUP.thrw(info);

    final TokenList tl = new TokenList();
    final String str = string(val);
    if (!str.isEmpty()) {
      final Matcher m = p.matcher(str);
      int s = 0;
      while (m.find()) {
        tl.add(str.substring(s, m.start()));
        s = m.end();
      }
      tl.add(str.substring(s, str.length()));
    }
    return StrSeq.get(tl);
  }
Esempio n. 5
0
 /**
  * Creates a container for the specified string.
  *
  * @param strings string
  * @return iterator
  */
 protected static Value strings(final String... strings) {
   final TokenList tl = new TokenList(strings.length);
   for (final String s : strings) tl.add(s);
   return StrSeq.get(tl.finish());
 }