2001-10-13 07:19:09 +08:00
|
|
|
BEGIN TRANSACTION;
|
|
|
|
|
2002-07-31 01:34:37 +08:00
|
|
|
-- Adjust this setting to control where the objects get created.
|
|
|
|
SET search_path = public;
|
|
|
|
|
2001-10-13 07:19:09 +08:00
|
|
|
-- TXTIDX type
|
|
|
|
|
2002-08-22 08:01:51 +08:00
|
|
|
CREATE FUNCTION txtidx_in(cstring)
|
|
|
|
RETURNS txtidx
|
2001-10-13 07:19:09 +08:00
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE 'c' with (isstrict);
|
|
|
|
|
2002-08-22 08:01:51 +08:00
|
|
|
CREATE FUNCTION txtidx_out(txtidx)
|
|
|
|
RETURNS cstring
|
2001-10-13 07:19:09 +08:00
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE 'c' with (isstrict);
|
|
|
|
|
|
|
|
CREATE TYPE txtidx (
|
|
|
|
internallength = -1,
|
|
|
|
input = txtidx_in,
|
2001-11-27 01:45:41 +08:00
|
|
|
output = txtidx_out,
|
|
|
|
storage = extended
|
2001-10-13 07:19:09 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION txt2txtidx(text)
|
|
|
|
RETURNS txtidx
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE 'c' with (isstrict);
|
|
|
|
|
|
|
|
CREATE FUNCTION txtidxsize(txtidx)
|
|
|
|
RETURNS int4
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE 'c' with (isstrict);
|
|
|
|
|
|
|
|
--QUERYTYPES
|
|
|
|
--without morphology
|
2002-08-22 08:01:51 +08:00
|
|
|
CREATE FUNCTION qtxt_in(cstring)
|
|
|
|
RETURNS query_txt
|
2001-10-13 07:19:09 +08:00
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE 'c' with (isstrict);
|
|
|
|
|
2002-08-22 08:01:51 +08:00
|
|
|
CREATE FUNCTION qtxt_out(query_txt)
|
|
|
|
RETURNS cstring
|
2001-10-13 07:19:09 +08:00
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE 'c' with (isstrict);
|
|
|
|
|
|
|
|
CREATE TYPE query_txt (
|
|
|
|
internallength = -1,
|
|
|
|
input = qtxt_in,
|
|
|
|
output = qtxt_out
|
|
|
|
);
|
|
|
|
|
|
|
|
--with morphology
|
2002-08-22 08:01:51 +08:00
|
|
|
CREATE FUNCTION mqtxt_in(cstring)
|
|
|
|
RETURNS mquery_txt
|
2001-10-13 07:19:09 +08:00
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE 'c' with (isstrict);
|
|
|
|
|
2002-08-22 08:01:51 +08:00
|
|
|
--same C output function as for query_txt
|
|
|
|
CREATE FUNCTION mqtxt_out(mquery_txt)
|
|
|
|
RETURNS cstring
|
|
|
|
AS 'MODULE_PATHNAME', 'qtxt_out'
|
|
|
|
LANGUAGE 'c' with (isstrict);
|
|
|
|
|
2001-10-13 07:19:09 +08:00
|
|
|
CREATE TYPE mquery_txt (
|
|
|
|
internallength = -1,
|
|
|
|
input = mqtxt_in,
|
2002-08-22 08:01:51 +08:00
|
|
|
output = mqtxt_out
|
2001-10-13 07:19:09 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
--only for debug
|
|
|
|
CREATE FUNCTION querytree(query_txt)
|
|
|
|
RETURNS text
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE 'c' with (isstrict);
|
|
|
|
|
|
|
|
CREATE FUNCTION querytree(mquery_txt)
|
|
|
|
RETURNS text
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE 'c' with (isstrict);
|
|
|
|
|
|
|
|
--operations
|
|
|
|
CREATE FUNCTION execqtxt(txtidx, query_txt) RETURNS bool
|
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' with (isstrict);
|
|
|
|
|
|
|
|
COMMENT ON FUNCTION execqtxt(txtidx, query_txt) IS 'boolean operation with text index';
|
|
|
|
|
|
|
|
CREATE FUNCTION execqtxt(txtidx, mquery_txt) RETURNS bool
|
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' with (isstrict);
|
|
|
|
|
|
|
|
COMMENT ON FUNCTION execqtxt(txtidx, mquery_txt) IS 'boolean operation with text index';
|
|
|
|
|
|
|
|
CREATE FUNCTION rexecqtxt(query_txt, txtidx) RETURNS bool
|
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' with (isstrict);
|
|
|
|
|
|
|
|
COMMENT ON FUNCTION rexecqtxt(query_txt, txtidx) IS 'boolean operation with text index';
|
|
|
|
|
|
|
|
CREATE FUNCTION rexecqtxt(mquery_txt, txtidx) RETURNS bool
|
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' with (isstrict);
|
|
|
|
|
|
|
|
COMMENT ON FUNCTION rexecqtxt(mquery_txt, txtidx) IS 'boolean operation with text index';
|
|
|
|
|
|
|
|
CREATE OPERATOR @@ (
|
|
|
|
LEFTARG = txtidx, RIGHTARG = query_txt, PROCEDURE = execqtxt,
|
|
|
|
COMMUTATOR = '~@', RESTRICT = contsel, JOIN = contjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE OPERATOR ~@ (
|
|
|
|
LEFTARG = query_txt, RIGHTARG = txtidx, PROCEDURE = rexecqtxt,
|
|
|
|
COMMUTATOR = '@@', RESTRICT = contsel, JOIN = contjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE OPERATOR ## (
|
|
|
|
LEFTARG = txtidx, RIGHTARG = mquery_txt, PROCEDURE = execqtxt,
|
|
|
|
COMMUTATOR = '~#', RESTRICT = contsel, JOIN = contjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE OPERATOR ~# (
|
|
|
|
LEFTARG = mquery_txt, RIGHTARG = txtidx, PROCEDURE = rexecqtxt,
|
|
|
|
COMMUTATOR = '##', RESTRICT = contsel, JOIN = contjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
--Trigger
|
2002-08-22 08:01:51 +08:00
|
|
|
create function tsearch() returns trigger as
|
2001-10-13 07:19:09 +08:00
|
|
|
'MODULE_PATHNAME'
|
|
|
|
language 'C';
|
|
|
|
|
|
|
|
--GiST
|
|
|
|
--GiST key type
|
2002-08-22 08:01:51 +08:00
|
|
|
CREATE FUNCTION gtxtidx_in(cstring)
|
|
|
|
RETURNS gtxtidx
|
2001-10-13 07:19:09 +08:00
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE 'c' with (isstrict);
|
|
|
|
|
2002-08-22 08:01:51 +08:00
|
|
|
CREATE FUNCTION gtxtidx_out(gtxtidx)
|
|
|
|
RETURNS cstring
|
2001-10-13 07:19:09 +08:00
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE 'c' with (isstrict);
|
|
|
|
|
|
|
|
CREATE TYPE gtxtidx (
|
|
|
|
internallength = -1,
|
|
|
|
input = gtxtidx_in,
|
|
|
|
output = gtxtidx_out
|
|
|
|
);
|
|
|
|
|
2002-07-31 01:34:37 +08:00
|
|
|
-- support functions
|
2002-08-22 08:01:51 +08:00
|
|
|
CREATE FUNCTION gtxtidx_consistent(gtxtidx,internal,int4) RETURNS bool
|
2001-10-13 07:19:09 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c';
|
|
|
|
|
2002-08-22 08:01:51 +08:00
|
|
|
CREATE FUNCTION gtxtidx_compress(internal) RETURNS internal
|
2001-10-13 07:19:09 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c';
|
|
|
|
|
2002-08-22 08:01:51 +08:00
|
|
|
CREATE FUNCTION gtxtidx_decompress(internal) RETURNS internal
|
2001-10-13 07:19:09 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c';
|
|
|
|
|
2002-08-22 08:01:51 +08:00
|
|
|
CREATE FUNCTION gtxtidx_penalty(internal,internal,internal) RETURNS internal
|
2001-10-13 07:19:09 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c' with (isstrict);
|
|
|
|
|
2002-08-22 08:01:51 +08:00
|
|
|
CREATE FUNCTION gtxtidx_picksplit(internal, internal) RETURNS internal
|
2001-10-13 07:19:09 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c';
|
|
|
|
|
2002-08-22 08:01:51 +08:00
|
|
|
CREATE FUNCTION gtxtidx_union(bytea, internal) RETURNS _int4
|
2001-10-13 07:19:09 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c';
|
|
|
|
|
2002-08-22 08:01:51 +08:00
|
|
|
CREATE FUNCTION gtxtidx_same(gtxtidx, gtxtidx, internal) RETURNS internal
|
2001-10-13 07:19:09 +08:00
|
|
|
AS 'MODULE_PATHNAME' LANGUAGE 'c';
|
|
|
|
|
2002-07-31 01:34:37 +08:00
|
|
|
-- create the operator class
|
|
|
|
CREATE OPERATOR CLASS gist_txtidx_ops
|
|
|
|
DEFAULT FOR TYPE txtidx USING gist AS
|
|
|
|
OPERATOR 1 @@ (txtidx, query_txt) RECHECK ,
|
|
|
|
OPERATOR 2 ## (txtidx, mquery_txt) RECHECK ,
|
2002-08-22 08:01:51 +08:00
|
|
|
FUNCTION 1 gtxtidx_consistent (gtxtidx, internal, int4),
|
|
|
|
FUNCTION 2 gtxtidx_union (bytea, internal),
|
|
|
|
FUNCTION 3 gtxtidx_compress (internal),
|
|
|
|
FUNCTION 4 gtxtidx_decompress (internal),
|
|
|
|
FUNCTION 5 gtxtidx_penalty (internal, internal, internal),
|
|
|
|
FUNCTION 6 gtxtidx_picksplit (internal, internal),
|
|
|
|
FUNCTION 7 gtxtidx_same (gtxtidx, gtxtidx, internal),
|
2002-07-31 01:34:37 +08:00
|
|
|
STORAGE gtxtidx;
|
2001-10-13 07:19:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
END TRANSACTION;
|