Example #1
0
Datum
to_tsquery(PG_FUNCTION_ARGS)
{
	text	   *in = PG_GETARG_TEXT_P(1);
	char	   *str;
	QUERYTYPE  *query;
	ITEM	   *res;
	int4		len;

	SET_FUNCOID();

	str = text2char(in);
	PG_FREE_IF_COPY(in, 1);

	query = queryin(str, pushval_morph, PG_GETARG_INT32(0));
	res = clean_fakeval_v2(GETQUERY(query), &len);
	if (!res)
	{
		query->len = HDRSIZEQT;
		query->size = 0;
		PG_RETURN_POINTER(query);
	}
	memcpy((void *) GETQUERY(query), (void *) res, len * sizeof(ITEM));
	pfree(res);
	PG_RETURN_POINTER(query);
}
Example #2
0
Datum
lexize(PG_FUNCTION_ARGS)
{
	text	   *in = PG_GETARG_TEXT_P(1);
	DictInfo   *dict;
	TSLexeme   *res,
			   *ptr;
	Datum	   *da;
	ArrayType  *a;

	SET_FUNCOID();
	dict = finddict(PG_GETARG_OID(0));

	ptr = res = (TSLexeme *) DatumGetPointer(
										  FunctionCall3(&(dict->lexize_info),
										   PointerGetDatum(dict->dictionary),
												PointerGetDatum(VARDATA(in)),
										Int32GetDatum(VARSIZE(in) - VARHDRSZ)
														)
		);
	PG_FREE_IF_COPY(in, 1);
	if (!res)
	{
		if (PG_NARGS() > 2)
			PG_RETURN_POINTER(NULL);
		else
			PG_RETURN_NULL();
	}

	while (ptr->lexeme)
		ptr++;
	da = (Datum *) palloc(sizeof(Datum) * (ptr - res + 1));
	ptr = res;
	while (ptr->lexeme)
	{
		da[ptr - res] = PointerGetDatum(char2text(ptr->lexeme));
		ptr++;
	}

	a = construct_array(
						da,
						ptr - res,
						TEXTOID,
						-1,
						false,
						'i'
		);

	ptr = res;
	while (ptr->lexeme)
	{
		pfree(DatumGetPointer(da[ptr - res]));
		pfree(ptr->lexeme);
		ptr++;
	}
	pfree(res);
	pfree(da);

	PG_RETURN_POINTER(a);
}
Example #3
0
Datum
reset_tsearch(PG_FUNCTION_ARGS)
{
    SET_FUNCOID();
    ts_error(NOTICE, "TSearch cache cleaned");
    PG_RETURN_VOID();
}
Example #4
0
Datum
exectsq(PG_FUNCTION_ARGS)
{
	tsvector   *val = (tsvector *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0)));
	QUERYTYPE  *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
	CHKVAL		chkval;
	bool		result;

	SET_FUNCOID();
	if (!val->size || !query->size)
	{
		PG_FREE_IF_COPY(val, 0);
		PG_FREE_IF_COPY(query, 1);
		PG_RETURN_BOOL(false);
	}

	chkval.arrb = ARRPTR(val);
	chkval.arre = chkval.arrb + val->size;
	chkval.values = STRPTR(val);
	chkval.operand = GETOPERAND(query);
	result = TS_execute(
						GETQUERY(query),
						&chkval,
						true,
						checkcondition_str
		);

	PG_FREE_IF_COPY(val, 0);
	PG_FREE_IF_COPY(query, 1);
	PG_RETURN_BOOL(result);
}
Example #5
0
Datum
set_curdict(PG_FUNCTION_ARGS)
{
	SET_FUNCOID();
	finddict(PG_GETARG_OID(0));
	currect_dictionary_id = PG_GETARG_OID(0);
	PG_RETURN_VOID();
}
Example #6
0
Datum
to_tsquery_current(PG_FUNCTION_ARGS)
{
	SET_FUNCOID();
	PG_RETURN_DATUM(DirectFunctionCall2(to_tsquery,
										Int32GetDatum(get_currcfg()),
										PG_GETARG_DATUM(0)));
}
Example #7
0
Datum
set_curcfg(PG_FUNCTION_ARGS)
{
    SET_FUNCOID();
    findcfg(PG_GETARG_OID(0));
    current_cfg_id = PG_GETARG_OID(0);
    PG_RETURN_VOID();
}
Example #8
0
Datum
set_curprs(PG_FUNCTION_ARGS)
{
	SET_FUNCOID();
	findprs(PG_GETARG_OID(0));
	current_parser_id = PG_GETARG_OID(0);
	PG_RETURN_VOID();
}
Example #9
0
/*
 * boolean operations
 */
Datum
rexectsq(PG_FUNCTION_ARGS)
{
	SET_FUNCOID();
	return DirectFunctionCall2(
							   exectsq,
							   PG_GETARG_DATUM(1),
							   PG_GETARG_DATUM(0)
		);
}
Example #10
0
Datum
headline_current(PG_FUNCTION_ARGS)
{
	SET_FUNCOID();
	PG_RETURN_DATUM(DirectFunctionCall4(
										headline,
										ObjectIdGetDatum(get_currcfg()),
										PG_GETARG_DATUM(0),
										PG_GETARG_DATUM(1),
				(PG_NARGS() > 2) ? PG_GETARG_DATUM(2) : PointerGetDatum(NULL)
										));
}
Example #11
0
Datum
set_curprs_byname(PG_FUNCTION_ARGS)
{
	text	   *name = PG_GETARG_TEXT_P(0);

	SET_FUNCOID();
	DirectFunctionCall1(
						set_curprs,
						ObjectIdGetDatum(name2id_prs(name))
		);
	PG_FREE_IF_COPY(name, 0);
	PG_RETURN_VOID();
}
Example #12
0
Datum
to_tsquery_name(PG_FUNCTION_ARGS)
{
	text	   *name = PG_GETARG_TEXT_P(0);
	Datum		res;

	SET_FUNCOID();
	res = DirectFunctionCall2(to_tsquery,
							  Int32GetDatum(name2id_cfg(name)),
							  PG_GETARG_DATUM(1));

	PG_FREE_IF_COPY(name, 0);
	PG_RETURN_DATUM(res);
}
Example #13
0
Datum
headline_byname(PG_FUNCTION_ARGS)
{
	text	   *cfg = PG_GETARG_TEXT_P(0);

	Datum		out;

	SET_FUNCOID();
	out = DirectFunctionCall4(
							  headline,
							  ObjectIdGetDatum(name2id_cfg(cfg)),
							  PG_GETARG_DATUM(1),
							  PG_GETARG_DATUM(2),
				(PG_NARGS() > 3) ? PG_GETARG_DATUM(3) : PointerGetDatum(NULL)
		);

	PG_FREE_IF_COPY(cfg, 0);
	PG_RETURN_DATUM(out);
}
Example #14
0
Datum
token_type(PG_FUNCTION_ARGS)
{
	FuncCallContext *funcctx;
	Datum		result;

	SET_FUNCOID();
	if (SRF_IS_FIRSTCALL())
	{
		funcctx = SRF_FIRSTCALL_INIT();
		setup_firstcall(fcinfo, funcctx, PG_GETARG_OID(0));
	}

	funcctx = SRF_PERCALL_SETUP();

	if ((result = process_call(funcctx)) != (Datum) 0)
		SRF_RETURN_NEXT(funcctx, result);
	SRF_RETURN_DONE(funcctx);
}
Example #15
0
Datum
lexize_byname(PG_FUNCTION_ARGS)
{
	text	   *dictname = PG_GETARG_TEXT_P(0);
	Datum		res;

	SET_FUNCOID();

	res = DirectFunctionCall3(
							  lexize,
							  ObjectIdGetDatum(name2id_dict(dictname)),
							  PG_GETARG_DATUM(1),
							  (Datum) 0
		);
	PG_FREE_IF_COPY(dictname, 0);
	if (res)
		PG_RETURN_DATUM(res);
	else
		PG_RETURN_NULL();
}
Example #16
0
Datum
token_type_current(PG_FUNCTION_ARGS)
{
	FuncCallContext *funcctx;
	Datum		result;

	SET_FUNCOID();
	if (SRF_IS_FIRSTCALL())
	{
		funcctx = SRF_FIRSTCALL_INIT();
		if (current_parser_id == InvalidOid)
			current_parser_id = name2id_prs(char2text("default"));
		setup_firstcall(fcinfo, funcctx, current_parser_id);
	}

	funcctx = SRF_PERCALL_SETUP();

	if ((result = process_call(funcctx)) != (Datum) 0)
		SRF_RETURN_NEXT(funcctx, result);
	SRF_RETURN_DONE(funcctx);
}
Example #17
0
Datum
headline(PG_FUNCTION_ARGS)
{
	text	   *in = PG_GETARG_TEXT_P(1);
	QUERYTYPE  *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(2)));
	text	   *opt = (PG_NARGS() > 3 && PG_GETARG_POINTER(3)) ? PG_GETARG_TEXT_P(3) : NULL;
	HLPRSTEXT	prs;
	text	   *out;
	TSCfgInfo  *cfg;
	WParserInfo *prsobj;

	SET_FUNCOID();
	cfg = findcfg(PG_GETARG_OID(0));
	prsobj = findprs(cfg->prs_id);

	memset(&prs, 0, sizeof(HLPRSTEXT));
	prs.lenwords = 32;
	prs.words = (HLWORD *) palloc(sizeof(HLWORD) * prs.lenwords);
	hlparsetext(cfg, &prs, query, VARDATA(in), VARSIZE(in) - VARHDRSZ);


	FunctionCall3(
				  &(prsobj->headline_info),
				  PointerGetDatum(&prs),
				  PointerGetDatum(opt),
				  PointerGetDatum(query)
		);

	out = genhl(&prs);

	PG_FREE_IF_COPY(in, 1);
	PG_FREE_IF_COPY(query, 2);
	if (opt)
		PG_FREE_IF_COPY(opt, 3);
	pfree(prs.words);
	pfree(prs.startsel);
	pfree(prs.stopsel);

	PG_RETURN_POINTER(out);
}
Example #18
0
Datum
parse(PG_FUNCTION_ARGS)
{
	FuncCallContext *funcctx;
	Datum		result;

	SET_FUNCOID();
	if (SRF_IS_FIRSTCALL())
	{
		text	   *txt = PG_GETARG_TEXT_P(1);

		funcctx = SRF_FIRSTCALL_INIT();
		prs_setup_firstcall(fcinfo, funcctx, PG_GETARG_OID(0), txt);
		PG_FREE_IF_COPY(txt, 1);
	}

	funcctx = SRF_PERCALL_SETUP();

	if ((result = prs_process_call(funcctx)) != (Datum) 0)
		SRF_RETURN_NEXT(funcctx, result);
	SRF_RETURN_DONE(funcctx);
}
Example #19
0
Datum
token_type_byname(PG_FUNCTION_ARGS)
{
	FuncCallContext *funcctx;
	Datum		result;

	SET_FUNCOID();
	if (SRF_IS_FIRSTCALL())
	{
		text	   *name = PG_GETARG_TEXT_P(0);

		funcctx = SRF_FIRSTCALL_INIT();
		setup_firstcall(fcinfo, funcctx, name2id_prs(name));
		PG_FREE_IF_COPY(name, 0);
	}

	funcctx = SRF_PERCALL_SETUP();

	if ((result = process_call(funcctx)) != (Datum) 0)
		SRF_RETURN_NEXT(funcctx, result);
	SRF_RETURN_DONE(funcctx);
}
Example #20
0
Datum
lexize_bycurrent(PG_FUNCTION_ARGS)
{
	Datum		res;

	SET_FUNCOID();
	if (currect_dictionary_id == 0)
		ereport(ERROR,
				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
				 errmsg("no currect dictionary"),
				 errhint("Execute select set_curdict().")));

	res = DirectFunctionCall3(
							  lexize,
							  ObjectIdGetDatum(currect_dictionary_id),
							  PG_GETARG_DATUM(0),
							  (Datum) 0
		);
	if (res)
		PG_RETURN_DATUM(res);
	else
		PG_RETURN_NULL();
}
Example #21
0
Datum
parse_current(PG_FUNCTION_ARGS)
{
	FuncCallContext *funcctx;
	Datum		result;

	SET_FUNCOID();
	if (SRF_IS_FIRSTCALL())
	{
		text	   *txt = PG_GETARG_TEXT_P(0);

		funcctx = SRF_FIRSTCALL_INIT();
		if (current_parser_id == InvalidOid)
			current_parser_id = name2id_prs(char2text("default"));
		prs_setup_firstcall(fcinfo, funcctx, current_parser_id, txt);
		PG_FREE_IF_COPY(txt, 0);
	}

	funcctx = SRF_PERCALL_SETUP();

	if ((result = prs_process_call(funcctx)) != (Datum) 0)
		SRF_RETURN_NEXT(funcctx, result);
	SRF_RETURN_DONE(funcctx);
}
Example #22
0
/*
 * in without morphology
 */
Datum
tsquery_in(PG_FUNCTION_ARGS)
{
	SET_FUNCOID();
	PG_RETURN_POINTER(queryin((char *) PG_GETARG_POINTER(0), pushval_asis, 0));
}
Example #23
0
Datum
show_curcfg(PG_FUNCTION_ARGS)
{
    SET_FUNCOID();
    PG_RETURN_OID(get_currcfg());
}