1

我目前正試圖添加一個FULLTEXT索引,以便能夠在包含關鍵詞的敘述欄中搜索關鍵詞。我已經嘗試了許多不同的教程,雖然我完全複製它們,但我無法在「WHERE」部分中使用'CONTAINS'功能時複製結果。SQL - FULLTEXT INDEX

下面是我使用一些示例數據的腳本示例。有人能夠向我解釋爲什麼這不起作用,因爲我正在認真努力地看到錯誤可能在哪裏。

CREATE TABLE dbo.AAAA_FullTextTest5 
    (ID INT Identity(1, 1) NOT NULL 
    ,LOCATION VARCHAR (255) 
    ,NARRATIVE VARCHAR(MAX) 
    ) 

ALTER TABLE dbo.AAAA_FullTextTest5 add constraint PK_FullTextTest5 PRIMARY KEY (ID) 

INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('USA Texas', 'WRIGHT BROTHERS') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Worldwide', 'CROWN PROS Builders LTD') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Devon United Kingdom', 'J PJH ROOFING LTD') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('UK', 'Shoreham Port Authority and Shoreham Port Developments & The Port of Shoreham Trustees ') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('EUROPE AND RUSSIA', 'ZHY SERVICES') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Austrialia', 'BrotherLimited') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('ASIA', 'DRILLING SERVICES LTD') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('JAPAN', 'BROOKS WASTE LTD') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Melbourne', 'TRC Service Company') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('GERMANY & HOLLAND', 'Samson Group') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Frankfurt', 'SCAFFOLDING LTD') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Swindon, England', 'Scaffold Access Ltd') 

CREATE FULLTEXT CATALOG FullTextTest5 

CREATE FULLTEXT INDEX ON dbo.AAAA_FullTextTest5 (
      Location language 1033 
      ,Narrative language 1033) 
KEY INDEX PK_FullTextTest5 ON FullTextTest5 
WITH CHANGE_TRACKING AUTO 

SELECT * FROM dbo.AAAA_FullTextTest5 
WHERE CONTAINS(NARRATIVE, 'Access') 
+0

哪個dbms? (這是產品特定的功能....) – jarlh 2015-03-25 12:29:50

+0

你能澄清它爲什麼不起作用嗎?任何錯誤,或只是不是你期望的結果(如果是的話)? – 2015-03-25 12:47:27

+0

運行時不會出現錯誤。它只是沒有結果被返回,我不明白爲什麼基於至少有一個結果與單詞'訪問'在其中。 – bwsutton 2015-03-25 13:49:26

回答

0

基於這裏的說明:https://msdn.microsoft.com/en-us/library/ms142497.aspx,下面會出現在我的本地安裝SQL Server 2008 R2中的正常工作,以及我的SQL Server的本地安裝2012:

CREATE TABLE dbo.AAAA_FullTextTest5 
    (ID INT Identity(1, 1) NOT NULL 
    ,LOCATION VARCHAR (255) 
    ,NARRATIVE VARCHAR(MAX) 
    ) 
GO 

CREATE UNIQUE INDEX UI_AAAA_FullTextTest5 ON dbo.AAAA_FullTextTest5(ID) 
GO 

INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('USA Texas', 'WRIGHT BROTHERS') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Worldwide', 'CROWN PROS Builders LTD') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Devon United Kingdom', 'J PJH ROOFING LTD') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('UK', 'Shoreham Port Authority and Shoreham Port Developments & The Port of Shoreham Trustees ') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('EUROPE AND RUSSIA', 'ZHY SERVICES') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Austrialia', 'BrotherLimited') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('ASIA', 'DRILLING SERVICES LTD') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('JAPAN', 'BROOKS WASTE LTD') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Melbourne', 'TRC Service Company') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('GERMANY & HOLLAND', 'Samson Group') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Frankfurt', 'SCAFFOLDING LTD') 
INSERT INTO dbo.AAAA_FullTextTest5 (LOCATION, NARRATIVE) VALUES ('Swindon, England', 'Scaffold Access Ltd') 
GO 

CREATE FULLTEXT CATALOG AAAA_FTCat; 
GO 

CREATE FULLTEXT INDEX ON AAAA_FullTextTest5 
(
    NARRATIVE       --Full-text index column name 
    Language 2057     --2057 is the LCID for British English 
) 
KEY INDEX UI_AAAA_FullTextTest5 ON AAAA_FTCat --Unique index 
WITH CHANGE_TRACKING AUTO   --Population type; 
GO 

隨着代替上述設置,然後我就可以查詢:

SELECT * FROM AAAA_FullTextTest5 
WHERE CONTAINS(NARRATIVE, 'Access') 

而得到這樣的結果集:

ID LOCATION   NARRATIVE 
12 Swindon, England Scaffold Access Ltd 
+0

嗨保羅 感謝您的回答。不幸的是,這仍然似乎沒有2012年的工作。 – bwsutton 2015-03-25 14:39:24

+0

@bwsutton你確定你已經正確地複製了代碼嗎?我可以使用相同的結果集對SQL Server 2012本地副本運行此操作。 – 2015-03-25 14:49:02

+0

嗨保羅 是的我相信我已經正確地複製了它,只是讓我的同事讓我去檢查。我現在嘗試了幾次,不幸的是仍然返回0行。 – bwsutton 2015-03-25 14:59:33