I am trying to search a remote fileshare (running windows server 2008 R2) for files that contain some text. If I try this, it works fine:
SELECT System.FileName
FROM RemoteServer.SystemIndex
WHERE SCOPE='file://RemoteServer/FileShare'
and I get lots of results. But as soon as I try to search for some text I get no results:
SELECT System.FileName
FROM RemoteServer.SystemIndex
WHERE SCOPE='file://RemoteServer/FileShare'
AND CONTAINS('a')
if I try it on my machine (Windows 7) it works fine:
SELECT FileName
FROM SystemIndex
WHERE CONTAINS('a')
Here is my c# code that I'm using to search:
string connectionString = "Provider=Search.CollatorDSO;Extended Properties=\"Application=Windows\"";
using (OleDbConnection myOleDbConnection = new OleDbConnection(connectionString))
{
myOleDbConnection.Open();
using (OleDbCommand myOleDbCommand = new OleDbCommand(sql, myOleDbConnection))
{
using (myDataReader = myOleDbCommand.ExecuteReader())
{
if (!myDataReader.HasRows)
{
System.Console.WriteLine("Query returned 0 rows!");
}
else
{
// Process results here
}
}
}
}
I have tried the following:
- Rebuilt the index
- Checked that the folder "FileShare" has been added on the server to be indexed
- Checked the "File Types" tab, that the correct extensions are ticked, and that "Index Properties and File Contents" is selected for those extensions
- Restarted the indexing service
- Restarted the server itself
to no avail.
Any other suggestions? Frustrating as I'm 99% of the way there. This whole windows desktop search seems to be pretty unsupported, maybe I should bin it and use something else?
Try declaring a nvarchar variable for the search word
Then Modify your code to:
This excerpt is from TechNet on CONTAINS See TechNet
*contains_search_condition* is nvarchar. An implicit conversion occurs when another character data type is used as input. In the following example, the @SearchWord variable, which is defined as varchar(30), causes an implicit conversion in the CONTAINS predicate.