fissoft / Fissoft.EntityFramework.Fts

Full Text Search for Microsoft SQL Server with Entity Framework
MIT License
59 stars 14 forks source link

"System.Data.SqlClient.SqlException: Syntax error near ... in the full-text search condition ..." when using special characters #4

Open icnocop opened 8 years ago

icnocop commented 8 years ago

I expected to be able to perform a full text search using special characters.

Here is an example unit test that fails for each of these special characters, but there could be more.

        [TestMethod]
        public void Contains_UsingSpecialCharacters_Succeeds()
        {
            foreach (string specialCharacter in new[]
            {
                "\"",
                "'",
                ")",
                "(",
                "%"
            })
            {
                using (var db = new MyDbContext())
                {
                    db.Database.Log = Console.WriteLine;
                    var text = FullTextSearchModelUtil.Contains(specialCharacter);
                    var query = db.TestModel
                        .Where(c => c.Name.Contains(text))
                        .ToList();
                }
            }
        }

Any work-arounds or recommendations?

Thank you!

shyamal890 commented 7 years ago

If I enter a string like '[Something]'. I get an error saying

Syntax error near '[' in the full-text search condition '(~[something])

Same issue with a string containing commas

Syntax error near ',' in the full-text search condition '(KGBV,Vinchiya,Jasdan)

@icnocop @chsword were you able to find a workaround for this?

chsword commented 7 years ago

@shyamal890 '[Something]' do not work with contains(it do not work in the T-SQL also), I think in this case, maybe try freetext

icnocop commented 5 years ago

I also found the same error with these special characters: Underscore (_) Tilde (~) Caret Symbol (^)