3

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?

Rocklan
  • 7,888
  • 3
  • 34
  • 49
  • Have you run the query locally on the server to see if it is returning results? Are you looking for a string without spaces or single character, or are you looking for a sentence or phrase? The CONTAINS predicate with no column defined searches ONLY the contents of the file as well, not sure if you had intended that. – randcd Jul 30 '13 at 19:01
  • Also you may try reordering your WHERE clause to move CONTAINS first and SCOPE second to see if that matters any... – randcd Jul 30 '13 at 19:07

2 Answers2

2

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.

Yakov R.
  • 602
  • 8
  • 22
  • It doesn't work. Search.CollatorDSO.1” provider don't support ICommandWithParameters interface.Current provider program don't support command parameters. – Surfsky Nov 20 '19 at 04:08
0

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%'
Surfsky
  • 86
  • 5