END;
$$
LANGUAGE plpgsql IMMUTABLE;
+
+
+CREATE OR REPLACE FUNCTION weigh_search(search_vector INT[],
+ term_vectors TEXT[],
+ weight_vectors FLOAT[],
+ def_weight FLOAT)
+ RETURNS FLOAT
+ AS $$
+DECLARE
+ pos INT := 1;
+ terms TEXT;
+BEGIN
+ FOREACH terms IN ARRAY term_vectors
+ LOOP
+ IF search_vector @> terms::INTEGER[] THEN
+ RETURN weight_vectors[pos];
+ END IF;
+ pos := pos + 1;
+ END LOOP;
+ RETURN def_weight;
+END;
+$$
+LANGUAGE plpgsql IMMUTABLE;
"""
assert self.rankings
- col = table.c[self.column]
-
- return sa.case(*((col.contains(r.tokens),r.penalty) for r in self.rankings),
- else_=self.default)
+ return sa.func.weigh_search(table.c[self.column],
+ [f"{{{','.join((str(s) for s in r.tokens))}}}"
+ for r in self.rankings],
+ [r.penalty for r in self.rankings],
+ self.default)
@dataclasses.dataclass
return f"{self.major}.{self.minor}.{self.patch_level}-{self.db_patch_level}"
-NOMINATIM_VERSION = NominatimVersion(4, 2, 99, 1)
+NOMINATIM_VERSION = NominatimVersion(4, 2, 99, 2)
POSTGRESQL_REQUIRED_VERSION = (9, 6)
POSTGIS_REQUIRED_VERSION = (2, 2)