我正在尝试在SQL Server 2008上进行自由文本搜索。但是我有问题让它工作。任何人都可以在我的剧本中发现错误:
为什么最后的查询没有结果?
----------------------------------------------------------------------------
-- Set up fulltext search
----------------------------------------------------------------------------
IF FullTextServiceProperty('IsFullTextInstalled') <> 1
BEGIN
PRINT 'Full Text Service is not installed, script is aborted.'
RETURN
END
IF DatabaseProperty(DB_NAME(), 'IsFulltextEnabled') <> 1
EXEC sp_fulltext_database 'enable'
IF NOT EXISTS
(
SELECT 1
FROM sys.fulltext_catalogs (NOLOCK)
WHERE name = 'searchcatalog_test'
)
BEGIN
CREATE FULLTEXT CATALOG searchcatalog_test
WITH ACCENT_SENSITIVITY = OFF
END
----------------------------------------------------------------------------
-- Set up table
----------------------------------------------------------------------------
IF OBJECT_ID('freetext_test', 'U') IS NOT NULL
BEGIN
EXEC SP_FULLTEXT_TABLE 'freetext_test', 'DROP'
DROP TABLE freetext_test
END
CREATE TABLE dbo.freetext_test
(
freetext_id INT IDENTITY
, freetext_data NVARCHAR(MAX)
CONSTRAINT pk_freetext_test PRIMARY KEY (freetext_id)
)
CREATE FULLTEXT INDEX ON freetext_test
(
freetext_data LANGUAGE 0 -- 0 = Neutral
)
KEY INDEX pk_freetext_test ON searchcatalog_test
WITH CHANGE_TRACKING AUTO
INSERT INTO freetext_test(freetext_data)
SELECT N'Some text to test free text searching'
UNION SELECT N'Another text to test with'
UNION SELECT N'Another test string'
UNION SELECT N'Today is a sunny day'
UNION SELECT N'I wonder if anyone at StackOverflow can help me?'
----------------------------------------------------------------------------
-- Test section
----------------------------------------------------------------------------
SELECT * FROM freetext_test
SELECT * FROM freetext_test WHERE FREETEXT (freetext_data, N'test')
SELECT * FROM freetext_test WHERE FREETEXT (freetext_data, N'string')
SELECT * FROM freetext_test WHERE FREETEXT (freetext_data, N'sunny')
SELECT * FROM freetext_test WHERE FREETEXT (freetext_data, N'StackOverflow')
SELECT * FROM freetext_test WHERE CONTAINS (freetext_data, N'text OR test')
SELECT * FROM freetext_test WHERE CONTAINS (freetext_data, N'string OR another')
SELECT * FROM freetext_test WHERE CONTAINS (freetext_data, N'today AND sunny')
SELECT * FROM freetext_test WHERE CONTAINS (freetext_data, N'anyone AND StackOverflow')
答案 0 :(得分:1)
你的剧本就像一个魅力。
您是否正在为索引引擎执行SELECT太快而无法构建目录?