Keywords: → custom ranking postgres full-text-search
→ stackoverflow.com/q/49050450
CREATE OR REPLACE FUNCTION public.ts_rank_custom(v tsvector, q tsquery)
RETURNS real
LANGUAGE plpgsql
IMMUTABLE PARALLEL SAFE STRICT
AS $func$
DECLARE
subtotal REAL;
ta text[];
i bigint;
BEGIN
SELECT INTO subtotal ts_rank(v,q);
ta = tsvector_to_array(v);
FOR i IN 1 .. array_upper(ta,1)
LOOP
IF length(ta[i])<4 THEN
subtotal = subtotal * 1.1;
END IF;
END LOOP;
RETURN subtotal;
END;
$func$;
Note:
SELECT array_upper(ARRAY[11,12,13],1);
=> 3