Lucene 基本概念

Classes used when indexing document with Lucene:

Document(Field Field Field Field Field...)-->Analyzer-->IndexWriter-->Directory


Core Indexing classes:

IndexWriter类: central component of the indexing process.

Directory类:the location of a Lucene index.

Analyzer类:extracting those tokens out of text that should be indexed and eliminating the rest.

Document类:a collection of fields.

Field类:each document in an index contains one or more named fields.



Core Searching classes:

IndexSearcher类: open an index in a read-only mode.

Directory dir = FSDirectory.open(new File("/tmp/index"));
IndexSearcher searcher = new IndexSearcher(dir);
Query q=new TermQuery(new Term("contents","lucene"));
TopDocs hits = searcher.search(q,10);
searcher.close();
Term类:

Query类:

TermQuery类:

TopDocs类: a simple container of pointers to the top N ranked search results--documents that match a given query.

你可能感兴趣的:(Lucene 基本概念)