|
||||||||||
| PREV NEXT | FRAMES NO FRAMES | |||||||||
See:
Description
| Packages | |
|---|---|
| org.apache.lucene | Top-level package. |
| org.apache.lucene.analysis | API and code to convert text into indexable/searchable tokens. |
| org.apache.lucene.analysis.standard | The org.apache.lucene.analysis.standard package contains three
fast grammar-based tokenizers constructed with JFlex: |
| org.apache.lucene.analysis.standard.std31 | |
| org.apache.lucene.analysis.tokenattributes | |
| org.apache.lucene.collation |
CollationKeyFilter
converts each token into its binary CollationKey using the
provided Collator, and then encode the CollationKey
as a String using
IndexableBinaryStringTools, to allow it to be
stored as an index term. |
| org.apache.lucene.document | The logical representation of a Document for indexing and searching. |
| org.apache.lucene.index | Code to maintain and access indices. |
| org.apache.lucene.messages | For Native Language Support (NLS), system of software internationalization. |
| org.apache.lucene.queryParser | A simple query parser implemented with JavaCC. |
| org.apache.lucene.search | Code to search indices. |
| org.apache.lucene.search.function |
Programmatic control over documents scores. |
| org.apache.lucene.search.payloads | The payloads package provides Query mechanisms for finding and using payloads. |
| org.apache.lucene.search.spans | The calculus of spans. |
| org.apache.lucene.store | Binary i/o API, used for all index data. |
| org.apache.lucene.util | Some utility classes. |
| org.apache.lucene.util.fst | Finite state transducers |
Apache Lucene is a high-performance, full-featured text search engine library. Here's a simple example how to use Lucene for indexing and searching (using JUnit to check if the results are what we expect):
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
// Store the index in memory:
Directory directory = new RAMDirectory();
// To store an index on disk, use this instead:
//Directory directory = FSDirectory.open("/tmp/testindex");
IndexWriter iwriter = new IndexWriter(directory, analyzer, true,
new IndexWriter.MaxFieldLength(25000));
Document doc = new Document();
String text = "This is the text to be indexed.";
doc.add(new Field("fieldname", text, Field.Store.YES,
Field.Index.ANALYZED));
iwriter.addDocument(doc);
iwriter.close();
// Now search the index:
IndexSearcher isearcher = new IndexSearcher(directory, true); // read-only=true
// Parse a simple query that searches for "text":
QueryParser parser = new QueryParser("fieldname", analyzer);
Query query = parser.parse("text");
ScoreDoc[] hits = isearcher.search(query, null, 1000).scoreDocs;
assertEquals(1, hits.length);
// Iterate through the results:
for (int i = 0; i < hits.length; i++) {
Document hitDoc = isearcher.doc(hits[i].doc);
assertEquals("This is the text to be indexed.", hitDoc.get("fieldname"));
}
isearcher.close();
directory.close();
The Lucene API is divided into several packages:
> java -cp lucene.jar:lucene-demo.jar:lucene-analyzers-common.jar org.apache.lucene.demo.IndexFiles rec.food.recipes/soups
adding rec.food.recipes/soups/abalone-chowder
[ ... ]> java -cp lucene.jar:lucene-demo.jar:lucene-analyzers-common.jar org.apache.lucene.demo.SearchFiles
Query: chowder
Searching for: chowder
34 total matching documents
1. rec.food.recipes/soups/spam-chowder
[ ... thirty-four documents contain the word "chowder" ... ]Query: "clam chowder" AND Manhattan
Searching for: +"clam chowder" +manhattan
2 total matching documents
1. rec.food.recipes/soups/clam-chowder
[ ... two documents contain the phrase "clam chowder" and the word "manhattan" ... ]
[ Note: "+" and "-" are canonical, but "AND", "OR" and "NOT" may be used. ]
|
||||||||||
| PREV NEXT | FRAMES NO FRAMES | |||||||||