lucene - demo

本文详细介绍了如何使用Lucene进行文档搜索,并通过Web应用实例展示了Lucene在实际场景中的应用。包括从下载源码、配置环境、创建索引到运行搜索流程的完整步骤,以及Lucene Web应用的搭建与运行方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 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,

 

------

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值