trueideal

用Indexing service做全文索引

这几天有一个小项目要用Indexing service索引文件档.开始一想用SQL Server的link server来做非常简单且容易用将索引服务的数据与数据库中的记录进行关联查询.

结果项目做完后,发现用户的环境是两天Server,一台Database server,一台站点Server.因为好像Indexing Service与SQL Server做link 时只能在同一台机器上,不知有没有朋友实现过跨服务器的link.

没办法,后来我已为Indexing Service可进行远程索引,但我这边试了无数次,也还是不行(登录账号绝对没有问题),就是索引不到文件.

 

最后没办法,只能用oledb来读取索引了,这个缺点就是没法直接来SQL Server进行关联查询了,只能先读取到dataset中,再将SQL中的读到另一Dataset中进行关联匹配筛选等操作了.

public static System.Data.DataSet funDataSet_IndexSyn(string strValue)
{
    System.Data.DataSet ds = new System.Data.DataSet();
    try
    {
        string strCatalog = "DocumentCatelog";//CatalogName
        string strQuery = "";
        strQuery = @"Select FileIndex , FileName,SIZE, DocAuthor, path,DocAppName ,
                    DocCategory,DocCharCount,DocComments,DocCompany ,DocKeywords ,DocTitle 
                    ,DocCreatedTm,docsubject  from Scope()  where FREETEXT('" + strValue + "')";
        string ConnString = "Provider=MSIDXS.1;Integrated Security .='';Data Source=" + strCatalog;
        System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(ConnString);
        conn.Open();
        System.Data.OleDb.OleDbDataAdapter cmd = new System.Data.OleDb.OleDbDataAdapter(strQuery, conn);
        cmd.Fill(ds);
    }
    catch
    {
    }
    return ds;
}

如果要用FileIndex 进行查询,在SQL Server 用link Server时可认为是字符串搜索,如

FileIndex='" FileIndexID+ "'"

但在oledb中要用

FileIndex=" +Int64.Parse(FileIndexID)

posted on 2010-02-27 09:04  trueideal  阅读(234)  评论(0编辑  收藏  举报

导航