* Portions Copyright (c) 2013-2015, NTT DATA Corporation
*
* Changelog:
- * 2013/01/09
- * Support full text search using bigrams.
- * Author: NTT DATA Corporation
+ * 2013/01/09
+ * Support full text search using bigrams.
+ * Author: NTT DATA Corporation
*
*-------------------------------------------------------------------------
*/
#include "utils/builtins.h"
/* GUC variable */
-extern bool bigm_enable_recheck;
-extern int bigm_gin_key_limit;
-extern double bigm_similarity_limit;
+extern bool bigm_enable_recheck;
+extern int bigm_gin_key_limit;
+extern double bigm_similarity_limit;
/* options */
#define LPADDING 1
typedef struct
{
- bool pmatch; /* partial match is required? */
- int bytelen; /* byte length of bi-gram string */
+ bool pmatch; /* partial match is required? */
+ int bytelen; /* byte length of bi-gram string */
+
/*
- * Bi-gram string; we assume here that the maximum bytes for
- * a character are four.
+ * Bi-gram string; we assume here that the maximum bytes for a character
+ * are four.
*/
- char str[8];
-} bigm;
+ char str[8];
+} bigm;
#define BIGMSIZE sizeof(bigm)
{
int32 vl_len_; /* varlena header (do not touch directly!) */
char data[1];
-} BIGM;
+} BIGM;
#define CALCGTSIZE(len) (VARHDRSZ + len * sizeof(bigm))
#define GETARR(x) ( (bigm *)( (char*)x + VARHDRSZ ) )
#define ARRNELEM(x) ( ( VARSIZE(x) - VARHDRSZ )/sizeof(bigm) )
-extern BIGM *generate_bigm(char *str, int slen);
-extern BIGM *generate_wildcard_bigm(const char *str, int slen, bool *removeDups);
+extern BIGM *generate_bigm(char *str, int slen);
+extern BIGM *generate_wildcard_bigm(const char *str, int slen, bool *removeDups);
#endif /* __BIGM_H__ */
* Portions Copyright (c) 2013-2015, NTT DATA Corporation
*
* Changelog:
- * 2013/01/09
- * Support full text search using bigrams.
- * Author: NTT DATA Corporation
+ * 2013/01/09
+ * Support full text search using bigrams.
+ * Author: NTT DATA Corporation
*
*-------------------------------------------------------------------------
*/
ptr = GETARR(bgm);
for (i = 0; i < bgmlen; i++)
{
- text *item = cstring_to_text_with_len(ptr->str, ptr->bytelen);
+ text *item = cstring_to_text_with_len(ptr->str, ptr->bytelen);
+
entries[i] = PointerGetDatum(item);
ptr++;
}
int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
StrategyNumber strategy = PG_GETARG_UINT16(2);
- bool **pmatch = (bool **) PG_GETARG_POINTER(3);
- Pointer **extra_data = (Pointer **) PG_GETARG_POINTER(4);
+ bool **pmatch = (bool **) PG_GETARG_POINTER(3);
+ Pointer **extra_data = (Pointer **) PG_GETARG_POINTER(4);
+
/* bool **nullFlags = (bool **) PG_GETARG_POINTER(5); */
int32 *searchMode = (int32 *) PG_GETARG_POINTER(6);
Datum *entries = NULL;
{
case LikeStrategyNumber:
{
- char *str = VARDATA(val);
- int slen = VARSIZE(val) - VARHDRSZ;
- bool *recheck;
+ char *str = VARDATA(val);
+ int slen = VARSIZE(val) - VARHDRSZ;
+ bool *recheck;
/*
* For wildcard search we extract all the bigrams that every
bgmlen = ARRNELEM(bgm);
/*
- * Check whether the heap tuple fetched by index search needs to be
- * rechecked against the query. If the search word consists of one
- * or two characters and doesn't contain any space character, we can
- * guarantee that the index test would be exact. That is, the heap
- * tuple does match the query, so it doesn't need to be rechecked.
+ * Check whether the heap tuple fetched by index search needs to
+ * be rechecked against the query. If the search word consists of
+ * one or two characters and doesn't contain any space character,
+ * we can guarantee that the index test would be exact. That is,
+ * the heap tuple does match the query, so it doesn't need to be
+ * rechecked.
*/
*extra_data = (Pointer *) palloc(sizeof(bool));
recheck = (bool *) *extra_data;
if (bgmlen == 1 && !removeDups)
{
- const char *sp;
+ const char *sp;
*recheck = false;
for (sp = str; (sp - str) < slen;)
ptr = GETARR(bgm);
for (i = 0; i < *nentries; i++)
{
- text *item;
+ text *item;
if (ptr->pmatch)
{
/* text *query = PG_GETARG_TEXT_P(2); */
int32 nkeys = PG_GETARG_INT32(3);
- Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4);
+ Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4);
bool *recheck = (bool *) PG_GETARG_POINTER(5);
bool res;
int32 i;
switch (strategy)
{
case LikeStrategyNumber:
+
/*
* Don't recheck the heap tuple against the query if either
- * pg_bigm.enable_recheck is disabled or the search word is
- * the special one so that the index can return the exact
- * result.
+ * pg_bigm.enable_recheck is disabled or the search word is the
+ * special one so that the index can return the exact result.
*/
Assert(extra_data != NULL);
*recheck = bigm_enable_recheck &&
Datum
gin_bigm_compare_partial(PG_FUNCTION_ARGS)
{
- text *arg1 = PG_GETARG_TEXT_PP(0);
- text *arg2 = PG_GETARG_TEXT_PP(1);
- char *a1p;
- char *a2p;
- int mblen1;
- int mblen2;
- int res;
+ text *arg1 = PG_GETARG_TEXT_PP(0);
+ text *arg2 = PG_GETARG_TEXT_PP(1);
+ char *a1p;
+ char *a2p;
+ int mblen1;
+ int mblen2;
+ int res;
a1p = VARDATA_ANY(arg1);
a2p = VARDATA_ANY(arg2);
index_close(indexRel, AccessShareLock);
/*
- * Construct a tuple descriptor for the result row. This must
- * match this function's pg_bigm--x.x.sql entry.
+ * Construct a tuple descriptor for the result row. This must match this
+ * function's pg_bigm--x.x.sql entry.
*/
tupdesc = CreateTemplateTupleDesc(2, false);
TupleDescInitEntry(tupdesc, (AttrNumber) 1,
* Portions Copyright (c) 2013-2015, NTT DATA Corporation
*
* Changelog:
- * 2013/01/09
- * Support full text search using bigrams.
- * Author: NTT DATA Corporation
+ * 2013/01/09
+ * Support full text search using bigrams.
+ * Author: NTT DATA Corporation
*
*-------------------------------------------------------------------------
*/
PG_MODULE_MAGIC;
/* Last update date of pg_bigm */
-#define BIGM_LAST_UPDATE "2013.11.22"
+#define BIGM_LAST_UPDATE "2013.11.22"
/* GUC variable */
-bool bigm_enable_recheck = false;
-int bigm_gin_key_limit = 0;
-double bigm_similarity_limit = 0.3;
-char *bigm_last_update = NULL;
+bool bigm_enable_recheck = false;
+int bigm_gin_key_limit = 0;
+double bigm_similarity_limit = 0.3;
+char *bigm_last_update = NULL;
PG_FUNCTION_INFO_V1(show_bigm);
PG_FUNCTION_INFO_V1(bigmtextcmp);
static int
comp_bigm(const void *a, const void *b, void *arg)
{
- int res;
- bool *haveDups = (bool *) arg;
+ int res;
+ bool *haveDups = (bool *) arg;
res = CMPBIGM(a, b);
return beginword;
}
-/*
+/*
* The function is named compact_bigram to maintain consistency with pg_trgm,
* though it does not reduce multibyte characters to hash values like in
* compact_trigram.
* count bigrams
*/
bptr = make_bigrams(bptr, buf, bytelen + LPADDING + RPADDING,
- charlen + LPADDING + RPADDING);
+ charlen + LPADDING + RPADDING);
}
pfree(buf);
*/
if (len > 1)
{
- bool haveDups = false;
+ bool haveDups = false;
qsort_arg((void *) GETARR(bgm), len, sizeof(bigm), comp_bigm, (void *) &haveDups);
if (haveDups)
const char *beginword = str;
const char *endword;
char *s = buf;
- bool in_leading_wildcard_meta = false;
- bool in_trailing_wildcard_meta = false;
+ bool in_leading_wildcard_meta = false;
+ bool in_trailing_wildcard_meta = false;
bool in_escape = false;
int clen;
else
{
/*
- * Back up endword to the escape character when stopping at
- * an escaped char, so that subsequent get_wildcard_part will
+ * Back up endword to the escape character when stopping at an
+ * escaped char, so that subsequent get_wildcard_part will
* restart from the escape character. We assume here that
* escape chars are single-byte.
*/
*/
if (len > 1)
{
- bool haveDups = false;
+ bool haveDups = false;
qsort_arg((void *) GETARR(bgm), len, sizeof(bigm), comp_bigm, (void *) &haveDups);
if (haveDups)
for (i = 0, ptr = GETARR(bgm); i < ARRNELEM(bgm); i++, ptr++)
{
text *item = cstring_to_text_with_len(ptr->str, ptr->bytelen);
+
d[i] = PointerGetDatum(item);
}
while (ptr1 - GETARR(bgm1) < len1 && ptr2 - GETARR(bgm2) < len2)
{
- int res = CMPBIGM(ptr1, ptr2);
+ int res = CMPBIGM(ptr1, ptr2);
if (res < 0)
ptr1++;
Datum
bigmtextcmp(PG_FUNCTION_ARGS)
{
- text *arg1 = PG_GETARG_TEXT_PP(0);
- text *arg2 = PG_GETARG_TEXT_PP(1);
- char *a1p = VARDATA_ANY(arg1);
- char *a2p = VARDATA_ANY(arg2);
- int len1 = VARSIZE_ANY_EXHDR(arg1);
- int len2 = VARSIZE_ANY_EXHDR(arg2);
+ text *arg1 = PG_GETARG_TEXT_PP(0);
+ text *arg2 = PG_GETARG_TEXT_PP(1);
+ char *a1p = VARDATA_ANY(arg1);
+ char *a2p = VARDATA_ANY(arg2);
+ int len1 = VARSIZE_ANY_EXHDR(arg1);
+ int len2 = VARSIZE_ANY_EXHDR(arg2);
PG_RETURN_INT32(bigmstrcmp(a1p, len1, a2p, len2));
}