`
shirlly
  • 浏览: 1623359 次
  • 性别: Icon_minigender_2
  • 来自: 福州
社区版块
存档分类
最新评论

Hubble.Net实现全文检索

阅读更多
一、 下载安装

到Hubble.net 项目首页 http://hubbledotnet.codeplex.com/的 download tab 里面下载安装文件
根据你的操作系统下载不同的安装包,我的系统是32位的windows 7系统,所以我下载

最好是下载最新版的,因为新版是对旧版的改进和修复。
Hubble。Net是个开源的项目,所以,你可以把他们的源码下载下来学习下

还可以下载一些文档学习下,如果安装和Hubble.Net使用手册,还有Demo


安装的时候,可以查看安装文档<<Hubble.Net安装指南.pdf>>

安装完,出现无法连接的情况,有可能是因为你安装的版本跟你操作系统的不对应,造成服务无法启动,或启动遇到错误而终止。
二、 配置Hubble.Net
安装完可以在系统应用程序中看到Query Analyzer应用程序,Hubble.Net和关系数据库之间的关系,主要是通过这个工具配置的。这个查询分析器的使用方法,可以查阅文档<<查询分析器使用指南.pdf>>
三、 需要明确几点
1、 Hubble.Net不存在实体数据库,只是在硬盘某一目录下建一个文件夹,来存放索引文件,这个索引就类似于字典的检索目录
2、 关系数据库和 Hubble.Net数据库要分开建,先在SQL Server Managerment Studio中建好关系数据库,然后在Query Analyzer中建数据库并建立和关系数据库的关系;Query Analyzer可以同时操作Hubble.Net数据库和关系数据库的表操作
四、 项目中的应用
(1)、配置webconfig文件
<connectionStrings> 
<add name="HubbleNetConnection" connectionString="Data Source=127.0.0.1; uid=sa;pwd=123456;Initial Catalog=News;" providerName="Hubble.SQLClient"/> 
</connectionStrings>

如果是集成windows身份认证,配置是这么写的
Data Source=127.0.0.1;Initial Catalog=News;Integrated Security=True

(2)、在Web项目中的bin中放入相应动态链接库


(3)、连接Hubble.Net获取DataSet

ConnectionStringSettings connString = WebConfigurationManager.ConnectionStrings["HubbleNetConnection"];
using (HubbleConnection conn = new HubbleConnection(connString.ConnectionString))
        {
            conn.Open();

            GetColumnAnalyzerName(conn, "News");
            HubbleCommand matchCmd = new HubbleCommand(conn);

            string wordssplitbyspace;
            string titleMatchString = matchCmd.GetKeywordAnalyzerStringFromServer("News", "Title", keywords, int.MaxValue, out wordssplitbyspace);
            string contentMatchString = matchCmd.GetKeywordAnalyzerStringFromServer("News", "Content", keywords, int.MaxValue, out wordssplitbyspace);

            //查单表
            HubbleCommand cmd = new HubbleCommand("select between {0} to {1} * from News where content match {2} or title^2 match {3} order by score desc, time desc",
                conn, (pageNo - 1) * pageLength, pageNo * pageLength - 1, contentMatchString, titleMatchString);

            //查多表(有几个需要注意的地方:1、sql前面要加[UnionSelect];2、查找的字段需写明确,不能用*;3、每个SQL返回的字段必须相同,返回的记录数也要相同;4、多条SQL之间用分号分开)
            //HubbleCommand cmd = new HubbleCommand("[UnionSelect] select between {0} to {1} title,content,url,time from News where content match {2} or title^2 match {3} order by score desc, time desc;select between {0} to {1} title,content,url,time from Activity where content match {2} or title^2 match {3} order by score desc, time desc",
            //    conn, (pageNo - 1) * pageLength, pageNo * pageLength - 1, contentMatchString, titleMatchString);

            newsDataSet = cmd.Query(CacheTimeout); 
        }




补充几个常见问题
1.无法连接,重启下服务试试
2.hubble.net 服务的端口是7523 如果连接不上,看下防火墙是否开启了这个端口
2.如果数据库中还有表,则默认不能删除数据库,如果你要删除数据库,要先删除表
3.创建数据了表的时候都有连接数据库,所以当数据库迁移的时候,要删掉原来的表和数据库重新建索引数据库
3.配置文件连接hubble.net数据库,不能用“.”只能用“127.0.0.1”
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics