I made some progress but I'm stuck. I'm focused on GiST for now. Please ignore sloppy naming for now.
I made the following changes to pg_trgm--1.2.sql:
CREATE TYPE pg_trgm_match AS (match TEXT, threshold REAL);
CREATE OR REPLACE FUNCTION trgm_check_match(string TEXT, match pg_trgm_match) RETURNS bool AS $$
BEGIN
RETURN match.match <-> string <= 1 - match.threshold;
END;
$$ LANGUAGE plpgsql;
CREATE OPERATOR %%(leftarg = text, rightarg = pg_trgm_match, procedure=trgm_check_match);
ALTER OPERATOR FAMILY gist_trgm_ops USING gist ADD
OPERATOR 9 %% (text, pg_trgm_match);
It does indeed make PostgreSQL complain about undefined strategy 9. I added the following define to trgm.h:
#define ThresholdStrategyNumber 9
It seems StrategyNumber is used in gtrgm_consistent and gtrgm_distance.
In gtrgm_consistent, I need change the way `nlimit` is obtained:
nlimit = (strategy == SimilarityStrategyNumber) ?
similarity_threshold : word_similarity_threshold;
I need to add a case for ThresholdStrategyNumber and extract `nlimit` from the argument of `pg_trgm_match`. I'm not sure what to do in `gtrgm_distance`.
My questions:
1a. Is it possible to make `gtrgm_consistent` accept `text` or `pg_trgm_match` as the second argument?
1b. What's the equivalent of `match.match` and `match.threshold` (where `match` is a `pg_trgm_match`) in C?
2. What to do with `gtrgm_distance`?
Thanks for help.
-- Greg Navis
I help tech companies to scale Heroku-hosted Rails apps.