| 11 文書検索のSQLは頑張ってます /* Document - 検索結果一覧 */ with tags_wv as ( select c001 as tag from apex_collections where collection_name = 'SEARCH_HASHTAGS' ), owners_wv as ( select c001 as owner from apex_collections where collection_name = 'SEARCH_OWNERS' ), doc_tags_wv as ( select link_num from tcw_hashtags where hashtag in (select tag from tags_wv) group by link_num having count(*) >= (select count(*) from tags_wv) ), doc_words_wv as ( select l.link_num from tcw_documents l left outer join tcw_doc_data d on l.link_num = d.link_num where contains(d.link_object, :AI_CONTAINS) > 0 or contains(l.obj_name, :AI_CONTAINS) > 0 or contains(l.abstract, :AI_CONTAINS) > 0 group by l.link_num ), doc_own_wv as ( select d.link_num from tcw_documents d left outer join tcw_doc_acls a on d.link_num = a.link_num where d.opl_code > 0 and d.in_consulting <= nvl(:IN_CONSULTING, 0) and (d.opl_code < 6 or d.upd_username = :APP_USER or a.user_name = :APP_USER) group by d.link_num ), doc_acls_wv as ( select d.link_num from tcw_documents d left outer join tcw_doc_acls a on d.link_num = a.link_num where d.opl_code > 0 and d.in_consulting <= nvl(:IN_CONSULTING, 0) and ( ( d.opl_code < 6 and ( d.upd_username in (select owner from owners_wv) or a.user_name in (select owner from owners_wv) ) ) or ( d.opl_code = 6 and ( ( d.upd_username in (select owner from owners_wv) and d.upd_username = :APP_USER ) or ( a.user_name in (select owner from owners_wv) and a.user_name = :APP_USER ) ) ) ) group by d.link_num ) select case when l.upd_username = :APP_USER or l.link_num in (select link_num from tcw_doc_acls where user_name = :APP_USER) then '<a href="' || apex_page.get_url(p_page => 2, p_clear_cache => 2, p_items => 'P2_LINK_NUM', p_values => l.link_num) || '"><span class="t-Icon fa fa-pencil"></a>' else '' end rowop, l.link_num as link_num, case when l.opl_code = 1 then '<div class="tcw-confsquare orange" title="公開資料"/>' when l.opl_code = 2 then '<div class="tcw-confsquare blue" title="Company Confidential"/>' when l.opl_code = 3 then '<div class="tcw-confsquare green" title="Internal Use Only"/>' when l.opl_code = 4 then '<div class="tcw-confsquare red" title="Strictly Confidential"/>' when l.opl_code = 5 then '<div class="tcw-confsquare black" title="Consulting Only"/>' when l.opl_code = 6 then '<div class="tcw-confsquare black" title="Private"/>' else to_char(l.opl_code) end opl_code_text, case when d.link_object is not null then '<a href="' || 'f?p=' || :APP_ID || ':DOWNLOAD:' || :APP_SESSION || '::NO::DOWNLOAD_LINK_NUM:' || l.link_num || '" title="' || d.file_name || '">' || l.obj_name || '</a><p class="tcw- Abstract">'||htf.escape_sc(substr(l.abstract,1,80))||'...</p>' when l.link_url is not null then '<a href="' || l.link_url || '" title="' || l.link_url || '">' || l.obj_name || '</a><p class="tcw- Abstract">'||htf.escape_sc(substr(l.abstract,1,80))||'...</p>' else l.obj_name end title, case when u.last_name is null then '<a href="' || apex_page.get_url(p_page => 5, p_request => 5, p_items => 'P0_KEYWORD', p_values=> '@' || l.upd_username) ||'">'|| tcw_util.get_name_part(l.upd_username) ||'</a>' else '<a href="' || apex_page.get_url(p_page => 5, p_request => 5, p_items => 'P0_KEYWORD', p_values=> '@' || l.upd_username) ||'">'|| u.last_name || ' ' || u.first_name||'</a>' end owner, l.upd_date updated, t.content_type_alias type, k.link_names related_url, l.upd_username r_last_updated_by, l.opl_code r_classification, l.obj_name r_title from tcw_documents l left outer join (tcw_doc_data d left outer join tcw_content_types t on d.content_type = t.content_type) on l.link_num = d.link_num left outer join tcw_user_names u on l.upd_username = u.user_name left outer join tcw_doc_links_v k on l.link_num = k.link_num where l.opl_code > 0 and l.in_consulting <= nvl(:IN_CONSULTING, 0) and ( ( case when (select count(*) from apex_collections where collection_name in ('SEARCH_WORDS','SEARCH_HASHTAGS','SEARCH_OWNERS')) = 0 and nvl(tcw_util.get_preference('CARE_NEWARRAIVAL'),'Y') = 'Y' then ( select x.link_num from tcw_documents x where x.upd_date > add_months(sysdate, -1) and x.announce_flag = 1 and x.link_num = l.link_num ) else l.link_num end ) = l.link_num and ( case when :AI_CONTAINS is not null then (select v.link_num from doc_words_wv v where v.link_num = l.link_num) else l.link_num end ) = l.link_num and ( case when (select count(*) from tags_wv) > 0 then (select v.link_num from doc_tags_wv v where v.link_num = l.link_num) else l.link_num end ) = l.link_num and ( case when (select count(*) from owners_wv) > 0 then (select v.link_num from doc_acls_wv v where v.link_num = l.link_num) else (select v.link_num from doc_own_wv v where v.link_num = l.link_num) end ) = l.link_num ) 以前はPL/SQLにて動的にSQLを生成していたが書き換えた。