예를 들어 "선로 균열"과 같은 정지 단어로 일부 구문을 검색하려고합니다. "통해"는 말을 멈추게합니다. 쿼리와 같은 결과를 얻고 싶습니다.구문 분석 FORMSOF에 대한 전체 텍스트 검색 조건 단어 제외
그래서 모든 단어의 모든 형태가 정지 단어를 제외한 모든 행을 포함합니다. 고객이 스톱 워드 목록을 모를 경우 할 수 있습니까?
예를 들어 "선로 균열"과 같은 정지 단어로 일부 구문을 검색하려고합니다. "통해"는 말을 멈추게합니다. 쿼리와 같은 결과를 얻고 싶습니다.구문 분석 FORMSOF에 대한 전체 텍스트 검색 조건 단어 제외
그래서 모든 단어의 모든 형태가 정지 단어를 제외한 모든 행을 포함합니다. 고객이 스톱 워드 목록을 모를 경우 할 수 있습니까?
어떤 SQL Server 버전을 사용하고 있습니까? 2008 년 이후라면 질의 런타임에 중지 단어 목록을 프로그래밍 방식으로 검색 할 수 있습니다. 그런 다음 검색 단어 중 하나라도 중지 단어 목록에 있는지 확인하고 "CONTAINS"쿼리 문자열에서 제외 할 수 있습니다.
다음 쿼리 (언어 ID 1033 미국 영어에 대한) 정지 단어의 목록을 반환합니다 : 당신이 이런 일을 할 수있는 검색 시저를 작성할 수이 정보를
-- Run the following to get a list of languages and their IDs
select lcid, name from sys.syslanguages order by 1
-- Then use that ID to get a list of stop words
select * from sys.fulltext_stopwords where language_id = 1033
(이 아주 기본적인 예입니다,하지만 당신은) 생각을해야합니다
USE [AdventureWorks]
GO
-- Make sure you have a full-text catalogue to test against
/*
IF EXISTS(SELECT * FROM sys.fulltext_indexes WHERE [object_id] = OBJECT_ID('Production.ProductDescription'))
DROP FULLTEXT INDEX ON Production.ProductDescription;
IF EXISTS(SELECT * FROM sys.fulltext_catalogs WHERE name = 'FTC_product_description')
DROP FULLTEXT CATALOG FTC_product_description;
CREATE FULLTEXT CATALOG [FTC_product_description]
WITH ACCENT_SENSITIVITY = OFF
AS DEFAULT AUTHORIZATION [dbo]
CREATE FULLTEXT INDEX ON [Production].[ProductDescription]([Description] LANGUAGE [English])
KEY INDEX [PK_ProductDescription_ProductDescriptionID] ON ([FTC_product_description], FILEGROUP [PRIMARY])
WITH (CHANGE_TRACKING = AUTO, STOPLIST = SYSTEM);
*/
GO
IF OBJECT_ID('dbo.my_search_proc') IS NULL EXEC ('CREATE PROC dbo.my_search_proc AS ');
GO
-- My Search Proc
ALTER PROC dbo.my_search_proc (
@query_string NVARCHAR(1000),
@language_id INT = 1033 -- change this to whatever your default language ID is
) AS
BEGIN
SET NOCOUNT ON;
------------------------------------------------------
-- Split the string into 1 row per word
------------------------------------------------------
-- I've done this in-line here for simplicity, but I
-- would recommend creating a CLR function instead
-- for performance reasons.
DECLARE @words TABLE (id INT IDENTITY(1,1), word NVARCHAR(100));
DECLARE @cnt INT, @split_on CHAR(1)
SELECT @cnt = 1, @split_on = ' ';
WHILE (CHARINDEX(@split_on, @query_string) > 0)
BEGIN
INSERT INTO @words (word)
SELECT word = LEFT(LTRIM(RTRIM(SUBSTRING(@query_string,1,CHARINDEX(@split_on,@query_string)-1))), 100);
SET @query_string = SUBSTRING(@query_string,CHARINDEX(@split_on,@query_string)+1,LEN(@query_string));
SET @cnt = @cnt + 1;
END
INSERT INTO @words (word)
SELECT word = LEFT(LTRIM(RTRIM(@query_string)), 100);
------------------------------------------------------
-- Now build your "FORMSOF" string, excluding stop words.
------------------------------------------------------
DECLARE @formsof NVARCHAR(4000);
SELECT @formsof = ISNULL(@formsof, '')
+ 'FORMSOF(INFLECTIONAL, "' + w.word + '") AND '
FROM @words AS w
LEFT JOIN sys.fulltext_system_stopwords AS sw -- use sys.fulltext_stopwords instead if you're using a user-defined stop-word list (or use both)
ON w.word = sw.stopword COLLATE database_default
AND sw.language_id = @language_id
WHERE sw.stopword IS NULL
ORDER BY w.id; -- retain original order in case you do any weighting based on position, etc.
-- If nothing was returned, then the whole query string was made up of stop-words,
-- so just return an empty result set to the application.
IF @@ROWCOUNT = 0
SELECT TOP(0) * FROM Production.ProductDescription;
SET @formsof = LEFT(@formsof, LEN(@formsof)-4); -- Remove the last "AND"
PRINT 'Query String: ' + @formsof
------------------------------------------------------
-- Now perform the actual Full-Text search
------------------------------------------------------
SELECT *
FROM Production.ProductDescription
WHERE CONTAINS(*, @formsof);
END
GO
EXEC dbo.my_search_proc 'bars for downhill';
을 그래서, 당신은 "내리막 바"를 검색하면, 다음 "를") 그 때문에 정지 단어 (교체 아웃 제거됩니다 , 너는 FORMSOF(INFLECTIONAL, "bars") AND FORMSOF(INFLECTIONAL, "downhill").
불행히도 SQL 2005를 사용하고 노이즈 단어 파일의 내용을 모르는 경우에는 내가 아는 한별로 할 수있는 일이 많지 않습니다.
건배, 데이브