3 CREATE OR REPLACE FUNCTION evergreen.rank_ou(lib INT, search_lib INT, pref_lib INT DEFAULT NULL)
7 -- lib matches search_lib
8 (SELECT CASE WHEN $1 = $2 THEN -20000 END),
10 -- lib matches pref_lib
11 (SELECT CASE WHEN $1 = $3 THEN -10000 END),
14 -- pref_lib is a child of search_lib and lib is a child of pref lib.
15 (SELECT distance - 5000
16 FROM actor.org_unit_descendants_distance($3)
17 WHERE id = $1 AND $3 IN (
18 SELECT id FROM actor.org_unit_descendants($2))),
20 -- lib is a child of search_lib
21 (SELECT distance FROM actor.org_unit_descendants_distance($2) WHERE id = $1),
23 -- all others pay cash
26 $$ LANGUAGE SQL STABLE;