A union of curiosity and data science

Knowledgebase and brain dump of a database engineer


SQL Server: Store localized versions of strings with language specific full text search

CREATE TABLE [dbo].[LanguageStrings](

       [Id] [int] IDENTITY(1,1) NOT NULL,

       [String] [xml] NOT NULL,

 

I added a full text index on the String column without specifying a language for the index. I then inserted the following into it.

 

INSERT INTO LanguageStrings VALUES

(

       '<strings>

              <string xml:lang="en">run</string>

              <string xml:lang="es">correr</string>

       </strings>'

)

 

The following query returns a row as expected.

 

select * from LanguageStrings where contains(String, 'formsof(inflectional, "run")', language 'English')

 

The past tense “ran” also returns a row proving that the inflectional search is working on the index.

 

select * from LanguageStrings where contains(String, 'formsof(inflectional, "ran")', language 'English')

 

If I search for “ran”, but tell the search to use Spanish as the language it returns no rows proving that it’s only searching the xml elements that are marked with the language specified.

 

select * from LanguageStrings where contains(String, 'formsof(inflectional, "ran")', language 'Spanish')

 

If I search for “correr” using Spanish as the language it returns a row.

 

select * from LanguageStrings where contains(String, 'formsof(inflectional, "correr")', language 'Spanish')

 

And if I search for the past tense “corrió” it also returns a row proving that inflectional search is also properly working for Spanish.

 

select * from LanguageStrings where contains(String, 'formsof(inflectional, "corrió")', language 'Spanish')

Add comment