Indexing Service simple sample

23 篇文章 0 订阅
Indexing Service 简单例子

1.要使用Windows的全文搜索服务,首先要确保在“添加删除程序/添加删除Windows组件/”中安装了“索引服务”:

然后就可以使用Indexing Service了,包括进行编程。
安装了索引服务后就可以到“计算机管理/服务和应用程序/”中找到索引服务,并对之进行设置和管理:

默认情况下会有两个编目(Catalog),System和Web,分别用于建立和维护本地文件和本地网站的索引。每个编目包含了多个目录(Scope),并有一个属性(Property)集合。
 
2.关于Windows Indexing Service的相关文档、编程参考和代码片断都可以在msdn中找到,下面是链接:
 
3.由于IndexingService相关API都是通过COM组件的形式提供的,因此如果要在程序中调用相关API,就必须首先添加对如下Type Library的引用:

API Reference Library
Admin Helper Indexing Service Administration Type Library 1.0 CIODMLib
Query Helper ixsso Control Library Cisso
ADO Micorsoft ActiveX Data Objects (ADO) version Library, where version is one of the available versions. ADODB
下面是对Indexing Service进行设置和管理的编程对象:
Object nameDescription
AdminIndexServer Manages Indexing Service. Allows access to all the functionality provided by the Microsoft Management Console (MMC) snap-in.
CatAdm Manages the collection of scopes for a catalog.
ScopeAdm Manages an individual scope.
下面是通过IndexingService进行全文搜索的编程对象:

Object nameDescription
Query Manages the query definition and result-set creation and navigation.
Utility Helpful utilities for managing the queries and result sets.
msdn的文档中提供了一些比较简单的示例代码,分别由VBScript, JScript, Visual Basic, Visual C++, 和Visual J++的代码,好像没有.NET的代码。
需要添加com引用
Interop.CIODMLib.dll
Interop.Cisso.dll
可用object browser查看里面的类
try
            {
                Cisso.CissoQueryClass query = new Cisso.CissoQueryClass();
               
                query.Columns = "Filename,Path,Size";
                query.Query = tbKeywords.Text;
                //query.CiScope = "";
                query.Catalog = "Web";// "testCatalog";
                OleDbDataAdapter sda = new OleDbDataAdapter();
                DataTable dtResult = new DataTable();
                sda.Fill(dtResult, query.CreateRecordset("nonsequential"));
                //dtResult.Columns[
                gvResult.DataSource = dtResult;
                gvResult.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        private DataTable GetIndexingServiceSearchResult()
        {
            Cisso.CissoQueryClass q = new Cisso.CissoQueryClass();
            Cisso.CissoUtilClass util = new Cisso.CissoUtilClass();
            OleDbDataAdapter da = new OleDbDataAdapter();
            DataTable dt = new DataTable();
            q.Query = tbKeywords.Text;
            q.Catalog = FullTextSearchCatalog;
            q.SortBy = "Filename";
            q.Columns = "Filename,Path,Size";
            util.AddScopeToQuery(q, FullTextSearchScope, "deep");
            da.Fill(dt, q.CreateRecordset("nonsequential"));
            return dt;
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值