Skip to content

Commit d6e29e7

Browse files
author
Artur Zakirov
committed
shared_ispell uses new version of IspellDict struct
1 parent 99f6e49 commit d6e29e7

File tree

3 files changed

+35
-85
lines changed

3 files changed

+35
-85
lines changed

expected/shared_ispell.out

+17-65
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
11
CREATE EXTENSION shared_ispell;
2-
SELECT shared_ispell_mem_available();
3-
shared_ispell_mem_available
4-
-----------------------------
5-
1048528
6-
(1 row)
7-
8-
SELECT shared_ispell_mem_used();
9-
shared_ispell_mem_used
10-
------------------------
11-
48
12-
(1 row)
13-
142
-- Test ISpell dictionary with ispell affix file
153
CREATE TEXT SEARCH DICTIONARY shared_ispell (
164
Template=shared_ispell,
@@ -60,12 +48,6 @@ SELECT ts_lexize('shared_ispell', 'rebooking');
6048
{booking,book}
6149
(1 row)
6250

63-
SELECT ts_lexize('shared_ispell', 'rebook');
64-
ts_lexize
65-
-----------
66-
67-
(1 row)
68-
6951
SELECT ts_lexize('shared_ispell', 'unbookings');
7052
ts_lexize
7153
-----------
@@ -108,18 +90,6 @@ SELECT ts_lexize('shared_ispell', 'footballyklubber');
10890
{foot,ball,klubber}
10991
(1 row)
11092

111-
SELECT shared_ispell_mem_available();
112-
shared_ispell_mem_available
113-
-----------------------------
114-
980312
115-
(1 row)
116-
117-
SELECT shared_ispell_mem_used();
118-
shared_ispell_mem_used
119-
------------------------
120-
68264
121-
(1 row)
122-
12393
-- Test ISpell dictionary with hunspell affix file
12494
CREATE TEXT SEARCH DICTIONARY shared_hunspell (
12595
Template=shared_ispell,
@@ -168,12 +138,6 @@ SELECT ts_lexize('shared_hunspell', 'rebooking');
168138
{booking,book}
169139
(1 row)
170140

171-
SELECT ts_lexize('shared_hunspell', 'rebook');
172-
ts_lexize
173-
-----------
174-
175-
(1 row)
176-
177141
SELECT ts_lexize('shared_hunspell', 'unbookings');
178142
ts_lexize
179143
-----------
@@ -216,29 +180,17 @@ SELECT ts_lexize('shared_hunspell', 'footballyklubber');
216180
{foot,ball,klubber}
217181
(1 row)
218182

219-
SELECT shared_ispell_mem_available();
220-
shared_ispell_mem_available
221-
-----------------------------
222-
914208
223-
(1 row)
224-
225-
SELECT shared_ispell_mem_used();
226-
shared_ispell_mem_used
227-
------------------------
228-
134368
229-
(1 row)
230-
231-
SELECT * FROM shared_ispell_dicts();
232-
dict_name | affix_name | words | affixes | bytes
233-
---------------+-----------------+-------+---------+-------
234-
ispell_sample | hunspell_sample | 8 | 0 | 66104
235-
ispell_sample | ispell_sample | 8 | 0 | 66104
183+
SELECT dict_name, affix_name, words, affixes FROM shared_ispell_dicts();
184+
dict_name | affix_name | words | affixes
185+
---------------+-----------------+-------+---------
186+
ispell_sample | hunspell_sample | 8 | 7
187+
ispell_sample | ispell_sample | 8 | 7
236188
(2 rows)
237189

238-
SELECT * FROM shared_ispell_stoplists();
239-
stop_name | words | bytes
240-
-----------+-------+-------
241-
english | 127 | 2112
190+
SELECT stop_name, words FROM shared_ispell_stoplists();
191+
stop_name | words
192+
-----------+-------
193+
english | 127
242194
(1 row)
243195

244196
SELECT shared_ispell_reset();
@@ -247,15 +199,15 @@ SELECT shared_ispell_reset();
247199

248200
(1 row)
249201

250-
SELECT shared_ispell_mem_available();
251-
shared_ispell_mem_available
252-
-----------------------------
253-
1048528
202+
SELECT ts_lexize('shared_ispell', 'skies');
203+
ts_lexize
204+
-----------
205+
{sky}
254206
(1 row)
255207

256-
SELECT shared_ispell_mem_used();
257-
shared_ispell_mem_used
258-
------------------------
259-
48
208+
SELECT ts_lexize('shared_hunspell', 'skies');
209+
ts_lexize
210+
-----------
211+
{sky}
260212
(1 row)
261213

sql/shared_ispell.sql

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
CREATE EXTENSION shared_ispell;
22

3-
SELECT shared_ispell_mem_available();
4-
SELECT shared_ispell_mem_used();
5-
63
-- Test ISpell dictionary with ispell affix file
74
CREATE TEXT SEARCH DICTIONARY shared_ispell (
85
Template=shared_ispell,
@@ -18,7 +15,6 @@ SELECT ts_lexize('shared_ispell', 'foot');
1815
SELECT ts_lexize('shared_ispell', 'foots');
1916
SELECT ts_lexize('shared_ispell', 'rebookings');
2017
SELECT ts_lexize('shared_ispell', 'rebooking');
21-
SELECT ts_lexize('shared_ispell', 'rebook');
2218
SELECT ts_lexize('shared_ispell', 'unbookings');
2319
SELECT ts_lexize('shared_ispell', 'unbooking');
2420
SELECT ts_lexize('shared_ispell', 'unbook');
@@ -28,9 +24,6 @@ SELECT ts_lexize('shared_ispell', 'footballklubber');
2824
SELECT ts_lexize('shared_ispell', 'ballyklubber');
2925
SELECT ts_lexize('shared_ispell', 'footballyklubber');
3026

31-
SELECT shared_ispell_mem_available();
32-
SELECT shared_ispell_mem_used();
33-
3427
-- Test ISpell dictionary with hunspell affix file
3528
CREATE TEXT SEARCH DICTIONARY shared_hunspell (
3629
Template=shared_ispell,
@@ -45,7 +38,6 @@ SELECT ts_lexize('shared_hunspell', 'foot');
4538
SELECT ts_lexize('shared_hunspell', 'foots');
4639
SELECT ts_lexize('shared_hunspell', 'rebookings');
4740
SELECT ts_lexize('shared_hunspell', 'rebooking');
48-
SELECT ts_lexize('shared_hunspell', 'rebook');
4941
SELECT ts_lexize('shared_hunspell', 'unbookings');
5042
SELECT ts_lexize('shared_hunspell', 'unbooking');
5143
SELECT ts_lexize('shared_hunspell', 'unbook');
@@ -55,13 +47,10 @@ SELECT ts_lexize('shared_hunspell', 'footballklubber');
5547
SELECT ts_lexize('shared_hunspell', 'ballyklubber');
5648
SELECT ts_lexize('shared_hunspell', 'footballyklubber');
5749

58-
SELECT shared_ispell_mem_available();
59-
SELECT shared_ispell_mem_used();
60-
61-
SELECT * FROM shared_ispell_dicts();
62-
SELECT * FROM shared_ispell_stoplists();
50+
SELECT dict_name, affix_name, words, affixes FROM shared_ispell_dicts();
51+
SELECT stop_name, words FROM shared_ispell_stoplists();
6352

6453
SELECT shared_ispell_reset();
6554

66-
SELECT shared_ispell_mem_available();
67-
SELECT shared_ispell_mem_used();
55+
SELECT ts_lexize('shared_ispell', 'skies');
56+
SELECT ts_lexize('shared_hunspell', 'skies');

src/shared_ispell.c

+14-5
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,13 @@ ispell_shmem_startup()
179179
segment = ShmemInitStruct(SEGMENT_NAME,
180180
max_ispell_mem_size(),
181181
&found);
182+
segment_info = (SegmentInfo *) segment;
182183

183184
/* Was the shared memory segment already initialized? */
184185
if (!found)
185186
{
186187
memset(segment, 0, max_ispell_mem_size());
187188

188-
segment_info = (SegmentInfo *) segment;
189-
190189
#if PG_VERSION_NUM >= 90600
191190
segment_info->lock = &(GetNamedLWLockTranche("shared_ispell"))->lock;
192191
#else
@@ -265,6 +264,9 @@ clean_dict_affix(IspellDict *dict)
265264
dict->nAffixData = 0;
266265

267266
dict->CompoundAffix = NULL;
267+
dict->CompoundAffixFlags = NULL;
268+
dict->nCompoundAffixFlag = 0;
269+
dict->mCompoundAffixFlag = 0;
268270

269271
dict->avail = 0;
270272
}
@@ -316,7 +318,13 @@ init_shared_dict(DictInfo *info, char *dictFile, char *affFile, char *stopFile)
316318
NIImportDictionary(dict, get_tsearch_config_filename(dictFile, "dict"));
317319

318320
dict->usecompound = info->dict.usecompound;
319-
memcpy(dict->flagval, &(info->dict.flagval), 65000);
321+
322+
dict->nCompoundAffixFlag = dict->mCompoundAffixFlag =
323+
info->dict.nCompoundAffixFlag;
324+
dict->CompoundAffixFlags = (CompoundAffixFlag *) palloc0(
325+
dict->nCompoundAffixFlag * sizeof(CompoundAffixFlag));
326+
memcpy(dict->CompoundAffixFlags, info->dict.CompoundAffixFlags,
327+
dict->nCompoundAffixFlag * sizeof(CompoundAffixFlag));
320328

321329
/*
322330
* If affix->useFlagAliases == true then AffixData is generated
@@ -342,11 +350,12 @@ init_shared_dict(DictInfo *info, char *dictFile, char *affFile, char *stopFile)
342350
/* check available space in shared segment */
343351
size = sizeIspellDict(dict, dictFile, affFile);
344352
if (size > segment_info->available)
345-
elog(ERROR, "shared dictionary %s.dict / %s.affix needs %d B, only %ld B available",
353+
elog(ERROR, "shared dictionary %s.dict / %s.affix needs %d B, only %zd B available",
346354
dictFile, affFile, size, segment_info->available);
347355

348356
/* fine, there's enough space - copy the dictionary */
349357
shdict = copyIspellDict(dict, dictFile, affFile, size, dict->nspell);
358+
shdict->dict.naffixes = info->dict.naffixes;
350359

351360
/* add the new dictionary to the linked list (of SharedIspellDict structures) */
352361
shdict->next = segment_info->shdict;
@@ -377,7 +386,7 @@ init_shared_dict(DictInfo *info, char *dictFile, char *affFile, char *stopFile)
377386

378387
size = sizeStopList(&stoplist, stopFile);
379388
if (size > segment_info->available)
380-
elog(ERROR, "shared stoplist %s.stop needs %d B, only %ld B available",
389+
elog(ERROR, "shared stoplist %s.stop needs %d B, only %zd B available",
381390
stopFile, size, segment_info->available);
382391

383392
/* fine, there's enough space - copy the stoplist */

0 commit comments

Comments
 (0)