Microsoft Desktop Search - CONTAINS not returning results on windows server 2008

1.6k views Asked by At

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?

2

There are 2 answers

1
Yakov R. On

Try declaring a nvarchar variable for the search word

DECLARE @SearchWord nvarchar(30) = 'a'

Then Modify your code to:

SELECT FileName

FROM SystemIndex

WHERE CONTAINS(@SearchWord)

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.

0
Surfsky On

I meet the same problem. After serval days suffering trying, I found out this code that can run in windows server 2008 r2:

AND CONTAINS('keyword')
->
and System.Search.AutoSummary like '%keyword%'