使用String.Join构建Linq到SQL ContainsTable搜索条件

使用String.Join构建Linq到SQL ContainsTable搜索条件,string,linq-to-sql,String,Linq To Sql,我正在使用SQLServerUDF来允许我在LINQtoSQL中使用CONTAINSTABLE 我使用字符串数组和正则表达式将用户的搜索字符串拆分为可识别的单词,然后将字符串数组重新组合为符合CONTAINSTABLE语法的搜索条件字符串 我想让用户能够用引号括住短语。换句话说,如果用户输入“黄色”或“蓝绿色”,则搜索条件应为“黄色或“蓝绿色”,在给出以下代码的情况下,处理此问题的最佳方法是什么 IEnumerable<string> keywords = Regex .Ma

我正在使用SQLServerUDF来允许我在LINQtoSQL中使用CONTAINSTABLE

我使用字符串数组和正则表达式将用户的搜索字符串拆分为可识别的单词,然后将字符串数组重新组合为符合CONTAINSTABLE语法的搜索条件字符串

我想让用户能够用引号括住短语。换句话说,如果用户输入“黄色”或“蓝绿色”,则搜索条件应为“黄色或“蓝绿色”,在给出以下代码的情况下,处理此问题的最佳方法是什么

IEnumerable<string> keywords = Regex
    .Matches(search, @"(?<match>\w+)|\""(?<match>[\w\s]*)""")
    .Cast<Match>()
    .Select(m => m.Groups["match"].Value)
    .ToList();

string searchCondition = "";
searchCondition = String.Join(" OR ", keywords);

List = from t1 in List
    join fts in _dc.udfSearchContent(searchCondition)
    on t1.ContentID equals fts.ContentID
    select t1;
IEnumerable关键字=Regex
.Matches(搜索,@“(?\w+)\”(?[\w\s]*)”)
.Cast()
.选择(m=>m.Groups[“匹配”].值)
.ToList();
字符串searchCondition=“”;
searchCondition=String.Join(“或”,关键字);
列表=从列表中的t1开始
在_dc.udfSearchContent(searchCondition)中加入fts
在t1.ContentID上等于fts.ContentID
选择t1;
谢谢

.Select(x=>@“+x+@”)
会起作用

IEnumerable<string> keywords = Regex
    .Matches(search, @"(?<match>\w+)|\""(?<match>[\w\s]*)""")
    .Cast<Match>()
    .Select(m => m.Groups["match"].Value)
    .ToList();

string searchCondition = "";
searchCondition = String.Join(" OR ", keywords.Select(x => @"""" + x + @""""));

List = from t1 in List
    join fts in _dc.udfSearchContent(searchCondition)
    on t1.ContentID equals fts.ContentID
    select t1;
IEnumerable关键字=Regex
.Matches(搜索,@“(?\w+)\”(?[\w\s]*)”)
.Cast()
.选择(m=>m.Groups[“匹配”].值)
.ToList();
字符串searchCondition=“”;
searchCondition=String.Join(“或”,关键字。选择(x=>@''+x+@');
列表=从列表中的t1开始
在_dc.udfSearchContent(searchCondition)中加入fts
在t1.ContentID上等于fts.ContentID
选择t1;