解决HubbleDotNet搜索引擎索引数据不全的问题

简介:

   HubbleDotnet是国产.NET平台搜索引擎的翘楚,开放源代码,使用方便,不过我一直在非生产环境下使用。官方网页在HubbleDotNet开源全文搜索数据库项目--技术详解.

      以前当数据库使用Mysql的时候没问题,但当使用了MonogoDB做数据源之后,经常出现数据无法全部自动索引的情况。比如有10W的表,常常只能索引到3W甚至更少,乃至每次索引的数量都不同。

  这件事拖了我很久,万不得已看日志查源代码,才发现是一个程序上的bug.

  系统日志记录如下:


LogTime:2015-01-06 16:43:32.773
Process:HubbleTask
Message:ErrMsg:Get documents for insert fail!
Exception:System.ArgumentException
Message:列“Year”不属于表 Table1。
Stack:   在 System.Data.DataRow.GetDataColumn(String columnName)
   在 System.Data.DataRow.get_Item(String columnName)
   在 Hubble.Core.Service.SynchronizeCanUpdate.GetOneRowDocument(DataRow row) 位置 d:\Codes\C#\OpenSources\hubbledotnet-100319\C#\src\Hubble.Data\Hubble.Core\Service\SynchronizeCanUpdate.cs:行号 300
   在 Hubble.Core.Service.SynchronizeCanUpdate.GetDocumentsForInsert(IDBAdapter dbAdapter, Int64& from) 位置 d:\Codes\C#\OpenSources\hubbledotnet-100319\C#\src\Hubble.Data\Hubble.Core\Service\SynchronizeCanUpdate.cs:行号 471
   在 Hubble.Core.Service.SynchronizeCanUpdate.DoGetDocumentsForInsertAsync(Object dbAdapter) 位置 d:\Codes\C#\OpenSources\hubbledotnet-100319\C#\src\Hubble.Data\Hubble.Core\Service\SynchronizeCanUpdate.cs:行号 425

    找到对应的源代码,SynchronizeCanUpdate.cs,位置如下:


foreach (Field field in _DBProvider.Table.Fields)
            {
                if (field.IndexType == Field.Index.None)
                {
                    if (!_DBProvider.Table.HasMirrorTable)
                    {
                        continue;
                    }
                }

                string value = null;

                if (row[field.Name] == DBNull.Value)  //此处出错
                {
                    if (!field.CanNull)
                    {
                        throw new DataException(string.Format("Field:{0} in table {1} is not null so that it can't be inserted null value!",
                            field.Name, _DBProvider.Table.Name));
                    }

                    if (field.DefaultValue == null)
                    {
                        if (field.IndexType != Field.Index.None)
                        {
                            throw new DataException(string.Format("Field:{0} in table {1} is null but hasn't default value so that it can't be inserted null value!",
                                field.Name, _DBProvider.Table.Name));
                        }
                    }

                    value = field.DefaultValue;
                }
                else
                {
                    if (row[field.Name] is DateTime)
                    {
                        value = ((DateTime)row[field.Name]).ToString("yyyy-MM-dd HH:mm:ss.fff");
                    }
                    else
                    {
                        value = row[field.Name].ToString();
                    }
                }

                document.Add(field.Name, value, field.DataType, field.DataLength, false);
            }

      很清楚,DataRow中,没有Year这个字段。但是我在建立索引 表的时候,是添加了一个可空字段Year的啊,更何况,其他条数据的索引都没问题,但就会遇到一些数据Row没有Year. 字段。可能是HubbleDotnet对MongoDb的驱动支持不够完善吧,在中间的转换出了问题,改进也很简单:


foreach (Field field in _DBProvider.Table.Fields)
            {
                if (field.IndexType == Field.Index.None)
                {
                    if (!_DBProvider.Table.HasMirrorTable)
                    {
                        continue;
                    }
                }

                string value = null;

                object v = DBNull.Value;
                try
                {
                    if (row.Table.Columns.Contains(field.Name))  //此处判断是否拥有该字段
                    {
                        v = row[field.Name];
                        
                    } 
                }
                catch (Exception ex)
                {

                    Global.Report.WriteErrorLog(string.Format("this is a null value, collum {0} not in the table",field.Name));
                }


                if (v == DBNull.Value)
                {
                    if (!field.CanNull)
                    {
                        throw new DataException(string.Format("Field:{0} in table {1} is not null so that it can't be inserted null value!",
                            field.Name, _DBProvider.Table.Name));
                    }

                    if (field.DefaultValue == null)
                    {
                        if (field.IndexType != Field.Index.None)
                        {
                            throw new DataException(string.Format("Field:{0} in table {1} is null but hasn't default value so that it can't be inserted null value!",
                                field.Name, _DBProvider.Table.Name));
                        }
                    }

                    value = field.DefaultValue;
                }
                else
                {
                    if (v is DateTime)
                    {
                        value = ((DateTime)v).ToString("yyyy-MM-dd HH:mm:ss.fff");
                    }
                    else
                    {
                        value = v.ToString();
                    }
                }

                document.Add(field.Name, value, field.DataType, field.DataLength, false);
            }

另外的问题如下:


LogTime:2015-01-06 17:52:34.389
Process:HubbleTask
Message:System.ArgumentException: 输入字符串的格式不正确。不能在 JournalName 列中存储 <research in microelectronics and electronics, 2005 phd>。所需类型是 Double。 ---> System.FormatException: 输入字符串的格式不正确。
   在 System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   在 System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
   在 System.Double.Parse(String s, NumberStyles style, NumberFormatInfo info)
   在 System.String.System.IConvertible.ToDouble(IFormatProvider provider)
   在 System.Data.Common.DoubleStorage.Set(Int32 record, Object value)
   在 System.Data.DataColumn.set_Item(Int32 record, Object value)
   --- 内部异常堆栈跟踪的结尾 ---
   在 System.Data.DataColumn.set_Item(Int32 record, Object value)
   在 System.Data.DataRow.set_Item(DataColumn column, Object value)
   在 Hubble.Core.DBAdapter.MongoAdapter.QuerySql(String sql) 位置 d:\Code\OpenSource\hubbledotnet-100319\C#\src\Hubble.Data\Hubble.Core\DBAdapter\MongoAdapter.cs:行号 1081

    明明我在JournalName 存储的是一个NVarchar字段,此处却一定要提示我所需类型是double,系统脑抽么,这也是MongoAdapter的映射没做好,好在这种情况在整个数据集中出现的次数很少,我加上Try-Catch,输出了Log日志,解决了这个问题(O(∩_∩)O~)。

  以上两个问题解决之后,搜索引擎可以正确检索全部数据了,好开心。

  好水的文章,能解决别人的问题也是好的,虽然解决方法没那么优雅,而且Hubble现在还有人用么?默默的匿了。



相关文章
|
Java C语言
为什么说指针是 C 语言的精髓?
为什么说指针是 C 语言的精髓?
325 0
|
8天前
|
域名解析 人工智能 Linux
|
19天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
17318 63
|
17天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
2天前
|
人工智能 安全 网络安全
|
6天前
|
云安全 数据采集 人工智能
|
7天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1331 3
|
14天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2407 7
|
19天前
|
弹性计算 人工智能 API
Codex超详细入门指南(下载·安装·登录·上手,全版本覆盖,2026最新版)
建议收藏本教程,2026 全年各版本更新随时回来查阅。如果你在搭建过程中遇到任何问题,欢迎结合 阿里云工单系统 提交技术支持请求,或在 阿里云开发者社区 搜索 Codex 相关话题交流。 祝你编码愉快,效率翻倍!
3883 22
|
20天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是DeepSeek AI开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、跑命令、处理表格、联网搜索等操作。免费开源,兼容Windows/macOS/Linux,提供桌面端与网页端,可灵活安装插件扩展能力。

热门文章

最新文章