Recently contacted Lucene, I think there are a lot of people have heard, so with curiosity, I began to understand Lucene, to me the most influential is that it has a lot of application of the Index table, the tool is fast because a large number of references to the index table. Today I just started to do a calendar example, create an index.
The following is a conceptual introduction to Lucene, Lucene is a library of information retrieval functions that you can use to index and search your application. Lucene users do not need to learn more about Full-text search, just learn to use a class in the library, and you can implement Full-text search for your application. But don't think Lucene is a search engine like Google, Lucene isn't even an application, It's just a tool, a library. You can also think of it as a very good set of Easy-to-use APIs that encapsulate the index and search functionality. With this API you can do a lot of things about search, and it's very convenient.
So what can lucene do? Lucene can index and search any data. Lucene can be analyzed and utilized by Lucene, regardless of the format of the data source, as long as it can be translated into the form of text. That is, whether it's MS Word, Html, PDF or some other form of file as long as you can extract the text form of content can be used by Lucene. You can index and search them in Lucene. Here's a small example of what I do, which is an example of a query that generates an index:
<span style= "FONT-SIZE:14PX;"
>package Com.jikexueyuan.study;
Import Java.io.File;
Import java.io.IOException;
Import Org.apache.lucene.analysis.Analyzer;
Import Org.apache.lucene.analysis.standard.StandardAnalyzer;
Import org.apache.lucene.document.Document;
Import Org.apache.lucene.document.IntField;
Import Org.apache.lucene.document.Field.Store;
Import Org.apache.lucene.document.StringField;
Import Org.apache.lucene.index.IndexWriter;
Import Org.apache.lucene.index.IndexWriterConfig;
Import Org.apache.lucene.index.IndexWriterConfig.OpenMode;
Import Org.apache.lucene.store.Directory;
Import Org.apache.lucene.store.FSDirectory;
Import org.apache.lucene.util.Version; public class Indexcreate {/** * @param args */public static void main (string[] args) {//TODO auto-generated m Ethod stub Analyzer analyzer=new standardanalyzer (version.lucene_46),//standardanalyzer is the English according to the blanks, punctuation, and so on participle, The Chinese word according to a single word, a Chinese character indexwriterconfig indexwriterconfig=new indexwriterconfig (Version.
Lucene_46,analyzer);//write the file with the specified word breaker to the article participle (so that the search can be checked quickly), and then put the word into the index file.
Indexwriterconfig.setopenmode (Openmode.create_or_append);
Directory Directory=null;
IndexWriter Indexwriter=null; try {directory=fsdirectory.open (new file ("E://index/test"))///Index inventory is placed in this folder, directory represents the location where the index file is saved, is an abstract class,
The two subclass Fsdirectory represents a file in which the ramdirectory representation is stored in memory if (indexwriter.islocked (directory)) {Indexwriter.unlock (directory);
} indexwriter=new IndexWriter (directory,indexwriterconfig);
catch (Exception e) {e.printstacktrace ();
//document document=new Document ();
Document doc = new document ();
Doc.add (New Stringfield ("id", "ABCDE", Store.yes));
Doc.add (New Org.apache.lucene.document.TextField ("Content", "Geek College", Store.yes));
Doc.add (New Intfield ("num", 1,store.yes));
try {indexwriter.adddocument (DOC);//Add Document (Insert)} catch (Exception e) {e.printstacktrace () to the index;
Document Doc1 = new document (); Doc1.add (New Stringfield ("id", "SDFSD", Store.YES));
Doc1.add (New Org.apache.lucene.document.TextField ("Content", "Lucene case", Store.yes));
Doc1.add (New Intfield ("num", 1,store.yes));
try {indexwriter.adddocument (Doc1);
catch (Exception e) {e.printstacktrace ();
try {indexwriter.commit ();
Indexwriter.close ();
Directory.close ();
catch (Exception e) {//TODO auto-generated catch block E.printstacktrace (); }} </span>
The result generates a series of files about the index, as shown in the following figure:
From the example above, we can see that the three elements needed to create an index are:
1, IndexWriter
2. Directory
3, Anayzer
4. Document
5. Field
For the sharing of Lucene to continue, I hope that more and more people can work together.