I've always wanted to take some time. System of learning under Lucene, today the Lucene source learning environment to build a bit. The following describes the environment construction process.
Configuration of the development environment (lucene-4.10.2 + Eclipse):
1: Download the latest Source: The jar package lucene-4.10.2, and Java source code lucene-4.10.2-src are downloaded.
: http://mirror.bit.edu.cn/apache/lucene/java/4.10.2/
2: Install lucene-4.10.2 Java source code in eclipse.
Create a new Java project and remove the "Use default location check". Select the source file directory.
There are many error prompts when the project is loaded, because there are still a lot of dependent packages that are not referenced.
Workaround, copy the jar package lucene-4.10.2 the jar package under the Lib file under each folder.
Build a Lib folder in the project. Copy the jar package so that it comes up. Then, add the jar package to the build path. There are so many bags.
Lucene-4.10.2-src\lucene-4.10.2\demo\src\java\org\apache\lucene\demo This directory has two simple instances, which are indexed and queried.
Create a new Java project and add a lucene-4.10.2 reference to the build project.
Below you can try to write the demo.
Here is an example of a built index:
PackageIndex.demo;ImportJava.io.File;Importjava.io.IOException;ImportJava.util.*;ImportOrg.apache.lucene.analysis.Analyzer;ImportOrg.apache.lucene.analysis.standard.StandardAnalyzer;Importorg.apache.lucene.document.Document;ImportOrg.apache.lucene.document.Field;ImportOrg.apache.lucene.document.LongField;ImportOrg.apache.lucene.document.StringField;ImportOrg.apache.lucene.index.IndexWriter;ImportOrg.apache.lucene.index.IndexWriterConfig;ImportOrg.apache.lucene.index.IndexWriterConfig.OpenMode;Importorg.apache.lucene.store.Directory;Importorg.apache.lucene.store.FSDirectory;Importorg.apache.lucene.util.Version;Importindex.bean.*;/** * @authorZHANGRH Index Building class*/ Public classIndexbuilder {PrivateIndexbuilder () {}/*** Indexing Initialization*/ Public Static voidInitindex () {Try{String Indexpath= "D://lucene/index"; Directory dir= Fsdirectory.open (NewFile (Indexpath)); Analyzer Analyzer=NewStandardAnalyzer (); Indexwriterconfig IWC=NewIndexwriterconfig (version.lucene_4_10_2, analyzer); Iwc.setopenmode (openmode.create); IndexWriter writer=NewIndexWriter (dir, IWC); ArrayList<Hotel> hotellist =Getcontentdata (); if(Hotellist! =NULL) { for(Hotel h:hotellist) {Document doc=NewDocument (); Longfield IDfield=NewLongfield ("id", H.getid (), Field.Store.YES); Doc.add (IDfield); Field Namecnfield=NewStringfield ("name", H.GETNAMECN (), Field.Store.YES); Doc.add (Namecnfield); Field Nameenfield=NewStringfield ("ename", H.getnameen (), Field.Store.YES); Doc.add (Nameenfield); Writer.adddocument (DOC); }} writer.close (); } Catch(IOException e) {//TODO Auto-generated catch blockE.printstacktrace (); } } /*** Return {@linkHotel} content Data * *@returnAn ArrayList of Hotel*/ Private StaticArraylistGetcontentdata () {ArrayList<Hotel> list =NewArraylist(); returnlist; }}
Official API Description: http://lucene.apache.org/core/4_10_2/index.html
One of Lucene Learning: building the source environment