Skip to content

Instantly share code, notes, and snippets.

@pka
Last active June 9, 2017 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pka/f6bb2fadaa48ae9e259b59e173c88ce2 to your computer and use it in GitHub Desktop.
Save pka/f6bb2fadaa48ae9e259b59e173c88ce2 to your computer and use it in GitHub Desktop.
Quickfinder adress search example
CREATE MATERIALIZED VIEW av.adressen AS
SELECT hau.pk, lok.r1_text || COALESCE(' ' || hau.r1_hausnum, '') AS adresse, hau.wkb_geometry
FROM av.ge_hausnummerpos hau
JOIN av.ge_lokalisationsnamepos lok ON lok.r1_benannt=hau.r1_gebaeud;
CREATE INDEX adressen_trgm_idx ON av.adressen USING gin (adresse gin_trgm_ops);
SELECT adresse,ST_AsBinary(wkb_geometry)::geometry
FROM av.adressen
WHERE similarity(adresse, %(search)s) > 0.2
ORDER BY adresse <-> %(search)s
LIMIT %(limit)s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment