lucene - demo
demo - location:
* download lucene
there is a "demo" folder, it include a war file,
* download lucene source
it include source code for demo,
*
demo - doc:
in lucene's doc, in "Getting Started" section, there is a part about demo,
------
demo - command line
demo - command line, is run under command line,
run steps:
* pre-step
* download lucene,
* uncompress
let's call the root folder as "lucene_home",
*
* create a folder, in some location,
e.g. ~/lucene_demo
* prepare jar
copy jar from "lucene_home" to "lucene_demo/lib", so that to add them into classpath later,
jar list:
* core/lucene-core-4.6.0.jar
* queryparser/lucene-queryparser-4.6.0.jar
* analysis/common/lucene-analyzers-common-4.6.0.jar
* demo/lucene-demo-4.6.0.jar
*
* export jar
linux:
export CLASSPATH = $CLASSPATH:lucene_demo/lib/*
* check jar
linux:
echo $CLASSPATH
make sure the lucene jars are in the classpath,
*
* cd lucene_demo/
* generate index
command:
java org.apache.lucene.demo.IndexFiles -docs lucene_home/docs/
this will create a "index/" folder under current folder, generate index for lucene docs, and store indexes in it,
* search via index
steps:
* enter command
java org.apache.lucene.demo.SearchFiles
* then input a keyword, and enter,
* now it shows the results,
*
* ok
*
*
------
demo - web
demo - web, is a web application, could run on tomcat,
run steps:
* pre-step
* download lucene,
* uncompress lucene,
let's call the root folder as "lucene_home",
* download lucene source,
* uncompress lucene source,
let's call the root folder as "lucene_source_home",
*
* in eclipse, create a web project,
configs:
* java compile level
1.6
* config build path
add a tomcat runtime lib,
*
* add jars
jars could be found in sub folders of "lucene_home",
include:
* lucene-analyzers-common-4.6.0.jar
* lucene-core-4.6.0.jar
* lucene-facet-4.6.0.jar
* lucene-queryparser-4.6.0.jar
* lucene-sandbox-4.6.0.jar
* lucene-queries-4.6.0.jar
* lucene-expressions-4.6.0.jar
*
suggestion:
copy these jars into a single folder on local disk, in eclipse define a user lib to include these lib,
then in eclipse, config build path, add this user library to project,
* copy code
* source code
copy code inside "lucene_source_home/demo/src/java/" into source folder of eclipse project,
optionally, remove the html files, besides the java file,
* resource
resource code are under "lucene_source_home/demo/src/resources/org/apache/lucene/demo/xmlparser/",
copy "index.jsp & stylesheet.css & WEB-INF" into "WebContent/" of eclipse project,
* issue fix
* open web.xml
change:
org.apache.lucene.xmlparser.webdemo.FormBasedXmlQueryDemo
to:
org.apache.lucene.demo.xmlparser.FormBasedXmlQueryDemo
*
*
* run
run project from eclipse via tomcat,
* query
* first, don't enter anything in the "description" field,
it will show all the result,
* then, input some keyword(e.g. Java) in the "description" field,
query again,
* plus, you can also choose other fields(e.g. Locations) as conditions,
*
*
* ok
*
data resource:
data file:
data.tsv
format:
all lines have the same format,
each line has several columns contain different type of data, and could be used as condition,
------
下一篇: 面试官:请说一下对象锁和类锁的区别
推荐阅读
-
QT Demo 之 calqlatr(2) calqlatr.qml
-
Zend Framework实现具有基本功能的留言本(附demo源码下载)_PHP
-
微信支付 NATIVE 扫码 PHP SDK 查询订单 官方 Demo 是不是有问题
-
求个mysql插入100万条数据的demo
-
PHP结合Ajax实现登录验证的Demo
-
Component 和 PureComponent 的区别;复制demo,肉眼可以的区别
-
C#编写了一个基于Lucene.Net的搜索引擎查询通用工具类:SearchEngineUtil
-
Js实现京东无延迟菜单效果实例(demo)
-
javascript - 小程序解决方案的Demo
-
JS 小demo之新建文件夹的实例教程