public IEnumerable<SearchResult> Query(String query) { var results = new List<SearchResult>(); if (String.IsNullOrWhiteSpace(query)) return results; var tokens = query.Split(' '); var builder = new SqlBuilder(); var selector = builder.AddTemplate("select * from TextIndex /**where**/"); foreach (var token in tokens) { builder.WhereAny("Token = @tkn", new { tkn = token }); } using (var conn = new SqlConnection(_connectionString)) { conn.Open(); var sqlResults = conn.Query(selector.RawSql, selector.Parameters); var grouped = sqlResults.GroupBy(r => (String)r.SourceFile, r => (Int32)r.Occurances); foreach (var group in grouped) { results.Add(new SearchResult { FileName = group.Key, Relevance = group.Sum(g => g) }); } } return results; }