如何使用纯 JavaScript 和 HTML5 创建客户端全文搜索引擎?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11340852/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create client side full text search engine with pure JavaScript and HTML5?
提问by Mohammad Nikravan
I need to create client side search engine for an offline html application in offline storage like CDROM. I already create it with Win32 and the catalog file is near 2GB (MDB file).
我需要为离线存储(如 CDROM)中的离线 html 应用程序创建客户端搜索引擎。我已经用 Win32 创建了它,并且目录文件接近 2GB(MDB 文件)。
My offline web application use CEF (Chromium Embedded Framework) and PhoneGAP so I can disable the browser web security. I thought the IndexedDB may help me but , I couldn't find anyway to copy the storage file to other media.
我的离线 Web 应用程序使用 CEF(Chromium 嵌入式框架)和 PhoneGAP,因此我可以禁用浏览器 Web 安全性。我认为 IndexedDB 可能对我有帮助,但是无论如何我都找不到将存储文件复制到其他媒体的方法。
- My catalog file will be near 2GB, so I can't read all record to memory.
- I need to make the output media cross-platfrom with PhoneGAP, so I can't use activeX objects for final search. Also I can disable web security restriction by that tools.
- I can create the catalog file and media with any windows application. the key note that the output file that query the catalog should be be pure JavaScript.
- 我的目录文件将接近 2GB,因此我无法将所有记录读取到内存中。
- 我需要使用 PhoneGAP 使输出媒体跨平台,所以我不能使用 activeX 对象进行最终搜索。我也可以通过该工具禁用网络安全限制。
- 我可以使用任何 Windows 应用程序创建目录文件和媒体。关键是查询目录的输出文件应该是纯JavaScript。
Is there any HTML5 big storage system available (I can disable web security by PhoneGAP) to create offline HTML application search catalog that can be copied to other removable media?
是否有任何可用的 HTML5 大存储系统(我可以通过 PhoneGAP 禁用网络安全)来创建可以复制到其他可移动媒体的离线 HTML 应用程序搜索目录?
回答by bobylito
Reyes is doing a fulltext search engine for this exact purpose : https://github.com/reyesr/fullproof
雷耶斯正在为此目的做一个全文搜索引擎:https: //github.com/reyesr/fullproof
During last september Paris JS, he did a presentation of the concepts behind : http://kornr.net/prez/paris.js22/#/
在去年九月的巴黎 JS 期间,他做了一个背后的概念的介绍:http: //kornr.net/prez/paris.js22/#/
Hope it answers your need.
希望它能满足您的需求。
回答by vanthome
回答by biphobe
Saving whole database in .json file definitely wouldn't be efficient, but splitting your database to chunks and saving them as .json files loaded on demand may work just fine - it would require testing though.
将整个数据库保存在 .json 文件中肯定不会有效率,但是将您的数据库拆分为块并将它们保存为按需加载的 .json 文件可能会工作得很好 - 不过它需要测试。
And - MongoDB stores database in BSON. You can also think about storing your database in this file format and loading it from your application (I would suggest splitting the whole database to smaller parts anyway).
并且 - MongoDB 将数据库存储在BSON 中。您还可以考虑以这种文件格式存储您的数据库并从您的应用程序加载它(无论如何我建议将整个数据库拆分为更小的部分)。
// edit - If you're going to give away the database as file, then I don't think that it's possible to set any kind of permissions. You could try to encrypt/obfuscate the file, but I have no idea how would that affect the performance or database' contents.
// 编辑 - 如果您打算将数据库作为文件赠送,那么我认为不可能设置任何类型的权限。您可以尝试加密/混淆文件,但我不知道这会如何影响性能或数据库的内容。
And yes, it is possible to have a standalone html+js application that would read the BSON database without any kind of server. Check this linkif you want to know more. I've heard of this before, but I have completely no experience when it comes to handling BSON files in pure JS, so I can't help you out with this. All I could do was to let you know that such a thing exists :)
是的,可以有一个独立的 html+js 应用程序,它可以在没有任何类型的服务器的情况下读取 BSON 数据库。如果您想了解更多信息,请查看此链接。我以前听说过这个,但是在纯 JS 中处理 BSON 文件时我完全没有经验,所以我无法帮助你。我所能做的就是让你知道这样的事情存在:)