Navigation Menu

Skip to content

Commit

Permalink
pat_fuzzy: fix memory leak that prefix query isn't match any tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
naoa committed Feb 11, 2018
1 parent 91d02ab commit d9823aa
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/pat.c
Expand Up @@ -1556,6 +1556,7 @@ grn_pat_fuzzy_search(grn_ctx *ctx, grn_pat *pat,
if (tid != GRN_ID_NIL) {
id = tid;
} else {
fuzzy_heap_close(ctx, heap);
return GRN_END_OF_DATA;
}
}
Expand All @@ -1564,6 +1565,7 @@ grn_pat_fuzzy_search(grn_ctx *ctx, grn_pat *pat,
}
dists = GRN_MALLOC((lx + 1) * (lx + max_distance + 1) * sizeof(uint16_t));
if (!dists) {
fuzzy_heap_close(ctx, heap);
return GRN_NO_MEMORY_AVAILABLE;
}

Expand Down
@@ -0,0 +1,53 @@
table_create Users TABLE_NO_KEY
[[0,0.0,0.0],true]
column_create Users name COLUMN_SCALAR ShortText
[[0,0.0,0.0],true]
table_create Names TABLE_PAT_KEY ShortText
[[0,0.0,0.0],true]
column_create Names user COLUMN_INDEX Users name
[[0,0.0,0.0],true]
load --table Users
[
{"name": "Tom"},
{"name": "Tomy"},
{"name": "Pom"},
{"name": "Tom"}
]
[[0,0.0,0.0],4]
select Users --filter 'fuzzy_search(name, "Tom", {"prefix_length": 1})' --output_columns 'name, _score' --match_escalation_threshold -1
[
[
0,
0.0,
0.0
],
[
[
[
3
],
[
[
"name",
"ShortText"
],
[
"_score",
"Int32"
]
],
[
"Tom",
2
],
[
"Tomy",
1
],
[
"Tom",
2
]
]
]
]
17 changes: 17 additions & 0 deletions test/command/suite/select/function/fuzzy_search/index/prefix.test
@@ -0,0 +1,17 @@
table_create Users TABLE_NO_KEY
column_create Users name COLUMN_SCALAR ShortText

table_create Names TABLE_PAT_KEY ShortText
column_create Names user COLUMN_INDEX Users name

load --table Users
[
{"name": "Tom"},
{"name": "Tomy"},
{"name": "Pom"},
{"name": "Tom"}
]

select Users --filter 'fuzzy_search(name, "Tom", {"prefix_length": 1})' \
--output_columns 'name, _score' \
--match_escalation_threshold -1
@@ -0,0 +1,18 @@
table_create Users TABLE_NO_KEY
[[0,0.0,0.0],true]
column_create Users name COLUMN_SCALAR ShortText
[[0,0.0,0.0],true]
table_create Names TABLE_PAT_KEY ShortText
[[0,0.0,0.0],true]
column_create Names user COLUMN_INDEX Users name
[[0,0.0,0.0],true]
load --table Users
[
{"name": "Tom"},
{"name": "Tomy"},
{"name": "Pom"},
{"name": "Tom"}
]
[[0,0.0,0.0],4]
select Users --filter 'fuzzy_search(name, "Atom", {"prefix_length": 1})' --output_columns 'name, _score' --match_escalation_threshold -1
[[0,0.0,0.0],[[[0],[["name","ShortText"],["_score","Int32"]]]]]
@@ -0,0 +1,17 @@
table_create Users TABLE_NO_KEY
column_create Users name COLUMN_SCALAR ShortText

table_create Names TABLE_PAT_KEY ShortText
column_create Names user COLUMN_INDEX Users name

load --table Users
[
{"name": "Tom"},
{"name": "Tomy"},
{"name": "Pom"},
{"name": "Tom"}
]

select Users --filter 'fuzzy_search(name, "Atom", {"prefix_length": 1})' \
--output_columns 'name, _score' \
--match_escalation_threshold -1

0 comments on commit d9823aa

Please sign in to comment.