Datum tsq_mcontains(PG_FUNCTION_ARGS) { TSQuery query = PG_GETARG_TSQUERY(0); TSQuery ex = PG_GETARG_TSQUERY(1); TSQuerySign sq, se; int i, j; QueryItem *iq, *ie; if (query->size < ex->size) { PG_FREE_IF_COPY(query, 0); PG_FREE_IF_COPY(ex, 1); PG_RETURN_BOOL(false); } sq = makeTSQuerySign(query); se = makeTSQuerySign(ex); if ((sq & se) != se) { PG_FREE_IF_COPY(query, 0); PG_FREE_IF_COPY(ex, 1); PG_RETURN_BOOL(false); } iq = GETQUERY(query); ie = GETQUERY(ex); for (i = 0; i < ex->size; i++) { if (ie[i].type != QI_VAL) continue; for (j = 0; j < query->size; j++) { if (iq[j].type == QI_VAL && ie[i].qoperand.valcrc == iq[j].qoperand.valcrc) break; } if (j >= query->size) { PG_FREE_IF_COPY(query, 0); PG_FREE_IF_COPY(ex, 1); PG_RETURN_BOOL(false); } } PG_FREE_IF_COPY(query, 0); PG_FREE_IF_COPY(ex, 1); PG_RETURN_BOOL(true); }
Datum tsquery_rewrite(PG_FUNCTION_ARGS) { TSQuery query = PG_GETARG_TSQUERY_COPY(0); TSQuery ex = PG_GETARG_TSQUERY(1); TSQuery subst = PG_GETARG_TSQUERY(2); TSQuery rewrited = query; QTNode *tree, *qex, *subs = NULL; if (query->size == 0 || ex->size == 0) { PG_FREE_IF_COPY(ex, 1); PG_FREE_IF_COPY(subst, 2); PG_RETURN_POINTER(rewrited); } tree = QT2QTN(GETQUERY(query), GETOPERAND(query)); QTNTernary(tree); QTNSort(tree); qex = QT2QTN(GETQUERY(ex), GETOPERAND(ex)); QTNTernary(qex); QTNSort(qex); if (subst->size) subs = QT2QTN(GETQUERY(subst), GETOPERAND(subst)); tree = findsubquery(tree, qex, subs, NULL); QTNFree(qex); QTNFree(subs); if (!tree) { SET_VARSIZE(rewrited, HDRSIZETQ); rewrited->size = 0; PG_FREE_IF_COPY(ex, 1); PG_FREE_IF_COPY(subst, 2); PG_RETURN_POINTER(rewrited); } else { QTNBinary(tree); rewrited = QTN2QT(tree); QTNFree(tree); } PG_FREE_IF_COPY(query, 0); PG_FREE_IF_COPY(ex, 1); PG_FREE_IF_COPY(subst, 2); PG_RETURN_POINTER(rewrited); }
Datum gtsquery_consistent(PG_FUNCTION_ARGS) { GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); TSQuery query = PG_GETARG_TSQUERY(1); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); /* Oid subtype = PG_GETARG_OID(3); */ bool *recheck = (bool *) PG_GETARG_POINTER(4); TSQuerySign key = DatumGetTSQuerySign(entry->key); TSQuerySign sq = makeTSQuerySign(query); bool retval; /* All cases served by this function are inexact */ *recheck = true; switch (strategy) { case RTContainsStrategyNumber: if (GIST_LEAF(entry)) retval = (key & sq) == sq; else retval = (key & sq) != 0; break; case RTContainedByStrategyNumber: if (GIST_LEAF(entry)) retval = (key & sq) == key; else retval = (key & sq) != 0; break; default: retval = FALSE; } PG_RETURN_BOOL(retval); }
Datum gtsquery_consistent(PG_FUNCTION_ARGS) { GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); TSQuerySign *key = (TSQuerySign *) DatumGetPointer(entry->key); TSQuery query = PG_GETARG_TSQUERY(1); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); TSQuerySign sq = makeTSQuerySign(query); bool retval; switch (strategy) { case RTContainsStrategyNumber: if (GIST_LEAF(entry)) retval = (*key & sq) == sq; else retval = (*key & sq) != 0; break; case RTContainedByStrategyNumber: if (GIST_LEAF(entry)) retval = (*key & sq) == *key; else retval = (*key & sq) != 0; break; default: retval = FALSE; } PG_RETURN_BOOL(retval); }
Datum ts_match_vq(PG_FUNCTION_ARGS) { TSVector val = PG_GETARG_TSVECTOR(0); TSQuery query = PG_GETARG_TSQUERY(1); CHKVAL chkval; bool result; 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); }
Datum gin_extract_tsquery(PG_FUNCTION_ARGS) { TSQuery query = PG_GETARG_TSQUERY(0); int32 *nentries = (int32 *) PG_GETARG_POINTER(1); StrategyNumber strategy = PG_GETARG_UINT16(2); Datum *entries = NULL; *nentries = 0; if (query->size > 0) { int4 i, j = 0, len; QueryItem *item; item = clean_NOT(GETQUERY(query), &len); if (!item) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("query requires full scan, which is not supported by GIN indexes"))); item = GETQUERY(query); for (i = 0; i < query->size; i++) if (item[i].type == QI_VAL) (*nentries)++; entries = (Datum *) palloc(sizeof(Datum) * (*nentries)); for (i = 0; i < query->size; i++) if (item[i].type == QI_VAL) { text *txt; QueryOperand *val = &item[i].operand; txt = (text *) palloc(VARHDRSZ + val->length); SET_VARSIZE(txt, VARHDRSZ + val->length); memcpy(VARDATA(txt), GETOPERAND(query) + val->distance, val->length); entries[j++] = PointerGetDatum(txt); if (strategy != TSearchWithClassStrategyNumber && val->weight != 0) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("@@ operator does not support lexeme weight restrictions in GIN index searches"), errhint("Use the @@@ operator instead."))); } } else *nentries = -1; /* nothing can be found */ PG_FREE_IF_COPY(query, 0); PG_RETURN_POINTER(entries); }
Datum tsq_mcontains(PG_FUNCTION_ARGS) { TSQuery query = PG_GETARG_TSQUERY(0); TSQuery ex = PG_GETARG_TSQUERY(1); char **query_values; int query_nvalues; char **ex_values; int ex_nvalues; bool result = true; /* Extract the query terms into arrays */ query_values = collectTSQueryValues(query, &query_nvalues); ex_values = collectTSQueryValues(ex, &ex_nvalues); /* Sort and remove duplicates from both arrays */ qsort(query_values, query_nvalues, sizeof(char *), cmp_string); query_nvalues = remove_duplicates(query_values, query_nvalues); qsort(ex_values, ex_nvalues, sizeof(char *), cmp_string); ex_nvalues = remove_duplicates(ex_values, ex_nvalues); if (ex_nvalues > query_nvalues) result = false; else { int i; int j = 0; for (i = 0; i < ex_nvalues; i++) { for (; j < query_nvalues; j++) { if (strcmp(ex_values[i], query_values[j]) == 0) break; } if (j == query_nvalues) { result = false; break; } } } PG_RETURN_BOOL(result); }
Datum tsquery_numnode(PG_FUNCTION_ARGS) { TSQuery query = PG_GETARG_TSQUERY(0); int nnode = query->size; PG_FREE_IF_COPY(query, 0); PG_RETURN_INT32(nnode); }
Datum ts_rankcd_tt(PG_FUNCTION_ARGS) { TSVector txt = PG_GETARG_TSVECTOR(0); TSQuery query = PG_GETARG_TSQUERY(1); float res; res = calc_rank_cd(getWeights(NULL), txt, query, DEF_NORM_METHOD); PG_FREE_IF_COPY(txt, 0); PG_FREE_IF_COPY(query, 1); PG_RETURN_FLOAT4(res); }
Datum ts_headline_byid_opt(PG_FUNCTION_ARGS) { Oid tsconfig = PG_GETARG_OID(0); text *in = PG_GETARG_TEXT_PP(1); TSQuery query = PG_GETARG_TSQUERY(2); text *opt = (PG_NARGS() > 3 && PG_GETARG_POINTER(3)) ? PG_GETARG_TEXT_PP(3) : NULL; HeadlineParsedText prs; List *prsoptions; text *out; TSConfigCacheEntry *cfg; TSParserCacheEntry *prsobj; cfg = lookup_ts_config_cache(tsconfig); prsobj = lookup_ts_parser_cache(cfg->prsId); if (!OidIsValid(prsobj->headlineOid)) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("text search parser does not support headline creation"))); memset(&prs, 0, sizeof(HeadlineParsedText)); prs.lenwords = 32; prs.words = (HeadlineWordEntry *) palloc(sizeof(HeadlineWordEntry) * prs.lenwords); hlparsetext(cfg->cfgId, &prs, query, VARDATA_ANY(in), VARSIZE_ANY_EXHDR(in)); if (opt) prsoptions = deserialize_deflist(PointerGetDatum(opt)); else prsoptions = NIL; FunctionCall3(&(prsobj->prsheadline), PointerGetDatum(&prs), PointerGetDatum(prsoptions), PointerGetDatum(query)); out = generateHeadline(&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); }
Datum ts_rankcd_ttf(PG_FUNCTION_ARGS) { TSVector txt = PG_GETARG_TSVECTOR(0); TSQuery query = PG_GETARG_TSQUERY(1); int method = PG_GETARG_INT32(2); float res; res = calc_rank_cd(getWeights(NULL), txt, query, method); PG_FREE_IF_COPY(txt, 0); PG_FREE_IF_COPY(query, 1); PG_RETURN_FLOAT4(res); }
Datum ts_rankcd_wtt(PG_FUNCTION_ARGS) { ArrayType *win = (ArrayType *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); TSVector txt = PG_GETARG_TSVECTOR(1); TSQuery query = PG_GETARG_TSQUERY(2); float res; res = calc_rank_cd(getWeights(win), txt, query, DEF_NORM_METHOD); PG_FREE_IF_COPY(win, 0); PG_FREE_IF_COPY(txt, 1); PG_FREE_IF_COPY(query, 2); PG_RETURN_FLOAT4(res); }
Datum ts_rank_wttf(PG_FUNCTION_ARGS) { ArrayType *win = (ArrayType *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); TSVector txt = PG_GETARG_TSVECTOR(1); TSQuery query = PG_GETARG_TSQUERY(2); int method = PG_GETARG_INT32(3); float res; res = calc_rank(getWeights(win), txt, query, method); PG_FREE_IF_COPY(win, 0); PG_FREE_IF_COPY(txt, 1); PG_FREE_IF_COPY(query, 2); PG_RETURN_FLOAT4(res); }
Datum ts_headline_json_byid_opt(PG_FUNCTION_ARGS) { Oid tsconfig = PG_GETARG_OID(0); text *json = PG_GETARG_TEXT_P(1); TSQuery query = PG_GETARG_TSQUERY(2); text *opt = (PG_NARGS() > 3 && PG_GETARG_POINTER(3)) ? PG_GETARG_TEXT_P(3) : NULL; text *out; JsonTransformStringValuesAction action = (JsonTransformStringValuesAction) headline_json_value; HeadlineParsedText prs; HeadlineJsonState *state = palloc0(sizeof(HeadlineJsonState)); memset(&prs, 0, sizeof(HeadlineParsedText)); prs.lenwords = 32; prs.words = (HeadlineWordEntry *) palloc(sizeof(HeadlineWordEntry) * prs.lenwords); state->prs = &prs; state->cfg = lookup_ts_config_cache(tsconfig); state->prsobj = lookup_ts_parser_cache(state->cfg->prsId); state->query = query; if (opt) state->prsoptions = deserialize_deflist(PointerGetDatum(opt)); else state->prsoptions = NIL; if (!OidIsValid(state->prsobj->headlineOid)) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("text search parser does not support headline creation"))); out = transform_json_string_values(json, state, action); PG_FREE_IF_COPY(json, 1); PG_FREE_IF_COPY(query, 2); if (opt) PG_FREE_IF_COPY(opt, 3); pfree(prs.words); if (state->transformed) { pfree(prs.startsel); pfree(prs.stopsel); } PG_RETURN_TEXT_P(out); }
Datum ts_match_tq(PG_FUNCTION_ARGS) { TSVector vector; TSQuery query = PG_GETARG_TSQUERY(1); bool res; vector = DatumGetTSVector(DirectFunctionCall1(to_tsvector, PG_GETARG_DATUM(0))); res = DatumGetBool(DirectFunctionCall2(ts_match_vq, TSVectorGetDatum(vector), TSQueryGetDatum(query))); pfree(vector); PG_FREE_IF_COPY(query, 1); PG_RETURN_BOOL(res); }
Datum tsa_rewrite_finish(PG_FUNCTION_ARGS) { TSQuery acc = PG_GETARG_TSQUERY(0); TSQuery rewrited; if (acc == NULL || PG_ARGISNULL(0) || acc->size == 0) { rewrited = (TSQuery) palloc(HDRSIZETQ); SET_VARSIZE(rewrited, HDRSIZETQ); rewrited->size = 0; } else { rewrited = (TSQuery) palloc(VARSIZE(acc)); memcpy(rewrited, acc, VARSIZE(acc)); pfree(acc); } PG_RETURN_POINTER(rewrited); }
Datum gin_tsquery_consistent(PG_FUNCTION_ARGS) { bool *check = (bool *) PG_GETARG_POINTER(0); /* StrategyNumber strategy = PG_GETARG_UINT16(1); */ TSQuery query = PG_GETARG_TSQUERY(2); bool res = FALSE; if (query->size > 0) { int i, j = 0; QueryItem *item; GinChkVal gcv; /* * check-parameter array has one entry for each value (operand) in the * query. We expand that array into mapped_check, so that there's one * entry in mapped_check for every node in the query, including * operators, to allow quick lookups in checkcondition_gin. Only the * entries corresponding operands are actually used. */ gcv.frst = item = GETQUERY(query); gcv.mapped_check = (bool *) palloc(sizeof(bool) * query->size); for (i = 0; i < query->size; i++) if (item[i].type == QI_VAL) gcv.mapped_check[i] = check[j++]; res = TS_execute( GETQUERY(query), &gcv, true, checkcondition_gin ); } PG_RETURN_BOOL(res); }
Datum gin_tsquery_consistent(PG_FUNCTION_ARGS) { bool *check = (bool *) PG_GETARG_POINTER(0); /* StrategyNumber strategy = PG_GETARG_UINT16(1); */ TSQuery query = PG_GETARG_TSQUERY(2); /* int32 nkeys = PG_GETARG_INT32(3); */ Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); bool *recheck = (bool *) PG_GETARG_POINTER(5); bool res = FALSE; /* The query requires recheck only if it involves weights */ *recheck = false; if (query->size > 0) { QueryItem *item; GinChkVal gcv; /* * check-parameter array has one entry for each value (operand) in the * query. */ gcv.first_item = item = GETQUERY(query); gcv.check = check; gcv.map_item_operand = (int *) (extra_data[0]); gcv.need_recheck = recheck; res = TS_execute( GETQUERY(query), &gcv, true, checkcondition_gin ); } PG_RETURN_BOOL(res); }
Datum gin_tsquery_triconsistent(PG_FUNCTION_ARGS) { GinTernaryValue *check = (GinTernaryValue *) PG_GETARG_POINTER(0); /* StrategyNumber strategy = PG_GETARG_UINT16(1); */ TSQuery query = PG_GETARG_TSQUERY(2); /* int32 nkeys = PG_GETARG_INT32(3); */ Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); GinTernaryValue res = GIN_FALSE; bool recheck; /* The query requires recheck only if it involves weights */ recheck = false; if (query->size > 0) { QueryItem *item; GinChkVal gcv; /* * check-parameter array has one entry for each value (operand) in the * query. */ gcv.first_item = item = GETQUERY(query); gcv.check = check; gcv.map_item_operand = (int *) (extra_data[0]); gcv.need_recheck = &recheck; res = TS_execute_ternary(GETQUERY(query), &gcv, checkcondition_gin); if (res == GIN_TRUE && recheck) res = GIN_MAYBE; } PG_RETURN_GIN_TERNARY_VALUE(res); }
Datum gin_tsquery_consistent(PG_FUNCTION_ARGS) { bool *check = (bool *) PG_GETARG_POINTER(0); /* StrategyNumber strategy = PG_GETARG_UINT16(1); */ TSQuery query = PG_GETARG_TSQUERY(2); /* int32 nkeys = PG_GETARG_INT32(3); */ Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); bool *recheck = (bool *) PG_GETARG_POINTER(5); bool res = false; /* Initially assume query doesn't require recheck */ *recheck = false; if (query->size > 0) { GinChkVal gcv; /* * check-parameter array has one entry for each value (operand) in the * query. */ gcv.first_item = GETQUERY(query); gcv.check = check; gcv.map_item_operand = (int *) (extra_data[0]); gcv.need_recheck = recheck; res = TS_execute(GETQUERY(query), &gcv, TS_EXEC_CALC_NOT | TS_EXEC_PHRASE_NO_POS, checkcondition_gin); } PG_RETURN_BOOL(res); }
Datum tsa_rewrite_accum(PG_FUNCTION_ARGS) { TSQuery acc; ArrayType *qa; TSQuery q; QTNode *qex = NULL, *subs = NULL, *acctree = NULL; bool isfind = false; Datum *elemsp; int nelemsp; MemoryContext aggcontext; MemoryContext oldcontext; aggcontext = ((AggState *) fcinfo->context)->aggcontext; if (PG_ARGISNULL(0) || PG_GETARG_POINTER(0) == NULL) { acc = (TSQuery) MemoryContextAlloc(aggcontext, HDRSIZETQ); SET_VARSIZE(acc, HDRSIZETQ); acc->size = 0; } else acc = PG_GETARG_TSQUERY(0); if (PG_ARGISNULL(1) || PG_GETARG_POINTER(1) == NULL) PG_RETURN_TSQUERY(acc); else qa = PG_GETARG_ARRAYTYPE_P_COPY(1); if (ARR_NDIM(qa) != 1) elog(ERROR, "array must be one-dimensional, not %d dimensions", ARR_NDIM(qa)); if (ArrayGetNItems(ARR_NDIM(qa), ARR_DIMS(qa)) != 3) elog(ERROR, "array must have three elements"); if (ARR_ELEMTYPE(qa) != TSQUERYOID) elog(ERROR, "array must contain tsquery elements"); deconstruct_array(qa, TSQUERYOID, -1, false, 'i', &elemsp, NULL, &nelemsp); q = DatumGetTSQuery(elemsp[0]); if (q->size == 0) { pfree(elemsp); PG_RETURN_POINTER(acc); } if (!acc->size) { if (VARSIZE(acc) > HDRSIZETQ) { pfree(elemsp); PG_RETURN_POINTER(acc); } else acctree = QT2QTN(GETQUERY(q), GETOPERAND(q)); } else acctree = QT2QTN(GETQUERY(acc), GETOPERAND(acc)); QTNTernary(acctree); QTNSort(acctree); q = DatumGetTSQuery(elemsp[1]); if (q->size == 0) { pfree(elemsp); PG_RETURN_POINTER(acc); } qex = QT2QTN(GETQUERY(q), GETOPERAND(q)); QTNTernary(qex); QTNSort(qex); q = DatumGetTSQuery(elemsp[2]); if (q->size) subs = QT2QTN(GETQUERY(q), GETOPERAND(q)); acctree = findsubquery(acctree, qex, subs, &isfind); if (isfind || !acc->size) { /* pfree( acc ); do not pfree(p), because nodeAgg.c will */ if (acctree) { QTNBinary(acctree); oldcontext = MemoryContextSwitchTo(aggcontext); acc = QTN2QT(acctree); MemoryContextSwitchTo(oldcontext); } else { acc = (TSQuery) MemoryContextAlloc(aggcontext, HDRSIZETQ); SET_VARSIZE(acc, HDRSIZETQ); acc->size = 0; } } pfree(elemsp); QTNFree(qex); QTNFree(subs); QTNFree(acctree); PG_RETURN_TSQUERY(acc); }
Datum gin_extract_tsquery(PG_FUNCTION_ARGS) { TSQuery query = PG_GETARG_TSQUERY(0); int32 *nentries = (int32 *) PG_GETARG_POINTER(1); /* StrategyNumber strategy = PG_GETARG_UINT16(2); */ bool **ptr_partialmatch = (bool **) PG_GETARG_POINTER(3); Pointer **extra_data = (Pointer **) PG_GETARG_POINTER(4); Datum *entries = NULL; bool *partialmatch; *nentries = 0; if (query->size > 0) { int4 i, j = 0, len; QueryItem *item; bool use_fullscan = false; int *map_item_operand; item = clean_NOT(GETQUERY(query), &len); if (!item) { use_fullscan = true; *nentries = 1; } item = GETQUERY(query); for (i = 0; i < query->size; i++) if (item[i].type == QI_VAL) (*nentries)++; entries = (Datum *) palloc(sizeof(Datum) * (*nentries)); partialmatch = *ptr_partialmatch = (bool *) palloc(sizeof(bool) * (*nentries)); /* * Make map to convert item's number to corresponding operand's (the * same, entry's) number. Entry's number is used in check array in * consistent method. We use the same map for each entry. */ *extra_data = (Pointer *) palloc0(sizeof(Pointer) * (*nentries)); map_item_operand = palloc0(sizeof(int) * (query->size + 1)); for (i = 0; i < query->size; i++) if (item[i].type == QI_VAL) { text *txt; QueryOperand *val = &item[i].qoperand; txt = cstring_to_text_with_len(GETOPERAND(query) + val->distance, val->length); (*extra_data)[j] = (Pointer) map_item_operand; map_item_operand[i] = j; partialmatch[j] = val->prefix; entries[j++] = PointerGetDatum(txt); } if (use_fullscan) { (*extra_data)[j] = (Pointer) map_item_operand; map_item_operand[i] = j; entries[j++] = PointerGetDatum(cstring_to_text_with_len("", 0)); } } else *nentries = -1; /* nothing can be found */ PG_FREE_IF_COPY(query, 0); PG_RETURN_POINTER(entries); }
Datum gin_extract_tsquery(PG_FUNCTION_ARGS) { TSQuery query = PG_GETARG_TSQUERY(0); int32 *nentries = (int32 *) PG_GETARG_POINTER(1); /* StrategyNumber strategy = PG_GETARG_UINT16(2); */ bool **ptr_partialmatch = (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; *nentries = 0; if (query->size > 0) { QueryItem *item = GETQUERY(query); int32 i, j; bool *partialmatch; int *map_item_operand; /* * If the query doesn't have any required positive matches (for * instance, it's something like '! foo'), we have to do a full index * scan. */ if (tsquery_requires_match(item)) *searchMode = GIN_SEARCH_MODE_DEFAULT; else *searchMode = GIN_SEARCH_MODE_ALL; /* count number of VAL items */ j = 0; for (i = 0; i < query->size; i++) { if (item[i].type == QI_VAL) j++; } *nentries = j; entries = (Datum *) palloc(sizeof(Datum) * j); partialmatch = *ptr_partialmatch = (bool *) palloc(sizeof(bool) * j); /* * Make map to convert item's number to corresponding operand's (the * same, entry's) number. Entry's number is used in check array in * consistent method. We use the same map for each entry. */ *extra_data = (Pointer *) palloc(sizeof(Pointer) * j); map_item_operand = (int *) palloc0(sizeof(int) * query->size); /* Now rescan the VAL items and fill in the arrays */ j = 0; for (i = 0; i < query->size; i++) { if (item[i].type == QI_VAL) { QueryOperand *val = &item[i].qoperand; text *txt; txt = cstring_to_text_with_len(GETOPERAND(query) + val->distance, val->length); entries[j] = PointerGetDatum(txt); partialmatch[j] = val->prefix; (*extra_data)[j] = (Pointer) map_item_operand; map_item_operand[i] = j; j++; } } } PG_FREE_IF_COPY(query, 0); PG_RETURN_POINTER(entries); }