0

現在、このクエリは article と呼ばれるテーブルを検索して、タイトルと要約フィールドに特定のキーワードが含まれているエントリを探します。返されるセットは、タイトルと要約にキーワードが含まれる記事ですが、タイトルまたは要約にキーワードが含まれる記事を返すように変更したいと思います。どうすればこれを達成できますか? 内部結合を外部結合に変更するだけですか?

BEGIN
    with articlesearch as (
    SELECT top 1000 FT_TBL.articleID, FT_TBL.title,FT_TBL.abstract,FT_TBL.publicationdate,
        (select j.journalID from journal  j where FT_TBL.journalID=j.journalID) as sourceID,
        (select j.journalname from journal  j where FT_TBL.journalID=j.journalID) as sourcename,
        (select j2.medabbr from journal j2 where FT_TBL.journalID=j2.journalID) as medabbr,
        (select j1.impactfactor from journal  j1 where FT_TBL.journalID=j1.journalID) as impactfactor,
        KEY_TBL.RANK,
        ROW_NUMBER() OVER (ORDER BY KEY_TBL.RANK desc) AS RowNumber
    FROM article AS FT_TBL 
        INNER JOIN 
            CONTAINSTABLE(article,title,@keyword) AS KEY_TBL
            ON FT_TBL.articleID = KEY_TBL.[KEY]
        INNER JOIN
            CONTAINSTABLE(article,abstract,@keyword) AS KEY_TBL2
            ON FT_TBL.articleID = KEY_TBL2.[KEY]
    where  FT_TBL.inactive=0
    ORDER BY RANK DESC
    )

    SELECT articleID, sourcename,title,abstract,publicationdate,medabbr  
    FROM articlesearch
    WHERE RowNumber BETWEEN @RowStart AND @RowEnd ORDER BY publicationdate desc;

END 
4

3 に答える 3

2

次のバージョンでは、inner joinsがleft outer joinsに変更され、必要なものを取得するための句が追加whereされています。

with articlesearch as (
SELECT top 1000 FT_TBL.articleID, FT_TBL.title,FT_TBL.abstract,FT_TBL.publicationdate,
    (select j.journalID from journal  j where FT_TBL.journalID=j.journalID) as sourceID,
    (select j.journalname from journal  j where FT_TBL.journalID=j.journalID) as sourcename,
    (select j2.medabbr from journal j2 where FT_TBL.journalID=j2.journalID) as medabbr,
    (select j1.impactfactor from journal  j1 where FT_TBL.journalID=j1.journalID) as impactfactor,
    KEY_TBL.RANK,
    ROW_NUMBER() OVER (ORDER BY KEY_TBL.RANK desc) AS RowNumber
FROM article AS FT_TBL 
    left outer JOIN 
        CONTAINSTABLE(article,title,@keyword) AS KEY_TBL
        ON FT_TBL.articleID = KEY_TBL.[KEY]
    left outer join 
        CONTAINSTABLE(article,abstract,@keyword) AS KEY_TBL2
        ON FT_TBL.articleID = KEY_TBL2.[KEY]
where FT_TBL.inactive=0 and (key_tbl.[key] is not null or key_tbl2.[key] is not null)
ORDER BY RANK DESC
)

SELECT articleID, sourcename,title,abstract,publicationdate,medabbr  
FROM articlesearch
WHERE RowNumber BETWEEN @RowStart AND @RowEnd ORDER BY publicationdate desc;
于 2012-11-20T23:04:37.593 に答える
0

INNER JOINDigitalDが示すように、をに変更する必要がありOUTERますが、少なくとも1つの結合が空でない場合は結果をフィルタリングする必要もあります。

-- snip
----
-- /snip
FROM article AS FT_TBL 
    LEFT OUTER JOIN 
        CONTAINSTABLE(article,title,@keyword) AS KEY_TBL
        ON FT_TBL.articleID = KEY_TBL.[KEY]
    LEFT OUTER JOIN
        CONTAINSTABLE(article,abstract,@keyword) AS KEY_TBL2
        ON FT_TBL.articleID = KEY_TBL2.[KEY]
WHERE  FT_TBL.inactive=0
    AND (KEY_TBL.[KEY] IS NOT NULL OR KEY_TBL2.[KEY] IS NOT NULL)
ORDER BY RANK DESC
)

-- snip
----
-- /snip
于 2012-11-20T23:09:47.523 に答える
0

INNER JOINon each を a に変更するLEFT JOINと、必要なものが得られるようです。慣れていないことは認めますが、CONTAINSTABLE

于 2012-11-20T22:52:09.810 に答える