Guest User

Untitled

a guest
Jan 5th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. CREATE OR REPLACE FUNCTION docs_within_distance(vec topics, threshold float)
  2. RETURNS TABLE(doc_id int, distance float) AS $$
  3. BEGIN
  4. RETURN QUERY
  5. SELECT *
  6. FROM (SELECT id, (SELECT sum(vec[i] * ln(vec[i] / topics[i]))
  7. FROM generate_subscripts(topics, 1) AS i
  8. WHERE topics[i] > 0) AS distance
  9. FROM doc) AS tab
  10. WHERE tab.distance < threshold
  11. ORDER BY tab.distance;
  12. END;
  13. $$ LANGUAGE plpgsql;
Add Comment
Please, Sign In to add comment