Esempio n. 1
0
Datum
dmetaphone_alt(PG_FUNCTION_ARGS)
{
	text	   *arg,
			   *result;
	int			alen,
				rsize;
	char	   *aptr,
			   *codes[2],
			   *code,
			   *rptr;

#ifdef DMETAPHONE_NOSTRICT
	if (PG_ARGISNULL(0))
		PG_RETURNNULL();
#endif
	arg = PG_GETARG_TEXT_P(0);
	alen = VARSIZE(arg) - VARHDRSZ;
	aptr = palloc(alen + 1);
	memcpy(aptr, VARDATA(arg), alen);
	aptr[alen] = 0;
	DoubleMetaphone(aptr, codes);
	code = codes[1];
	if (!code)
		code = "";
	rsize = VARHDRSZ + strlen(code);
	result = (text *) palloc(rsize);
	memset(result, 0, rsize);
	rptr = VARDATA(result);
	memcpy(rptr, code, strlen(code));
	VARATT_SIZEP(result) = rsize;
	PG_RETURN_TEXT_P(result);
}
Esempio n. 2
0
Datum
dmetaphone(PG_FUNCTION_ARGS)
{
	text	   *arg,
			   *result;
	int			alen,
				rsize;
	char	   *aptr,
			   *codes[2],
			   *code,
			   *rptr;

#ifdef DMETAPHONE_NOSTRICT
	if (PG_ARGISNULL(0))
		PG_RETURNNULL();
#endif
	arg = PG_GETARG_TEXT_P(0);
	alen = VARSIZE(arg) - VARHDRSZ;

	/*
	 * Postgres' string values might not have trailing nuls. The VARSIZE will
	 * not include the nul in any case so we copy things out and add a
	 * trailing nul. When we copy back we ignore the nul (and we don't make
	 * space for it).
	 */

	aptr = palloc(alen + 1);
	memcpy(aptr, VARDATA(arg), alen);
	aptr[alen] = 0;
	DoubleMetaphone(aptr, codes);
	code = codes[0];
	if (!code)
		code = "";
	rsize = VARHDRSZ + strlen(code);
	result = (text *) palloc(rsize);
	memset(result, 0, rsize);
	rptr = VARDATA(result);
	memcpy(rptr, code, strlen(code));
	VARATT_SIZEP(result) = rsize;
	PG_RETURN_TEXT_P(result);
}
Esempio n. 3
0
Datum
dmetaphone_alt(PG_FUNCTION_ARGS)
{
	text	   *arg;
	char	   *aptr,
			   *codes[2],
			   *code;

#ifdef DMETAPHONE_NOSTRICT
	if (PG_ARGISNULL(0))
		PG_RETURN_NULL();
#endif
	arg = PG_GETARG_TEXT_P(0);
	aptr = text_to_cstring(arg);

	DoubleMetaphone(aptr, codes);
	code = codes[1];
	if (!code)
		code = "";

	PG_RETURN_TEXT_P(cstring_to_text(code));
}
Esempio n. 4
0
datum_t
dmetaphone_alt(PG_FUNC_ARGS)
{
	text	   *arg;
	char	   *aptr,
			   *codes[2],
			   *code;

#ifdef DMETAPHONE_NOSTRICT
	if (PG_ARG_ISNULL(0))
		RET_NULL();
#endif
	arg = ARG_TEXT_P(0);
	aptr = text_to_cstring(arg);

	DoubleMetaphone(aptr, codes);
	code = codes[1];
	if (!code)
		code = "";

	RET_TEXT_P(cstring_to_text(code));
}
Esempio n. 5
0
static FUZZY_WORD *double_metaphone( FUZZY_OBJECT *fi, const char *inword)
{
    FUZZY_WORD *fw = create_fuzzy_word( inword, 2 ); /* create place to store stemmed word */
    char *codes[2];

    DoubleMetaphone( inword, codes );

    if ( !(*codes[0]) )  /* was there at least one conversion? */
    {
        efree( codes[0] );
        efree( codes[1] );
        return fw;
    }

    fw->free_strings = 1;
    fw->string_list[0] = codes[0];


    /* Is double metaphone enabled? */

    if ( FUZZY_DOUBLE_METAPHONE != fi->stemmer->fuzzy_mode )
        return fw;

    /* Is there a second metaphone that is different from the first? */

    if ( *codes[1] && strcmp(codes[0], codes[1]) )
    {
        fw->list_size++;
        fw->string_list[1] = codes[1];
    }
    else
    {
        efree( codes[1] );
    }
    return fw;
}