public static List <WindowsSearchResult> Search(string term) { var list = new List <WindowsSearchResult>(); // prevent hidden (0x2) and system (0x4) files var sql = @"select top 1000 System.ItemNameDisplay, System.ItemPathDisplay, System.Kind, System.Search.Rank, System.FileAttributes from systemindex where CONTAINS(""System.ItemNameDisplay"", '""*{0}*""') and System.FileAttributes <> ALL BITWISE 0x4 and System.FileAttributes <> ALL BITWISE 0x2 order by System.Search.Rank" ; using (OleDbCommand command = new OleDbCommand()) { command.Connection = _connection; command.CommandText = string.Format(sql, term.Trim()); using (OleDbDataReader reader = command.ExecuteReader()) { while (reader.Read()) { var result = new WindowsSearchResult() { FileName = reader["System.ItemNameDisplay"].ToString(), FilePath = reader["System.ItemPathDisplay"].ToString(), Rank = (int)reader["System.Search.Rank"] }; String[] kinds = reader["System.Kind"] as String[]; if (kinds != null && kinds.Length >= 1) { foreach (var k in reader["System.Kind"] as String[]) { result.Kind |= (WindowsSearchKind)Enum.Parse(typeof(WindowsSearchKind), k); } } else { result.Kind = WindowsSearchKind.file; } list.Add(result); } } } var results = list.Distinct(p => p.FileName).ToList(); return(results); }
public static List<WindowsSearchResult> Search(string term) { var list = new List<WindowsSearchResult>(); // prevent hidden (0x2) and system (0x4) files var sql = @"select top 1000 System.ItemNameDisplay, System.ItemPathDisplay, System.Kind, System.Search.Rank, System.FileAttributes from systemindex where CONTAINS(""System.ItemNameDisplay"", '""*{0}*""') and System.FileAttributes <> ALL BITWISE 0x4 and System.FileAttributes <> ALL BITWISE 0x2 order by System.Search.Rank"; using (OleDbCommand command = new OleDbCommand()) { command.Connection = _connection; command.CommandText = string.Format(sql, term.Trim()); using (OleDbDataReader reader = command.ExecuteReader()) { while (reader.Read()) { var result = new WindowsSearchResult() { FileName = reader["System.ItemNameDisplay"].ToString(), FilePath = reader["System.ItemPathDisplay"].ToString(), Rank = (int)reader["System.Search.Rank"] }; String[] kinds = reader["System.Kind"] as String[]; if (kinds != null && kinds.Length >= 1) { foreach (var k in reader["System.Kind"] as String[]) { result.Kind |= (WindowsSearchKind)Enum.Parse(typeof(WindowsSearchKind), k); } } else { result.Kind = WindowsSearchKind.file; } list.Add(result); } } } var results = list.Distinct(p => p.FileName).ToList(); return results; }