Navigation Menu

Skip to content

Commit

Permalink
select adjuster: factor must be int instead of float
Browse files Browse the repository at this point in the history
Because _score and grn_search_optarg.vector_size are int.
  • Loading branch information
kou committed Feb 24, 2014
1 parent 50c9dc0 commit d57d1a5
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
24 changes: 12 additions & 12 deletions lib/proc.c
Expand Up @@ -442,26 +442,26 @@ is_output_columns_format_v1(grn_ctx *ctx,
return GRN_TRUE;
}

static double
static int
grn_select_apply_adjuster_ensure_factor(grn_ctx *ctx, grn_obj *factor_object)
{
if (!factor_object) {
return 1.0;
} else if (factor_object->header.domain == GRN_DB_FLOAT) {
return GRN_FLOAT_VALUE(factor_object);
return 1;
} else if (factor_object->header.domain == GRN_DB_INT32) {
return GRN_INT32_VALUE(factor_object);
} else {
grn_rc rc;
grn_obj float_object;
double factor;
GRN_FLOAT_INIT(&float_object, 0);
rc = grn_obj_cast(ctx, factor_object, &float_object, GRN_FALSE);
grn_obj int32_object;
int factor;
GRN_INT32_INIT(&int32_object, 0);
rc = grn_obj_cast(ctx, factor_object, &int32_object, GRN_FALSE);
if (rc == GRN_SUCCESS) {
factor = GRN_FLOAT_VALUE(&float_object);
factor = GRN_INT32_VALUE(&int32_object);
} else {
/* TODO: Log or return error? */
factor = 1.0;
factor = 1;
}
GRN_OBJ_FIN(ctx, &float_object);
GRN_OBJ_FIN(ctx, &int32_object);
return factor;
}
}
Expand Down Expand Up @@ -532,7 +532,7 @@ grn_select_apply_adjuster_adjust(grn_ctx *ctx, grn_obj *table, grn_obj *res,
{
grn_obj *index;
unsigned int n_indexes;
double factor_value;
int factor_value;

n_indexes = grn_column_index(ctx, column, GRN_OP_MATCH, &index, 1, NULL);
if (n_indexes == 0) {
Expand Down
8 changes: 4 additions & 4 deletions test/command/suite/select/adjuster/multiple.expected
Expand Up @@ -29,7 +29,7 @@ load --table Memos
}
]
[[0,0.0,0.0],3]
select Memos --filter true --adjuster 'tags @ "groonga" * 2.5 + tags @ "mroonga" * 0.5 + tags @ "ruby" * 1.5' --output_columns _key,_score
select Memos --filter true --adjuster 'tags @ "groonga" * 4 + tags @ "mroonga" * 3 + tags @ "ruby" * 2' --output_columns _key,_score
[
[
0,
Expand All @@ -53,15 +53,15 @@ select Memos --filter true --adjuster 'tags @ "groonga" * 2.5 + tags @ "mroo
],
[
"Groonga is fast",
251
401
],
[
"Mroonga is also fast",
76
341
],
[
"Ruby is an object oriented script language",
151
201
]
]
]
Expand Down
2 changes: 1 addition & 1 deletion test/command/suite/select/adjuster/multiple.test
Expand Up @@ -30,5 +30,5 @@ load --table Memos

select Memos \
--filter true \
--adjuster 'tags @ "groonga" * 2.5 + tags @ "mroonga" * 0.5 + tags @ "ruby" * 1.5' \
--adjuster 'tags @ "groonga" * 4 + tags @ "mroonga" * 3 + tags @ "ruby" * 2' \
--output_columns _key,_score
2 changes: 1 addition & 1 deletion test/command/suite/select/adjuster/not_all_match.expected
Expand Up @@ -32,7 +32,7 @@ load --table Memos
}
]
[[0,0.0,0.0],4]
select Memos --filter '_id != 1' --adjuster 'tags @ "groonga" * 1.0' --output_columns _key,_score
select Memos --filter '_id != 1' --adjuster 'tags @ "groonga" * 1' --output_columns _key,_score
[
[
0,
Expand Down
2 changes: 1 addition & 1 deletion test/command/suite/select/adjuster/not_all_match.test
Expand Up @@ -33,5 +33,5 @@ load --table Memos

select Memos \
--filter '_id != 1' \
--adjuster 'tags @ "groonga" * 1.0' \
--adjuster 'tags @ "groonga" * 1' \
--output_columns _key,_score
6 changes: 3 additions & 3 deletions test/command/suite/select/adjuster/one.expected
Expand Up @@ -29,7 +29,7 @@ load --table Memos
}
]
[[0,0.0,0.0],3]
select Memos --filter true --adjuster 'tags @ "groonga" * 2.5' --output_columns _key,_score
select Memos --filter true --adjuster 'tags @ "groonga" * 2' --output_columns _key,_score
[
[
0,
Expand All @@ -53,11 +53,11 @@ select Memos --filter true --adjuster 'tags @ "groonga" * 2.5' --output_co
],
[
"Groonga is fast",
251
201
],
[
"Mroonga is also fast",
26
21
],
[
"Ruby is an object oriented script language",
Expand Down
2 changes: 1 addition & 1 deletion test/command/suite/select/adjuster/one.test
Expand Up @@ -30,5 +30,5 @@ load --table Memos

select Memos \
--filter true \
--adjuster 'tags @ "groonga" * 2.5' \
--adjuster 'tags @ "groonga" * 2' \
--output_columns _key,_score

0 comments on commit d57d1a5

Please sign in to comment.