Question

I have database with table 'Product', column 'Name'. I need to implement case and accent insensitive search so I tried to change collation of the column like this:

EXEC sp_fulltext_column @tabname = 'Product' , @colname = 'Name', @action = 'drop' 

ALTER TABLE dbo.Product
ALTER COLUMN Name nvarchar(400) COLLATE SQL_Latin1_General_CP1_CI_AI NOT NULL;

EXEC sp_fulltext_column @tabname = 'Product' , @colname = 'Name', @action = 'add'

Then I checked the collation of the column like this:

SELECT collation_name  FROM sys.columns 
WHERE name = 'name' AND object_id = (select object_id from sys.tables where name = 'Product');

And collation is set correctly to CI and AI (SQL_Latin1_General_CP1_CI_AI).

I have test products in database with names like 'Čučoriedka', 'Čúčo', 'Test'. I would like to be able select 'Čučoriedka' and 'Čúčo' by query:

select * from product where CONTAINS([Name], 'cuc')

But neither 'test' is working with this queries:

select * from product where CONTAINS([Name], 'tes')
select * from product where PATINDEX('tes', [Name] COLLATE SQL_Latin1_General_CP1_CI_AI ) > 0 

I tried also another collations, but nothing works.

Do you have any idea what can help here?

Thanks a lot! Marek

Was it helpful?

Solution

I found the solution! I found out that, collation has impact only for ordering. I'm using fulltext search so I need to change fulltext indexes. Here is how I did if anyone else need do the same..

IF EXISTS (SELECT 1 FROM sys.fulltext_indexes WHERE object_id = object_id('Product'))
DROP FULLTEXT INDEX ON [Product]

DECLARE @create_index_text nvarchar(4000)
SET @create_index_text = '
  IF NOT EXISTS (SELECT 1 FROM sys.fulltext_indexes WHERE object_id = object_id(''[Product]''))
  ALTER FULLTEXT INDEX ON [Product]([Name]  Language 1051, [ShortDescription]  Language 1051, [FullDescription]  Language 1051, [Sku]  Language 1051)
  KEY INDEX [' + dbo.[nop_getprimarykey_indexname] ('Product') +  '] ON [nopCommerceFullTextCatalog] WITH CHANGE_TRACKING AUTO'
EXEC(@create_index_text)

ALTER FULLTEXT CATALOG nopCommerceFullTextCatalog REBUILD WITH ACCENT_SENSITIVITY=OFF;

The language code 1051 is for slovak language, you can find your code here: http://technet.microsoft.com/en-us/library/ms176076.aspx

Hope it helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top