mirror of https://github.com/apache/lucene.git
update TestDemo code (match overview.html, they were out of whack, plus use non deprecated code)
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@807755 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
52bffef75b
commit
caa67be375
|
@ -27,7 +27,7 @@ to check if the results are what we expect):</p>
|
|||
<!-- code comes from org.apache.lucene.TestDemo: -->
|
||||
<!-- ======================================================== -->
|
||||
<!-- = Java Sourcecode to HTML automatically converted code = -->
|
||||
<!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = -->
|
||||
<!-- = Java2Html Converter 5.0 [2006-03-04] by Markus Gebhard markus@jave.de = -->
|
||||
<!-- = Further information: http://www.java2html.de = -->
|
||||
<div align="left" class="java">
|
||||
<table border="0" cellpadding="3" cellspacing="0" bgcolor="#ffffff">
|
||||
|
@ -35,7 +35,7 @@ to check if the results are what we expect):</p>
|
|||
<!-- start source code -->
|
||||
<td nowrap="nowrap" valign="top" align="left">
|
||||
<code>
|
||||
<font color="#ffffff"> </font><font color="#000000">Analyzer analyzer = </font><font color="#7f0055"><b>new </b></font><font color="#000000">StandardAnalyzer</font><font color="#000000">()</font><font color="#000000">;</font><br />
|
||||
<font color="#ffffff"> </font><font color="#000000">Analyzer analyzer = </font><font color="#7f0055"><b>new </b></font><font color="#000000">StandardAnalyzer</font><font color="#000000">(</font><font color="#000000">Version.LUCENE_CURRENT</font><font color="#000000">)</font><font color="#000000">;</font><br />
|
||||
<font color="#ffffff"></font><br />
|
||||
<font color="#ffffff"> </font><font color="#3f7f5f">// Store the index in memory:</font><br />
|
||||
<font color="#ffffff"> </font><font color="#000000">Directory directory = </font><font color="#7f0055"><b>new </b></font><font color="#000000">RAMDirectory</font><font color="#000000">()</font><font color="#000000">;</font><br />
|
||||
|
@ -51,7 +51,7 @@ to check if the results are what we expect):</p>
|
|||
<font color="#ffffff"> </font><font color="#000000">iwriter.close</font><font color="#000000">()</font><font color="#000000">;</font><br />
|
||||
<font color="#ffffff"> </font><br />
|
||||
<font color="#ffffff"> </font><font color="#3f7f5f">// Now search the index:</font><br />
|
||||
<font color="#ffffff"> </font><font color="#000000">IndexSearcher isearcher = </font><font color="#7f0055"><b>new </b></font><font color="#000000">IndexSearcher</font><font color="#000000">(</font><font color="#000000">directory</font><font color="#000000">)</font><font color="#000000">;</font><br />
|
||||
<font color="#ffffff"> </font><font color="#000000">IndexSearcher isearcher = </font><font color="#7f0055"><b>new </b></font><font color="#000000">IndexSearcher</font><font color="#000000">(</font><font color="#000000">directory, </font><font color="#7f0055"><b>true</b></font><font color="#000000">)</font><font color="#000000">; </font><font color="#3f7f5f">// read-only=true</font><br />
|
||||
<font color="#ffffff"> </font><font color="#3f7f5f">// Parse a simple query that searches for "text":</font><br />
|
||||
<font color="#ffffff"> </font><font color="#000000">QueryParser parser = </font><font color="#7f0055"><b>new </b></font><font color="#000000">QueryParser</font><font color="#000000">(</font><font color="#2a00ff">"fieldname"</font><font color="#000000">, analyzer</font><font color="#000000">)</font><font color="#000000">;</font><br />
|
||||
<font color="#ffffff"> </font><font color="#000000">Query query = parser.parse</font><font color="#000000">(</font><font color="#2a00ff">"text"</font><font color="#000000">)</font><font color="#000000">;</font><br />
|
||||
|
@ -68,12 +68,14 @@ to check if the results are what we expect):</p>
|
|||
</td>
|
||||
<!-- end source code -->
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
<!-- = END of automatically generated HTML code = -->
|
||||
<!-- ======================================================== -->
|
||||
|
||||
|
||||
|
||||
<p>The Lucene API is divided into several packages:</p>
|
||||
|
||||
<ul>
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.apache.lucene.search.ScoreDoc;
|
|||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.RAMDirectory;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util.Version;
|
||||
import org.apache.lucene.util._TestUtil;
|
||||
|
||||
/**
|
||||
|
@ -44,12 +45,12 @@ public class TestDemo extends LuceneTestCase {
|
|||
|
||||
public void testDemo() throws IOException, ParseException {
|
||||
|
||||
Analyzer analyzer = new StandardAnalyzer();
|
||||
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(new File("/tmp/testindex"));
|
||||
//Directory directory = FSDirectory.open("/tmp/testindex");
|
||||
IndexWriter iwriter = new IndexWriter(directory, analyzer, true,
|
||||
new IndexWriter.MaxFieldLength(25000));
|
||||
Document doc = new Document();
|
||||
|
@ -59,10 +60,8 @@ public class TestDemo extends LuceneTestCase {
|
|||
iwriter.addDocument(doc);
|
||||
iwriter.close();
|
||||
|
||||
_TestUtil.checkIndex(directory);
|
||||
|
||||
// Now search the index:
|
||||
IndexSearcher isearcher = new IndexSearcher(directory);
|
||||
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");
|
||||
|
|
Loading…
Reference in New Issue