Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows search - full text search in c#

I am looking for a code that gets results of full text search using Windows search (it should be available in Vista, 7 and 8 by default).

I have found some questions here and some texts on msdn, but none of them have some exact code that works. I have tried with Windows API Code Pack (as it is mentioned as one of the interfaces to Windows Search), but it returns results only for file names, not for full text.

like image 347
Ivan Ičin Avatar asked Jun 30 '13 10:06

Ivan Ičin


People also ask

How do I search all text files in Windows 10?

Turn on Option To Search Through File ContentsOn the Indexing Options dialog box, click Advanced. Click the File Types tab on the Advanced Options dialog box. By default, all the extensions are selected, and that's what we want. This will allow Windows to search through all the types of files on your hard drive.

How do I do a detailed search in Windows?

Tap on the Windows start button and open “Settings.” Click on “Search,” then “Searching Windows.” Under “Classic,” select “Customize search location here.”

How do I search an entire folder for text?

If you'd like to always search within file contents for a specific folder, navigate to that folder in File Explorer and open the “Folder and Search Options.” On the “Search” tab, select the “Always search file names and contents” option.


2 Answers

Here is the code that does work - in example I made it to search for the word "dummy" in the desktop folder:

string connectionString = "Provider=Search.CollatorDSO;Extended Properties=\"Application=Windows\"";
OleDbConnection connection = new OleDbConnection(connectionString);

string query = @"SELECT System.ItemName FROM SystemIndex " +
   @"WHERE scope ='file:" + System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "' and FREETEXT('dummy')";
OleDbCommand command = new OleDbCommand(query, connection);
connection.Open();

List<string> result = new List<string>();

OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
    result.Add(reader.GetString(0));
}

connection.Close();
like image 143
Ivan Ičin Avatar answered Oct 04 '22 11:10

Ivan Ičin


Take a look at the DSearch example. Windows Search Code Samples

That's what you want.

like image 22
user743414 Avatar answered Oct 04 '22 11:10

user743414