Skip to content

Commit 86f26fe

Browse files
committed
delete: add support for referenced weight vector
If a referenced record is deleted, values that refer the record are also removed when there are indexes for them. It worked for non-weight vector column but didn't work for weight vector column. If the feature was used for weight vector column, the value of the weight vector column will be broken. This fixes the problem.
1 parent f2db1e3 commit 86f26fe

File tree

7 files changed

+145
-5
lines changed

7 files changed

+145
-5
lines changed

lib/db.c

+13-5
Original file line numberDiff line numberDiff line change
@@ -2826,15 +2826,23 @@ delete_reference_records_in_index(grn_ctx *ctx,
28262826
GRN_TEXT_INIT(&value, 0);
28272827
grn_obj_get_value(ctx, source, posting->rid, &value);
28282828
if (value.header.type == GRN_UVECTOR) {
2829-
int i, n_ids;
28302829
GRN_RECORD_INIT(&new_value, GRN_OBJ_VECTOR, value.header.domain);
2831-
n_ids = GRN_BULK_VSIZE(&value) / sizeof(grn_id);
2832-
for (i = 0; i < n_ids; i++) {
2833-
grn_id reference_id = GRN_RECORD_VALUE_AT(&value, i);
2830+
if (grn_obj_is_weight_uvector(ctx, &value)) {
2831+
new_value.header.flags |= GRN_OBJ_WITH_WEIGHT;
2832+
}
2833+
uint32_t n = grn_uvector_size(ctx, &value);
2834+
uint32_t i;
2835+
for (i = 0; i < n; i++) {
2836+
float weight;
2837+
grn_id reference_id =
2838+
grn_uvector_get_element_record(ctx, &value, i, &weight);
28342839
if (reference_id == data->id) {
28352840
continue;
28362841
}
2837-
GRN_RECORD_PUT(ctx, &new_value, reference_id);
2842+
grn_uvector_add_element_record(ctx,
2843+
&new_value,
2844+
reference_id,
2845+
weight);
28382846
}
28392847
} else {
28402848
unsigned int i, n_elements;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
table_create Tags TABLE_PAT_KEY ShortText
2+
[[0,0.0,0.0],true]
3+
table_create Memos TABLE_HASH_KEY ShortText
4+
[[0,0.0,0.0],true]
5+
column_create Memos tags COLUMN_VECTOR Tags
6+
[[0,0.0,0.0],true]
7+
column_create Tags memos_tags COLUMN_INDEX Memos tags
8+
[[0,0.0,0.0],true]
9+
load --table Memos
10+
[
11+
{"_key": "Groonga", "tags": ["Groonga", "Full text search"]},
12+
{"_key": "Rroonga", "tags": ["Groonga", "Ruby", "Library"]}
13+
]
14+
[[0,0.0,0.0],2]
15+
delete Tags Ruby
16+
[[0,0.0,0.0],true]
17+
dump
18+
table_create Memos TABLE_HASH_KEY ShortText
19+
20+
table_create Tags TABLE_PAT_KEY ShortText
21+
22+
column_create Memos tags COLUMN_VECTOR Tags
23+
24+
load --table Memos
25+
[
26+
["_key","tags"],
27+
["Groonga",["Groonga","Full text search"]],
28+
["Rroonga",["Groonga","Library"]]
29+
]
30+
31+
column_create Tags memos_tags COLUMN_INDEX Memos tags
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
table_create Tags TABLE_PAT_KEY ShortText
2+
table_create Memos TABLE_HASH_KEY ShortText
3+
column_create Memos tags COLUMN_VECTOR Tags
4+
column_create Tags memos_tags COLUMN_INDEX Memos tags
5+
6+
load --table Memos
7+
[
8+
{"_key": "Groonga", "tags": ["Groonga", "Full text search"]},
9+
{"_key": "Rroonga", "tags": ["Groonga", "Ruby", "Library"]}
10+
]
11+
12+
delete Tags Ruby
13+
dump
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
table_create Tags TABLE_PAT_KEY ShortText
2+
[[0,0.0,0.0],true]
3+
table_create Memos TABLE_HASH_KEY ShortText
4+
[[0,0.0,0.0],true]
5+
column_create Memos tags COLUMN_VECTOR|WITH_WEIGHT Tags
6+
[[0,0.0,0.0],true]
7+
column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags
8+
[[0,0.0,0.0],true]
9+
load --table Memos
10+
[
11+
{"_key": "Groonga", "tags": {"Groonga": 100, "Full text search": 2}},
12+
{"_key": "Rroonga", "tags": {"Groonga": 5, "Ruby": 100, "Library": 50}}
13+
]
14+
[[0,0.0,0.0],2]
15+
delete Tags Ruby
16+
[[0,0.0,0.0],true]
17+
dump
18+
table_create Memos TABLE_HASH_KEY ShortText
19+
20+
table_create Tags TABLE_PAT_KEY ShortText
21+
22+
column_create Memos tags COLUMN_VECTOR|WITH_WEIGHT Tags
23+
24+
load --table Memos
25+
[
26+
["_key","tags"],
27+
["Groonga",{"Groonga":100,"Full text search":2}],
28+
["Rroonga",{"Groonga":5,"Library":50}]
29+
]
30+
31+
column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
table_create Tags TABLE_PAT_KEY ShortText
2+
table_create Memos TABLE_HASH_KEY ShortText
3+
column_create Memos tags COLUMN_VECTOR|WITH_WEIGHT Tags
4+
column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags
5+
6+
load --table Memos
7+
[
8+
{"_key": "Groonga", "tags": {"Groonga": 100, "Full text search": 2}},
9+
{"_key": "Rroonga", "tags": {"Groonga": 5, "Ruby": 100, "Library": 50}}
10+
]
11+
12+
delete Tags Ruby
13+
dump
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
table_create Tags TABLE_PAT_KEY ShortText
2+
[[0,0.0,0.0],true]
3+
table_create Memos TABLE_HASH_KEY ShortText
4+
[[0,0.0,0.0],true]
5+
column_create Memos tags COLUMN_VECTOR|WITH_WEIGHT|WEIGHT_FLOAT32 Tags
6+
[[0,0.0,0.0],true]
7+
column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags
8+
[[0,0.0,0.0],true]
9+
load --table Memos
10+
[
11+
{"_key": "Groonga", "tags": {"Groonga": 100.0, "Full text search": 2.0}},
12+
{"_key": "Rroonga", "tags": {"Groonga": 2.5, "Ruby": 100.0, "Library": 50}}
13+
]
14+
[[0,0.0,0.0],2]
15+
delete Tags Ruby
16+
[[0,0.0,0.0],true]
17+
dump
18+
table_create Memos TABLE_HASH_KEY ShortText
19+
20+
table_create Tags TABLE_PAT_KEY ShortText
21+
22+
column_create Memos tags COLUMN_VECTOR|WITH_WEIGHT|WEIGHT_FLOAT32 Tags
23+
24+
load --table Memos
25+
[
26+
["_key","tags"],
27+
["Groonga",{"Groonga":100.0,"Full text search":2.0}],
28+
["Rroonga",{"Groonga":2.5,"Library":50.0}]
29+
]
30+
31+
column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
table_create Tags TABLE_PAT_KEY ShortText
2+
table_create Memos TABLE_HASH_KEY ShortText
3+
column_create Memos tags COLUMN_VECTOR|WITH_WEIGHT|WEIGHT_FLOAT32 Tags
4+
column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags
5+
6+
load --table Memos
7+
[
8+
{"_key": "Groonga", "tags": {"Groonga": 100.0, "Full text search": 2.0}},
9+
{"_key": "Rroonga", "tags": {"Groonga": 2.5, "Ruby": 100.0, "Library": 50}}
10+
]
11+
12+
delete Tags Ruby
13+
dump

0 commit comments

Comments
 (0)