惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
Help Net Security
Help Net Security
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
LINUX DO - 热门话题
Security Latest
Security Latest
A
Arctic Wolf
G
GRAHAM CLULEY
月光博客
月光博客
S
Securelist
D
Docker
J
Java Code Geeks
T
Troy Hunt's Blog
T
Tenable Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
SecWiki News
SecWiki News
S
Security @ Cisco Blogs
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 最新话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
博客园 - 【当耐特】
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 三生石上(FineUI控件)
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
Netflix TechBlog - Medium
Vercel News
Vercel News
Forbes - Security
Forbes - Security
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
B
Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Check Point Blog
云风的 BLOG
云风的 BLOG
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
L
Lohrmann on Cybersecurity
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed

博客园 - 陈叙远

发现了lucene一个bug .netFramework1.1下创建文件几种方式的不同之处 关于密码管理,一个很好的思路 无ASPX文件部署(续) NO Stop的GUI 在c#中调用windows脚本的方法 - 陈叙远 - 博客园 .net中的魔字符串 - 陈叙远 - 博客园 有人对开发一个开发平台感兴趣吗? 用来整理桌面的jscript脚本 某知名软件公司的一道笔试题 令人困绕的timer 热烈庆祝第一次博客园&博客堂线下聚会圆满成功 hello customer & order----你是哪一级? 立即释放.net下的com组件 笔试题系列之四 java和c#语言上的一个不同之处 - 陈叙远 - 博客园 笔试题系列之三 笔试题系列之二 中秋佳节,献上笔试题一道,祝各位事业蒸蒸日上!
介绍一下Hyper Estraier
陈叙远 · 2006-12-08 · via 博客园 - 陈叙远

Hyper Estraier 是一个来自日本的全文搜索引擎,作者是 Mikio Hirabayashi,目前最高版本是1.49

可以从这里下载编译好的版本

个引擎使用C开发,另外提供了java以及rubyperl言的上API引擎使用2.1版本的GNU Lesser General Public License为开协议LGPL是一个商友好的License,大家可以放心地用在自己的工程中。

hyperestraier-1.4.9-win32.zip解压缩到d:\hyperestraier文件夹,从中可以找到README-en.txt这个文件,这个文件中简要介绍了重要文件的清单,大家可以先看一下,熟悉下情况,其中重点关注的是estcmd.exeestraier.jar

下面主要围绕这两个文件做下介绍

estcmd.exe是一个命令行工具,通过它,可以完成基本的搜索工作,供大家测试之用;

estraier.jar的全称是Java Binding of Hyper Estraier,是一个使用JNI技术的上层JAVA API,通过它,可以使用JAVA编程来调用这个引擎。

estcmd.exe的核心命令有两个,分别是gather(创建索引)search(搜索)

下面我们实战一下

首先创建一个文件夹d:\myData,然后找些htm以及txt文件copy进去

在开始菜单-〉运行中键入cmd,打开命令行界面,切换到estcmd.exe所在的文件夹,运行下面的命令

estcmd gather -sd myData d:\myData

这个命令的意思是,对d:\myData下的所有文件建立索引,索引数据库的名称为myData

命令运行后,可以在看到目录下的所有文件被一一registered,最后,会提示

estcmd:INFO:finished successfully:elapsed time: *h *m *s

其中*表示创建索引所花费的时间

这样,索引就建好了,dir一下,可以发现,当前目录下多了一个叫做myData的文件夹,这就是索引库

来,让我们体验一下全文搜索的魅力吧

运行下面的命令

estcmd search -ic Shift-Jis -vx myData どうぞ

这个意思是以Shift-Jis作为编码格式,在索引库myData中,搜索どうぞ,如果不需要指定编码格式,则可以去掉 –ic Shift-Jis命令

呵呵,看到搜索结果了吧,如果觉得搜索结果可读性不好,也可以将 –vx指令换成 –vh,这样,将把输出结果由xml格式变为摘要格式

喝口水,接着说

下面介绍如何通过JAVA API来完成同样的工作

首先,在操作系统的系统环境变量中,找到PATH,向其中加入d:\hyperestraier

然后,打开Eclipse,新建一个项目,并在Build PathAdd External JARs,添加对前面提到的estraier.jar的引用

最后,在代码中,import estraier.*;

好了,可以写程序了

Database db = new Database();

if(!db.open("D:\\hyperestraier\\myData",

Database.DBWRITER | Database.DBCREAT)){

System.err.println("error: " + db.err_msg(db.error()));

return;

}

Document doc = new Document();

doc.add_attr("@uri", "d:\\myData\\helloworld.txt");

doc.add_attr("@title", "helloworld");

doc.add_attr("otherAttribute", "attributeValue");

doc.add_text("life's made up of little things.");

if(!db.put_doc(doc, Database.PDCLEAN))

System.err.println("error: " + db.err_msg(db.error()));

if(!db.close())

System.err.println("error: " + db.err_msg(db.error()));

程序的大意是,新建或打开索引库D:\hyperestraier\myData

向其中添加一个文档,文档的地址是d:\myData\helloworld.txt

文档标题为helloworld

这个文档还有一个额外的自定义属性,属性的名/值为otherAttribute/ attributeValue

文档的内容为life's made up of little things

还差最后一点,就是通过程序检索了

Database db = new Database();

if(!db.open("D:\\hyperestraier\\myData", Database.DBREADER)){

System.err.println("error msg: " + db.err_msg(db.error()));

return;

}

Condition cond = new Condition();

cond.set_phrase("どうぞ");

//cond.set_order("@size NUMA");

//cond.set_order("otherAttribute STRD ");

cond.set_max(5);

//cond.add_attr("otherAttribute STREQ  value");

//cond.add_attr("@title STRINC hello");

Result result = db.search(cond);

for(int i = 0; i < result.doc_num(); i++){

Document doc = db.get_doc(result.get_doc_id(i), 0);

if(doc == null) continue;

String uri = doc.attr("@uri");

if(uri != null) System.out.println("URI: " + uri);

String title = doc.attr("@title");

if(title != null) System.out.println("Title: " + title);

String myAttr = doc.attr("otherAttribute");

if(myAttr != null) System.out.println("otherAttribute:" + myAttr);

else System.out.println("there's no attr named otherAttribute ");

Iterator it = doc.texts().iterator();

while(it.hasNext()){

System.out.println((String)it.next());

}

}

if(!db.close())

System.err.println("error: " + db.err_msg(db.error()));

程序的大意是,对索引库D:\hyperestraier\myData,检索关键词,然后把前5条结果输出

程序中还注释掉了一些检索条件留给大家探索哈

啰罗嗦嗦写了半天,就先介绍到这里吧,进一步的学习,大家可以参考D:\hyperestraier下的doc文件夹中的帮助,帮助有英/日两国文字,总有一款适合您