|
11 | 11 |
|
12 | 12 | #include "postgres.h" |
13 | 13 |
|
| 14 | +#include "access/hash.h" |
14 | 15 | #include "access/htup_details.h" |
| 16 | +#include "catalog/pg_collation.h" |
15 | 17 | #include "catalog/pg_type.h" |
16 | 18 | #include "funcapi.h" |
17 | 19 | #include "miscadmin.h" |
|
25 | 27 |
|
26 | 28 | #include <math.h> |
27 | 29 |
|
| 30 | +PG_FUNCTION_INFO_V1(rum_cmp_tslexeme); |
28 | 31 | PG_FUNCTION_INFO_V1(rum_extract_tsvector); |
29 | 32 | PG_FUNCTION_INFO_V1(rum_extract_tsquery); |
30 | 33 | PG_FUNCTION_INFO_V1(rum_tsvector_config); |
@@ -503,11 +506,15 @@ rum_extract_tsvector(PG_FUNCTION_ARGS) |
503 | 506 | for (i = 0; i < vector->size; i++) |
504 | 507 | { |
505 | 508 | text *txt; |
| 509 | + bytea *hash_value; |
506 | 510 | bytea *posData; |
507 | 511 | int posDataSize; |
508 | 512 |
|
509 | 513 | txt = cstring_to_text_with_len(STRPTR(vector) + we->pos, we->len); |
510 | | - entries[i] = PointerGetDatum(txt); |
| 514 | + hash_value = (bytea *) palloc(VARHDRSZ + sizeof(int32)); |
| 515 | + SET_VARSIZE(hash_value, VARHDRSZ + sizeof(int32)); |
| 516 | + *VARDATA(hash_value) = DirectFunctionCall1(hashtext, PointerGetDatum(txt)); |
| 517 | + entries[i] = PointerGetDatum(hash_value); |
511 | 518 |
|
512 | 519 | if (we->haspos) |
513 | 520 | { |
@@ -586,10 +593,14 @@ rum_extract_tsquery(PG_FUNCTION_ARGS) |
586 | 593 | for (i = 0; i < (*nentries); i++) |
587 | 594 | { |
588 | 595 | text *txt; |
| 596 | + bytea *hash_value; |
589 | 597 |
|
590 | 598 | txt = cstring_to_text_with_len(GETOPERAND(query) + operands[i]->distance, |
591 | 599 | operands[i]->length); |
592 | | - entries[i] = PointerGetDatum(txt); |
| 600 | + hash_value = (bytea *) palloc(VARHDRSZ + sizeof(int32)); |
| 601 | + SET_VARSIZE(hash_value, VARHDRSZ + sizeof(int32)); |
| 602 | + *VARDATA(hash_value) = DirectFunctionCall1(hashtext, PointerGetDatum(txt)); |
| 603 | + entries[i] = PointerGetDatum(hash_value); |
593 | 604 | partialmatch[i] = operands[i]->prefix; |
594 | 605 | (*extra_data)[i] = (Pointer) map_item_operand; |
595 | 606 | } |
@@ -1389,3 +1400,17 @@ rum_ts_join_pos(PG_FUNCTION_ARGS) |
1389 | 1400 |
|
1390 | 1401 | PG_RETURN_BYTEA_P(result); |
1391 | 1402 | } |
| 1403 | + |
| 1404 | +Datum |
| 1405 | +rum_cmp_tslexeme(PG_FUNCTION_ARGS) |
| 1406 | +{ |
| 1407 | + bytea *arg1 = PG_GETARG_BYTEA_P(0); |
| 1408 | + bytea *arg2 = PG_GETARG_BYTEA_P(1); |
| 1409 | + int32 a = *VARDATA(arg1); |
| 1410 | + int32 b = *VARDATA(arg2); |
| 1411 | + int cmp; |
| 1412 | + |
| 1413 | + cmp = (a > b) ? 1 : ((a == b) ? 0 : -1); |
| 1414 | + |
| 1415 | + PG_RETURN_INT32(cmp); |
| 1416 | +} |
0 commit comments