我在远程计算机上有需要编制索引的文件。我正在使用本地计算机的索引服务来索引这些文件,但我无法做到这一点。
如果有人可以建议我怎么做或者可以使用远程计算机的索引服务?
public DataSet performBasicSearch(ref string msg, string strWithAllWords, string strExactPhrase, string strWithAtleast, string strWithOutwords, string strWithWordsNear, string libName)
{
ConnectionOleDb Objconn = new ConnectionOleDb();
DataSet dSetBSearchResults = new DataSet();
OleDbDataAdapter dAdpt;
int ANDFlag = 0, i, enableNOT = 0, jT; ;
string queryString = "\"Test\"", testStr = "\"";
queryString = "SELECT filename FROM SCOPE()";
string[] abc;
try
{
if (Objconn.Ini_Connection(ref msg, "Provider=MSIDXS.1;Data Source=" + libName) == true)
{
if ((strWithAllWords.Length > 0) || (strExactPhrase.Length > 0) || (strWithWordsNear.Length > 0) || (strWithAtleast.Length > 0))
{
queryString = queryString + " WHERE ";
}
if (strWithAllWords.Length > 0)
{
ANDFlag = 1;
enableNOT = 1;
abc = strWithAllWords.Split(' ');
for (i = 0; i <= (abc.Length - 1); i++)
{
if (i > 0)
{
queryString = queryString + "AND CONTAINS(";
queryString = queryString + "'\"" + abc[i].ToString() + "\"'";
queryString = queryString + ")";
}
else
{
queryString = queryString + "CONTAINS('\"";
queryString = queryString + abc[i].ToString();
queryString = queryString + "\"')";
}
}
}
//Contaning With exact Phrase
if (strExactPhrase.Length > 0)
{
if (ANDFlag == 1)
{
queryString = queryString + " AND ";
}
ANDFlag = 1;
enableNOT = 1;
queryString = queryString + "(";
queryString = queryString + " Contains(contents, '\"" + strExactPhrase.ToString() + "\"')";
queryString = queryString + ")";
}
if (strWithAtleast.Length > 0)
{
if (ANDFlag == 1)
{
queryString = queryString + " AND ";
}
ANDFlag = 1;
enableNOT = 1;
queryString = queryString + "(";
queryString = queryString + "FreeText('" + strWithAtleast + "') ";
queryString = queryString + ") ";
}
if (strWithWordsNear.Length > 0)
{
if (ANDFlag == 1)
{
queryString = queryString + " AND ";
}
ANDFlag = 1;
enableNOT = 1;
abc = strWithWordsNear.Split(' ');
queryString = queryString + "(";
queryString = queryString + "Contains(contents, '";
for (i = 0; i <= (abc.Length - 1); i++)
{
if (i > 0)
{
queryString = queryString + " NEAR \"" + abc[i].ToString() + "\"";
}
else
{
queryString = queryString + "\"" + abc[i].ToString() + "\"";
}
}
queryString = queryString + "'))";
}
if ((strWithOutwords.Length > 0) && (enableNOT > 0))
{
abc = strWithOutwords.Split(' ');
for (i = 0; i <= (abc.Length - 1); i++)
{
if (i > 0)
{
queryString = queryString + " AND NOT FreeText('" + abc[i].ToString() + "') ";
}
else
{
queryString = queryString + " AND NOT FreeText('" + abc[i].ToString() + "') ";
}
}
}
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = queryString;
cmd.Connection = Objconn.conn;
cmd.CommandType = CommandType.Text;
dAdpt = new OleDbDataAdapter(cmd);
dAdpt.Fill(dSetBSearchResults);
return dSetBSearchResults;
}
else
{
return null;
}
}
catch (Exception ex)
{
msg = ex.Message;
return null;
}
}//end function