Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE FUNCTION docs_within_distance(vec topics, threshold float)
- RETURNS TABLE(doc_id int, distance float) AS $$
- BEGIN
- RETURN QUERY
- SELECT *
- FROM (SELECT id, (SELECT sum(vec[i] * ln(vec[i] / topics[i]))
- FROM generate_subscripts(topics, 1) AS i
- WHERE topics[i] > 0) AS distance
- FROM doc) AS tab
- WHERE tab.distance < threshold
- ORDER BY tab.distance;
- END;
- $$ LANGUAGE plpgsql;
Add Comment
Please, Sign In to add comment