Я экспериментирую с поиском свободного текста в 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')