Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd1b5495

Browse files
author
Artur Zakirov
committed
Tests was corrected.
Fixed bugs with the functions shared_ispell_reset(), shared_ispell_dicts(), shared_ispell_stoplists().
1 parentf89418a commitd1b5495

File tree

7 files changed

+138
-21
lines changed

7 files changed

+138
-21
lines changed

‎Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ MODULE_big = shared_ispell
44
OBJS = src/shared_ispell.o
55

66
EXTENSION = shared_ispell
7-
DATA =sql/shared_ispell--1.1.0.sql
7+
DATA = shared_ispell--1.1.0.sql
88

99
REGRESS = shared_ispell
1010

11+
EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/postgresql.conf
12+
1113
ifdefUSE_PGXS
1214
PG_CONFIG = pg_config
1315
PGXS :=$(shell$(PG_CONFIG) --pgxs)
@@ -17,4 +19,7 @@ subdir = contrib/shared_ispell
1719
top_builddir = ../..
1820
include$(top_builddir)/src/Makefile.global
1921
include$(top_srcdir)/contrib/contrib-global.mk
20-
endif
22+
endif
23+
24+
installcheck:
25+
@echo"installcheck is disabled"

‎README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ the config file (or update the current values)
4040
# libraries to load
4141
shared_preload_libraries = 'shared_ispell'
4242

43+
# known GUC prefixes
44+
custom_variable_classes = 'shared_ispell'
45+
4346
# config of the shared memory
4447
shared_ispell.max_size = 32MB
4548

‎expected/shared_ispell.out

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
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+
214
-- Test ISpell dictionary with ispell affix file
315
CREATE TEXT SEARCH DICTIONARY shared_ispell (
416
Template=shared_ispell,
517
DictFile=ispell_sample,
6-
AffFile=ispell_sample
18+
AffFile=ispell_sample,
19+
Stopwords=english
720
);
821
SELECT ts_lexize('shared_ispell', 'skies');
922
ts_lexize
@@ -95,6 +108,18 @@ SELECT ts_lexize('shared_ispell', 'footballyklubber');
95108
{foot,ball,klubber}
96109
(1 row)
97110

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+
98123
-- Test ISpell dictionary with hunspell affix file
99124
CREATE TEXT SEARCH DICTIONARY shared_hunspell (
100125
Template=shared_ispell,
@@ -191,3 +216,46 @@ SELECT ts_lexize('shared_hunspell', 'footballyklubber');
191216
{foot,ball,klubber}
192217
(1 row)
193218

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
236+
(2 rows)
237+
238+
SELECT * FROM shared_ispell_stoplists();
239+
stop_name | words | bytes
240+
-----------+-------+-------
241+
english | 127 | 2112
242+
(1 row)
243+
244+
SELECT shared_ispell_reset();
245+
shared_ispell_reset
246+
---------------------
247+
248+
(1 row)
249+
250+
SELECT shared_ispell_mem_available();
251+
shared_ispell_mem_available
252+
-----------------------------
253+
1048528
254+
(1 row)
255+
256+
SELECT shared_ispell_mem_used();
257+
shared_ispell_mem_used
258+
------------------------
259+
48
260+
(1 row)
261+

‎postgresql.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
shared_preload_libraries = 'shared_ispell'
2+
shared_ispell.max_size = 1MB
File renamed without changes.

‎sql/shared_ispell.sql

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
CREATE EXTENSION shared_ispell;
22

3+
SELECT shared_ispell_mem_available();
4+
SELECT shared_ispell_mem_used();
5+
36
-- Test ISpell dictionary with ispell affix file
47
CREATETEXT SEARCH DICTIONARY shared_ispell (
58
Template=shared_ispell,
69
DictFile=ispell_sample,
7-
AffFile=ispell_sample
10+
AffFile=ispell_sample,
11+
Stopwords=english
812
);
913

1014
SELECT ts_lexize('shared_ispell','skies');
@@ -24,6 +28,9 @@ SELECT ts_lexize('shared_ispell', 'footballklubber');
2428
SELECT ts_lexize('shared_ispell','ballyklubber');
2529
SELECT ts_lexize('shared_ispell','footballyklubber');
2630

31+
SELECT shared_ispell_mem_available();
32+
SELECT shared_ispell_mem_used();
33+
2734
-- Test ISpell dictionary with hunspell affix file
2835
CREATETEXT SEARCH DICTIONARY shared_hunspell (
2936
Template=shared_ispell,
@@ -47,3 +54,14 @@ SELECT ts_lexize('shared_hunspell', 'footklubber');
4754
SELECT ts_lexize('shared_hunspell','footballklubber');
4855
SELECT ts_lexize('shared_hunspell','ballyklubber');
4956
SELECT ts_lexize('shared_hunspell','footballyklubber');
57+
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();
63+
64+
SELECT shared_ispell_reset();
65+
66+
SELECT shared_ispell_mem_available();
67+
SELECT shared_ispell_mem_used();

‎src/shared_ispell.c

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@
5757
#include"tsearch/ts_locale.h"
5858
#include"access/htup_details.h"
5959
#include"funcapi.h"
60+
#include"utils/builtins.h"
6061

6162
#include"shared_ispell.h"
6263
#include"tsearch/dicts/spell.h"
63-
#include"regex/regguts.h"
6464

6565
PG_MODULE_MAGIC;
6666

@@ -247,6 +247,28 @@ get_shared_stop_list(char *stop)
247247
returnNULL;
248248
}
249249

250+
/*
251+
* Cleares IspellDict fields which are used for store affix list.
252+
*/
253+
staticvoid
254+
clean_dict_affix(IspellDict*dict)
255+
{
256+
dict->maffixes=0;
257+
dict->naffixes=0;
258+
dict->Affix=NULL;
259+
260+
dict->Suffix=NULL;
261+
dict->Prefix=NULL;
262+
263+
dict->AffixData=NULL;
264+
dict->lenAffixData=0;
265+
dict->nAffixData=0;
266+
267+
dict->CompoundAffix=NULL;
268+
269+
dict->avail=0;
270+
}
271+
250272
/*
251273
* Initializes the dictionary for use in backends - checks whether such dictionary
252274
* and list of stopwords is already used, and if not then parses it and loads it into
@@ -278,6 +300,9 @@ init_shared_dict(DictInfo *info, char *dictFile, char *affFile, char *stopFile)
278300
/* lookup if the dictionary (words and affixes) is already loaded in the shared segment */
279301
shdict=get_shared_dict(dictFile,affFile);
280302

303+
/* clear dict affix sources */
304+
clean_dict_affix(&(info->dict));
305+
281306
/* load affix list */
282307
NIStartBuild(&(info->dict));
283308
NIImportAffixes(&(info->dict),get_tsearch_config_filename(affFile,"affix"));
@@ -397,7 +422,7 @@ PG_FUNCTION_INFO_V1(dispell_list_stoplists);
397422

398423
/*
399424
* Resets the shared dictionary memory, i.e. removes all the dictionaries. This
400-
* is the only way to remove dictionaries from the memory - either when when
425+
* is the only way to remove dictionaries from the memory - either when
401426
* a dictionary is no longer needed or needs to be reloaded (e.g. to update
402427
* list of words / affixes).
403428
*/
@@ -791,7 +816,6 @@ dispell_list_dicts(PG_FUNCTION_ARGS)
791816
{
792817
FuncCallContext*funcctx;
793818
TupleDesctupdesc;
794-
AttInMetadata*attinmeta;
795819
SharedIspellDict*dict;
796820

797821
/* init on the first call */
@@ -817,8 +841,7 @@ dispell_list_dicts(PG_FUNCTION_ARGS)
817841
* generate attribute metadata needed later to produce tuples from raw
818842
* C strings
819843
*/
820-
attinmeta=TupleDescGetAttInMetadata(tupdesc);
821-
funcctx->attinmeta=attinmeta;
844+
funcctx->attinmeta=TupleDescGetAttInMetadata(tupdesc);
822845
funcctx->tuple_desc=tupdesc;
823846

824847
/* switch back to the old context */
@@ -844,14 +867,14 @@ dispell_list_dicts(PG_FUNCTION_ARGS)
844867

845868
memset(nulls,0,sizeof(nulls));
846869

847-
dictname=(text*)palloc(strlen(dict->dictFile)+VARHDRSZ);
848-
affname=(text*)palloc(strlen(dict->affixFile)+VARHDRSZ);
870+
dictname=cstring_to_text(dict->dictFile);
871+
affname=cstring_to_text(dict->affixFile);
849872

850-
SET_VARSIZE(dictname,strlen(dict->dictFile)+VARHDRSZ);
851-
SET_VARSIZE(affname,strlen(dict->affixFile)+VARHDRSZ);
873+
//SET_VARSIZE(dictname, strlen(dict->dictFile) + VARHDRSZ);
874+
//SET_VARSIZE(affname, strlen(dict->affixFile) + VARHDRSZ);
852875

853-
strcpy(VARDATA(dictname),dict->dictFile);
854-
strcpy(VARDATA(affname),dict->affixFile);
876+
//strcpy(dictname, dict->dictFile);
877+
//strcpy(affname, dict->affixFile);
855878

856879
values[0]=PointerGetDatum(dictname);
857880
values[1]=PointerGetDatum(affname);
@@ -884,7 +907,6 @@ dispell_list_stoplists(PG_FUNCTION_ARGS)
884907
{
885908
FuncCallContext*funcctx;
886909
TupleDesctupdesc;
887-
AttInMetadata*attinmeta;
888910
SharedStopList*stoplist;
889911

890912
/* init on the first call */
@@ -910,8 +932,7 @@ dispell_list_stoplists(PG_FUNCTION_ARGS)
910932
* generate attribute metadata needed later to produce tuples from raw
911933
* C strings
912934
*/
913-
attinmeta=TupleDescGetAttInMetadata(tupdesc);
914-
funcctx->attinmeta=attinmeta;
935+
funcctx->attinmeta=TupleDescGetAttInMetadata(tupdesc);
915936
funcctx->tuple_desc=tupdesc;
916937

917938
/* switch back to the old context */
@@ -936,11 +957,11 @@ dispell_list_stoplists(PG_FUNCTION_ARGS)
936957

937958
memset(nulls,0,sizeof(nulls));
938959

939-
stopname=(text*)palloc(strlen(stoplist->stopFile)+VARHDRSZ);
960+
stopname=cstring_to_text(stoplist->stopFile);
940961

941-
SET_VARSIZE(stopname,strlen(stoplist->stopFile)+VARHDRSZ);
962+
//SET_VARSIZE(stopname, strlen(stoplist->stopFile) + VARHDRSZ);
942963

943-
strcpy(VARDATA(stopname),stoplist->stopFile);
964+
//strcpy(VARDATA(stopname), stoplist->stopFile);
944965

945966
values[0]=PointerGetDatum(stopname);
946967
values[1]=UInt32GetDatum(stoplist->stop.len);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp