Exemplo n.º 1
0
grn_rc
grn_query_search(grn_ctx *ctx, grn_ii *i, grn_query *q, grn_hash *r, grn_operator op)
{
  int p = q->escalation_threshold;
  // dump_query(q, q->expr, 0);
  // grn_log("escalation_threshold=%d", p);
  if (p >= 0 || (-p & 1)) {
    q->default_mode = GRN_OP_EXACT;
    exec_search(ctx, i, q, q->expr, r, op);
    GRN_LOG(ctx, GRN_LOG_INFO, "hits(exact)=%d", *r->n_entries);
  }
  if ((p >= 0) ? (p >= *r->n_entries) : (-p & 2)) {
    q->weight_offset -= q->escalation_decaystep;
    q->default_mode = GRN_OP_UNSPLIT;
    exec_search(ctx, i, q, q->expr, r, op);
    GRN_LOG(ctx, GRN_LOG_INFO, "hits(unsplit)=%d", *r->n_entries);
  }
  if ((p >= 0) ? (p >= *r->n_entries) : (-p & 4)) {
    q->weight_offset -= q->escalation_decaystep;
    q->default_mode = GRN_OP_PARTIAL;
    exec_search(ctx, i, q, q->expr, r, op);
    GRN_LOG(ctx, GRN_LOG_INFO, "hits(partial)=%d", *r->n_entries);
  }
  return GRN_SUCCESS;
}
Exemplo n.º 2
0
static void exec_cmd(Pcs pcs, struct params *params)
{
	switch (params->action)
	{
	case ACTION_QUOTA:
		break;
	case ACTION_META: /*获取元数据*/
		exec_meta(pcs, params);
		break;
	case ACTION_LIST: /* 列出目录 */
		exec_list(pcs, params);
		break;
	case ACTION_RENAME: /* 重命名文件或目录 */
		exec_rename(pcs, params);
		break;
	case ACTION_MOVE: /* 移动文件或目录 */
		exec_move(pcs, params);
		break;
	case ACTION_COPY: /* 复制文件或目录 */
		exec_copy(pcs, params);
		break;
	case ACTION_MKDIR: /* 创建目录 */
		exec_mkdir(pcs, params);
		break;
	case ACTION_DELETE: /* 删除文件或目录 */
		exec_delete(pcs, params);
		break;
	case ACTION_CAT: /* 直接显示网盘中文本文件的内容 */
		exec_cat(pcs, params);
		break;
	case ACTION_ECHO: /* 直接把文本保存到网盘文件中 */
		exec_echo(pcs, params);
		break;
	case ACTION_SEARCH: /* 搜索网盘文件 */
		exec_search(pcs, params);
		break;
	case ACTION_DOWNLOAD: /* 下载网盘文件或目录 */
		exec_download(pcs, params);
		break;
	case ACTION_UPLOAD: /* 上传文件或目录到网盘中 */
		exec_upload(pcs, params);
		break;
	default:
		printf("Unknown command, use `--help` to view help.\n");
		break;
	}
}
Exemplo n.º 3
0
/* hashed command search routine
 * ----------------------------------------------------------------------- */
union command exec_hash(char *name, enum hash_id *idptr) {
  enum hash_id id;
  union command cmd;

  /* name contains slashes, its a path */
  if(name[str_chr(name, '/')]) {
    /* do not hash this... */
    id = H_PROGRAM;
    cmd.path = name;

    /* ...but validate the path */
    if(access(cmd.path, X_OK) != 0)
      cmd.path = NULL;
  }
  /* otherwise try to find hashed entry */
  else {
    struct exechash *entry;
    unsigned long hash;

    /* hash the name for possible re-use on exechash_create() */
    hash = exec_hashstr(name);
  
    /* do we have a cache hit? */
    if((entry = exec_search(name, hash))) {
      entry->hits++;
      id = entry->id;
      cmd = entry->cmd;
    }
    /* if we don't have a cache hit we're gonna search, special builtins first */
    else {
      id = H_EXEC;
      cmd.builtin = builtin_search(name, B_EXEC);

      /* then search for functions */
      if(cmd.builtin == NULL) {
        id = H_SBUILTIN;
        cmd.builtin = builtin_search(name, B_SPECIAL);
      }
      
      /* then search for functions */
      if(cmd.builtin == NULL) {
        id = H_FUNCTION;
        cmd.fn = /* FIXME */ NULL;
      }
      
      /* then search for normal builtins */
      if(cmd.fn == NULL) {
        id = H_BUILTIN;
        cmd.builtin = builtin_search(name, B_DEFAULT);
      }
      
      /* then search for external commands */
      if(cmd.builtin == NULL) {
        id = H_PROGRAM;
        cmd.path = exec_path(name);
      }
      
      /* if we found something then create a new cache entry */
      if(cmd.ptr) {
        entry = exec_create(name, hash);
        entry->hits++;
        entry->id = id;
        entry->cmd = cmd;
      }
    }
  }
  
  /* we have a command, set the id */
  if(cmd.ptr && idptr)
    *idptr = id;

  return cmd;
}
Exemplo n.º 4
0
static void
exec_search(grn_ctx *ctx, grn_ii *i, grn_query *q, grn_cell *c,
            grn_hash *r, grn_operator op)
{
  grn_hash *s;
  grn_cell *e, *ope = NIL;
  int n = *r->n_entries;
  grn_operator op0 = GRN_OP_OR, *opp = &op0, op1 = q->default_op;
  if (!n && op != GRN_OP_OR) { return; }
  if (n) {
    s = grn_hash_create(ctx, NULL, r->key_size, r->value_size, r->obj.header.flags);
    s->obj.header.impl_flags = 0;
    s->obj.header.domain = r->obj.header.domain;
    s->obj.range = r->obj.range;
    s->obj.max_n_subrecs = r->obj.max_n_subrecs;
    s->obj.subrec_size = r->obj.subrec_size;
    s->obj.subrec_offset = r->obj.subrec_offset;
    s->obj.id = r->obj.id;
    s->obj.db = r->obj.db;
    s->obj.source = r->obj.source;
    s->obj.source_size = r->obj.source_size;
    /*
    grn_hook_entry entry;
    for (entry = 0; entry < N_HOOK_ENTRIES; entry++) {
      s->obj.hooks[entry] = NULL;
    }
    */
  } else {
    s = r;
  }
  while (c != NIL) {
    POP(e, c);
    switch (e->header.type) {
    case GRN_CELL_OP :
      if (opp == &op0 && e->u.op.op == GRN_OP_BUT) {
        POP(e, c);
      } else {
        ope = e;
        op1 = ope->u.op.op;
      }
      continue;
    case GRN_CELL_STR :
      if (ope != NIL) {
        q->opt.mode = ope->u.op.mode == -1 ? q->default_mode : ope->u.op.mode;
        q->opt.max_interval = q->opt.similarity_threshold = ope->u.op.option;
        if (!q->opt.weight_vector) {
          q->opt.vector_size = ope->u.op.weight + q->weight_offset;
        }
        if (ope->u.op.mode == GRN_OP_SIMILAR) {
          q->opt.max_interval = q->default_mode;
        }
      } else {
        q->opt.mode = q->default_mode;
        q->opt.max_interval = DEFAULT_MAX_INTERVAL;
        q->opt.similarity_threshold = DEFAULT_SIMILARITY_THRESHOLD;
        if (!q->opt.weight_vector) {
          q->opt.vector_size = DEFAULT_WEIGHT + q->weight_offset;
        }
      }
      if (grn_ii_select(ctx, i, e->u.b.value, e->u.b.size, s, *opp, &q->opt)) {
        GRN_LOG(ctx, GRN_LOG_ERROR, "grn_inv_select on exec_search failed !");
        return;
      }
      break;
    case GRN_CELL_LIST :
      exec_search(ctx, i, q, e, s, *opp);
      break;
    default :
      GRN_LOG(ctx, GRN_LOG_NOTICE, "invalid object assigned in query (%d)", e->header.type);
      break;
    }
    opp = &op1;
    ope = NIL;
    op1 = q->default_op;
  }
  if (n) {
    grn_table_setoperation(ctx, (grn_obj *)r, (grn_obj *)s, (grn_obj *)r, op);
    grn_hash_close(ctx, s);
  }
}