      where st_dwithin(s.geography, v_geography, v_radius)
        and st.tag = any (v_tag_ids)
        and s.side = 'PROVIDE'
+       and s.status = 'ACTIVE'
      group by s.id;
   else
     -- v_side = 'PROVIDE'

     where st_dwithin(s.geography, v_geography, s.radius)
       and st.tag = any (v_tag_ids)                  
       and s.side = 'SEEK'
     group by s.id;
  end if;
end;

    select t.search_id, t.matches, t.distance, t.score, t.query
      from speedycrew.find_matches(i_search_id) t
  loop
    -- this is the aggressive search
    a := i_search_id;
    b := v_search_id;
    matches = v_matches;
    distance = v_distance;
    score := v_score;
    message := null;
    return next;
    -- the is the passive search
    a := v_search_id;
    b := i_search_id;
    if v_my_side = 'PROVIDE' then
        message := 'Captain sighted: ' || v_query;
    else
	message := 'Crew sighted: ' || v_query;
    end if;
    return next;
  end loop;
end;
