blob: 0edaa6e75b7eeb0e5b7869db196cfab33f321d74 [file] [log] [blame]
<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Lucene.Net | Apache Lucene.NET 4.8.0-beta00013 Documentation </title>
<meta name="viewport" content="width=device-width">
<meta name="title" content="Lucene.Net | Apache Lucene.NET 4.8.0-beta00013 Documentation ">
<meta name="generator" content="docfx 2.56.2.0">
<link rel="shortcut icon" href="https://lucenenet.apache.org/docs/4.8.0-beta00009/logo/favicon.ico">
<link rel="stylesheet" href="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/docfx.vendor.css">
<link rel="stylesheet" href="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/docfx.css">
<link rel="stylesheet" href="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/main.css">
<meta property="docfx:navrel" content="toc.html">
<meta property="docfx:tocrel" content="core/toc.html">
<meta property="docfx:rel" content="https://lucenenet.apache.org/docs/4.8.0-beta00009/">
</head>
<body data-spy="scroll" data-target="#affix" data-offset="120">
<span id="forkongithub"><a href="https://github.com/apache/lucenenet" target="_blank">Fork me on GitHub</a></span>
<div id="wrapper">
<header>
<nav id="autocollapse" class="navbar ng-scope" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">
<img id="logo" class="svg" src="https://lucenenet.apache.org/docs/4.8.0-beta00009/logo/lucene-net-color.png" alt="">
</a>
</div>
<div class="collapse navbar-collapse" id="navbar">
<form class="navbar-form navbar-right" role="search" id="search">
<div class="form-group">
<input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off">
</div>
</form>
</div>
</div>
</nav>
<div class="subnav navbar navbar-default">
<div class="container hide-when-search">
<ul class="level0 breadcrumb">
<li>
<a href="https://lucenenet.apache.org/docs/4.8.0-beta00009/">API</a>
<span id="breadcrumb">
<ul class="breadcrumb">
<li></li>
</ul>
</span>
</li>
</ul>
</div>
</div>
</header>
<div class="container body-content">
<div id="search-results">
<div class="search-list"></div>
<div class="sr-items">
<p><i class="glyphicon glyphicon-refresh index-loading"></i></p>
</div>
<ul id="pagination"></ul>
</div>
</div>
<div role="main" class="container body-content hide-when-search">
<div class="sidenav hide-when-search">
<a class="btn toc-toggle collapse" data-toggle="collapse" href="#sidetoggle" aria-expanded="false" aria-controls="sidetoggle">Show / Hide Table of Contents</a>
<div class="sidetoggle collapse" id="sidetoggle">
<div id="sidetoc"></div>
</div>
</div>
<div class="article row grid-right">
<div class="col-md-10">
<article class="content wrap" id="_content" data-uid="Lucene.Net">
<h1 id="" data-uid="Lucene.Net" class="text-break">Lucene.Net</h1>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>Apache Lucene is a high-performance, full-featured text search engine library. Here&#39;s a simple example how to use Lucene for indexing and searching (using JUnit to check if the results are what we expect):</p>
<!-- = Java2Html Converter 5.0 [2006-03-04] by Markus Gebhard markus@jave.de = -->
<pre><code> 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(&quot;/tmp/testindex&quot;);
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_CURRENT, analyzer);
IndexWriter iwriter = new IndexWriter(directory, config);
Document doc = new Document();
String text = &quot;This is the text to be indexed.&quot;;
doc.add(new Field(&quot;fieldname&quot;, text, TextField.TYPE_STORED));
iwriter.addDocument(doc);
iwriter.close();
// Now search the index:
DirectoryReader ireader = DirectoryReader.open(directory);
IndexSearcher isearcher = new IndexSearcher(ireader);
// Parse a simple query that searches for &quot;text&quot;:
QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, &quot;fieldname&quot;, analyzer);
Query query = parser.parse(&quot;text&quot;);
ScoreDoc[] hits = isearcher.search(query, null, 1000).scoreDocs;
assertEquals(1, hits.length);
// Iterate through the results:
for (int i = 0; i &lt; hits.length;=&quot;&quot; i++)=&quot;&quot; {=&quot;&quot; document=&quot;&quot; hitdoc=&quot;isearcher.doc(hits[i].doc);&quot; assertequals(&quot;this=&quot;&quot; is=&quot;&quot; the=&quot;&quot; text=&quot;&quot; to=&quot;&quot; be=&quot;&quot; indexed.&quot;,=&quot;&quot; hitdoc.get(&quot;fieldname&quot;));=&quot;&quot; }=&quot;&quot; ireader.close();=&quot;&quot;&gt;
</code></pre><p>The Lucene API is divided into several packages:</p>
<ul>
<li><p><strong><a class="xref" href="Lucene.Net.Analysis.html">Lucene.Net.Analysis</a></strong>
defines an abstract <a class="xref" href="Lucene.Net.Analysis.Analyzer.html">Analyzer</a>
API for converting text from a {@link java.io.Reader}
into a <a class="xref" href="Lucene.Net.Analysis.TokenStream.html">TokenStream</a>,
an enumeration of token <a class="xref" href="Lucene.Net.Util.Attribute.html">Attribute</a>s.
A TokenStream can be composed by applying <a class="xref" href="Lucene.Net.Analysis.TokenFilter.html">TokenFilter</a>s
to the output of a <a class="xref" href="Lucene.Net.Analysis.Tokenizer.html">Tokenizer</a>.
Tokenizers and TokenFilters are strung together and applied with an <a class="xref" href="Lucene.Net.Analysis.Analyzer.html">Analyzer</a>.
<a href="../analyzers-common/overview-summary.html">analyzers-common</a> provides a number of Analyzer implementations, including
<a href="../analyzers-common/org/apache/lucene/analysis/core/StopAnalyzer.html">StopAnalyzer</a>
and the grammar-based <a href="../analyzers-common/org/apache/lucene/analysis/standard/StandardAnalyzer.html">StandardAnalyzer</a>.</p>
</li>
<li><p><strong><a class="xref" href="Lucene.Net.Codecs.html">Lucene.Net.Codecs</a></strong>
provides an abstraction over the encoding and decoding of the inverted index structure,
as well as different implementations that can be chosen depending upon application needs.</p>
</li>
<li><p><strong><a class="xref" href="Lucene.Net.Documents.html">Lucene.Net.Documents</a></strong>
provides a simple <a class="xref" href="Lucene.Net.Documents.Document.html">Document</a>
class. A Document is simply a set of named <a class="xref" href="Lucene.Net.Documents.Field.html">Field</a>s,
whose values may be strings or instances of {@link java.io.Reader}.</p>
</li>
<li><p><strong><a class="xref" href="Lucene.Net.Index.html">Lucene.Net.Index</a></strong>
provides two primary classes: <a class="xref" href="Lucene.Net.Index.IndexWriter.html">IndexWriter</a>,
which creates and adds documents to indices; and <a class="xref" href="Lucene.Net.Index.IndexReader.html">IndexReader</a>,
which accesses the data in the index.</p>
</li>
<li><p><strong><a class="xref" href="Lucene.Net.Search.html">Lucene.Net.Search</a></strong>
provides data structures to represent queries (ie <a class="xref" href="Lucene.Net.Search.TermQuery.html">TermQuery</a>
for individual words, <a class="xref" href="Lucene.Net.Search.PhraseQuery.html">PhraseQuery</a>
for phrases, and <a class="xref" href="Lucene.Net.Search.BooleanQuery.html">BooleanQuery</a>
for boolean combinations of queries) and the <a class="xref" href="Lucene.Net.Search.IndexSearcher.html">IndexSearcher</a>
which turns queries into <a class="xref" href="Lucene.Net.Search.TopDocs.html">TopDocs</a>.
A number of <a href="../queryparser/overview-summary.html">QueryParser</a>s are provided for producing
query structures from strings or xml.</p>
</li>
<li><p><strong><a class="xref" href="Lucene.Net.Store.html">Lucene.Net.Store</a></strong>
defines an abstract class for storing persistent data, the <a class="xref" href="Lucene.Net.Store.Directory.html">Directory</a>,
which is a collection of named files written by an <a class="xref" href="Lucene.Net.Store.IndexOutput.html">IndexOutput</a>
and read by an <a class="xref" href="Lucene.Net.Store.IndexInput.html">IndexInput</a>.
Multiple implementations are provided, including <a class="xref" href="Lucene.Net.Store.FSDirectory.html">FSDirectory</a>,
which uses a file system directory to store files, and <a class="xref" href="Lucene.Net.Store.RAMDirectory.html">RAMDirectory</a>
which implements files as memory-resident data structures.</p>
</li>
<li><p><strong><a class="xref" href="Lucene.Net.Util.html">Lucene.Net.Util</a></strong>
contains a few handy data structures and util classes, ie <a class="xref" href="Lucene.Net.Util.OpenBitSet.html">OpenBitSet</a>
and <a href="xref:Lucene.Net.Util.PriorityQueue">PriorityQueue</a>.</p>
</li>
</ul>
<p>To use Lucene, an application should:</p>
<ol>
<li><p>Create <a class="xref" href="Lucene.Net.Documents.Document.html">Document</a>s by
adding
<a class="xref" href="Lucene.Net.Documents.Field.html">Field</a>s;</p>
</li>
<li><p>Create an <a class="xref" href="Lucene.Net.Index.IndexWriter.html">IndexWriter</a>
and add documents to it with <a class="xref" href="Lucene.Net.Index.IndexWriter.html#methods">AddDocument</a>;</p>
</li>
<li><p>Call <a href="../queryparser/org/apache/lucene/queryparser/classic/QueryParserBase.html#parse(java.lang.String)">QueryParser.parse()</a>
to build a query from a string; and</p>
</li>
<li><p>Create an <a class="xref" href="Lucene.Net.Search.IndexSearcher.html">IndexSearcher</a>
and pass the query to its <a class="xref" href="Lucene.Net.Search.IndexSearcher.html#methods">Search</a>
method.</p>
</li>
</ol>
<p>Some simple examples of code which does this are:</p>
<ul>
<li><p><a href="../demo/src-html/org/apache/lucene/demo/IndexFiles.html">IndexFiles.java</a> creates an
index for all the files contained in a directory.</p>
</li>
<li><p><a href="../demo/src-html/org/apache/lucene/demo/SearchFiles.html">SearchFiles.java</a> prompts for
queries and searches an index.</p>
</li>
</ul>
</article>
</div>
<div class="hidden-sm col-md-2" role="complementary">
<div class="sideaffix">
<div class="contribution">
<ul class="nav">
<li>
<a href="https://github.com/apache/lucenenet/blob/docs/4.8.0-beta00013/src/Lucene.Net/overview.md/#L1" class="contribution-link">Improve this Doc</a>
</li>
</ul>
</div>
<nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
<!-- <p><a class="back-to-top" href="#top">Back to top</a><p> -->
</nav>
</div>
</div>
</div>
</div>
<footer>
<div class="grad-bottom"></div>
<div class="footer">
<div class="container">
<span class="pull-right">
<a href="#top">Back to top</a>
</span>
Copyright © 2020 The Apache Software Foundation, Licensed under the <a href='http://www.apache.org/licenses/LICENSE-2.0' target='_blank'>Apache License, Version 2.0</a><br> <small>Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation. <br>All other marks mentioned may be trademarks or registered trademarks of their respective owners.</small>
</div>
</div>
</footer>
</div>
<script type="text/javascript" src="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/docfx.vendor.js"></script>
<script type="text/javascript" src="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/docfx.js"></script>
<script type="text/javascript" src="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/main.js"></script>
</body>
</html>