mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Make contrib/pg_trgm also support regex searches with GiST indexes.
This wasn't addressed in the original patch, but it doesn't take very much additional code to cover the case, so let's get it done. Since pg_trgm 1.1 hasn't been released yet, I just changed the definition of what's in it, rather than inventing a 1.2.
This commit is contained in:
@ -616,6 +616,50 @@ trgm_contained_by(TRGM *trg1, TRGM *trg2)
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a palloc'd boolean array showing, for each trigram in "query",
|
||||
* whether it is present in the trigram array "key".
|
||||
* This relies on the "key" array being sorted, but "query" need not be.
|
||||
*/
|
||||
bool *
|
||||
trgm_presence_map(TRGM *query, TRGM *key)
|
||||
{
|
||||
bool *result;
|
||||
trgm *ptrq = GETARR(query),
|
||||
*ptrk = GETARR(key);
|
||||
int lenq = ARRNELEM(query),
|
||||
lenk = ARRNELEM(key),
|
||||
i;
|
||||
|
||||
result = (bool *) palloc0(lenq * sizeof(bool));
|
||||
|
||||
/* for each query trigram, do a binary search in the key array */
|
||||
for (i = 0; i < lenq; i++)
|
||||
{
|
||||
int lo = 0;
|
||||
int hi = lenk;
|
||||
|
||||
while (lo < hi)
|
||||
{
|
||||
int mid = (lo + hi) / 2;
|
||||
int res = CMPTRGM(ptrq, ptrk + mid);
|
||||
|
||||
if (res < 0)
|
||||
hi = mid;
|
||||
else if (res > 0)
|
||||
lo = mid + 1;
|
||||
else
|
||||
{
|
||||
result[i] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ptrq++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Datum
|
||||
similarity(PG_FUNCTION_ARGS)
|
||||
{
|
||||
|
Reference in New Issue
Block a user