2

I've written a program that presents a web interface to a file share on a Windows 2012 R2 server. Within the webapp, I've added the ability to query the Windows Search index running on that server so users can get results back. Below is the query that's used to search in index:

SELECT System.FileName, System.ItemPathDisplay, System.ItemType, System.Size, System.ItemDate, System.DateModified
FROM myserver.systemindex
WHERE SCOPE='file://myserver/myshare' AND System.FileName LIKE '%<somevalue>%'

Works well for most scenarios, except for numbers in file names. It appears that any only groups numbers as a whole. For example, if I have a file named "G-5687-R2.txt", a search for "G", "G-5687", "5687", or "2" will return the document. However, searches for "G-56" or "56" return nothing. Performing a "56" search within windows explorer does return the document, so I think there's something missing from my query.

Complete code below:

string searchLocation = "file://myserver/myshare";
string searchString = "56";
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Search.CollatorDSO.1;Extended Properties='Application=Windows';";

OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText = string.Format("SELECT System.FileName, System.ItemPathDisplay, System.ItemType, System.Size, System.ItemDate, System.DateModified FROM " +
" myserver.systemindex WHERE SCOPE='{1}' AND" + 
" System.FileName LIKE " +  " '%{0}%'"
, searchString, searchLocation);

conn.Open();
OleDbDataReader rdr = cmd.ExecuteReader();
Evan M.
  • 211
  • 1
  • 4
  • 13

0 Answers0