0

Linq to SQL で CONTAINSTABLE を使用できるようにするために、SQL Server UDF を使用しています。

文字列配列と正規表現を使用して、ユーザーの検索文字列を認識可能な単語に分割し、文字列配列を CONTAINSTABLE 構文に準拠する検索条件文字列に再構築しています。

ユーザーがフレーズを引用符で囲むことができるようにしたいと思います。つまり、ユーザーが「yellow "blue green"」と入力した場合、検索条件は「yellow OR "blue green"」である必要があります。次のコードを考えると、これを処理する最善の方法は何でしょうか。

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;

ありがとう!

4

1 に答える 1

0

.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;
于 2012-05-15T15:45:02.550 に答える