

* The ASF licenses this file to You under the Apache License, Version 2.0 * this work for additional information regarding copyright ownership.
#USING APACHE LUCENE SOFTWARE#
* Licensed to the Apache Software Foundation (ASF) under one or more
#USING APACHE LUCENE HOW TO#
The following code shows how to search the indexed files. TermQuery is a query object and we can use it to create many complex It is similar to Field in indexing process.Īn abstract class and contains various utility methods and is the parent of all types of queries. Reads/searches indexes created after indexing process.

The following table lists classes used during searching process. Index for all the files contained in a directory.Searching process is the process to do the searching. Some simple examples of code which does this are: Which implements files as memory-resident data structures.Ĭontains a few handy data structures and util classes, ie OpenBitSetĪnd add documents to it with AddDocument() Which uses a file system directory to store files, and RAMDirectory Multiple implementations are provided, including FSDirectory, Which is a collection of named files written by an IndexOutput Provides data structures to represent queries (ie TermQueryįor boolean combinations of queries) and the IndexSearcherĪ number of QueryParsers are provided for producingĭefines an abstract class for storing persistent data, the Directory, Which creates and adds documents to indices and IndexReader, Provides two primary classes: IndexWriter, Whose values may be strings or instances of.

A Document is simply a set of named Fields, Provides an abstraction over the encoding and decoding of the inverted index structure,Īs well as different implementations that can be chosen depending upon application needs.Ĭlass. provides a number of Analyzer implementations, including Tokenizers and TokenFilters are strung together and applied with an Analyzer. The Lucene API is divided into several packages:ĪPI for converting text from a Ī TokenStream can be composed by applying TokenFilters ScoreDoc hits = isearcher.Search(query, null, 1000).ScoreDocs ĭocument hitDoc = isearcher.Doc(hits.Doc) Īssert.AreEqual("This is the text to be indexed.", hitDoc.Get("fieldname")) QueryParser parser = new QueryParser(LuceneVersion.LUCENE_CURRENT, "fieldname", analyzer) Parse a simple query that searches for "text": IndexSearcher isearcher = new IndexSearcher(ireader) Using DirectoryReader ireader = DirectoryReader.Open(directory) String text = "This is the text to be indexed." ĭoc.Add(new Field("fieldname", text, TextField.TYPE_STORED)) Using IndexWriter iwriter = new IndexWriter(directory, config) IndexWriterConfig config = new IndexWriterConfig(LuceneVersion.LUCENE_CURRENT, analyzer) Directory directory = FSDirectory.Open(indexPath) var indexPath = Path.Combine(basePath, "index") var basePath = Environment.GetFolderPath() Construct a machine-independent path for the index To store an index on disk, use this instead: Here's a simple example how to use Lucene.NET for indexing and searching (using NUnit to check if the results are what we expect): Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT) ĭirectory directory = new RAMDirectory() Apache Lucene.NET is a high-performance, full-featured text search engine library.
