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,

------

猜你喜欢

转载自kuchaguangjie.iteye.com/blog/1984565