mirror of https://github.com/apache/lucene.git
improve the example code a bit
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@526225 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9d7f9911a4
commit
e21ffed782
|
@ -22,10 +22,8 @@ to check if the results are what we expect):</p>
|
|||
<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 />
|
||||
<font color="#ffffff"> </font><font color="#3f7f5f">// To store an index on disk, use this instead (note that the </font><br />
|
||||
<font color="#ffffff"> </font><font color="#3f7f5f">// parameter true will overwrite the index in that directory</font><br />
|
||||
<font color="#ffffff"> </font><font color="#3f7f5f">// if one exists):</font><br />
|
||||
<font color="#ffffff"> </font><font color="#3f7f5f">//Directory directory = FSDirectory.getDirectory("/tmp/testindex", true);</font><br />
|
||||
<font color="#ffffff"> </font><font color="#3f7f5f">// To store an index on disk, use this instead:</font><br />
|
||||
<font color="#ffffff"> </font><font color="#3f7f5f">//Directory directory = FSDirectory.getDirectory("/tmp/testindex");</font><br />
|
||||
<font color="#ffffff"> </font><font color="#000000">IndexWriter iwriter = </font><font color="#7f0055"><b>new </b></font><font color="#000000">IndexWriter</font><font color="#000000">(</font><font color="#000000">directory, analyzer, </font><font color="#7f0055"><b>true</b></font><font color="#000000">)</font><font color="#000000">;</font><br />
|
||||
<font color="#ffffff"> </font><font color="#000000">iwriter.setMaxFieldLength</font><font color="#000000">(</font><font color="#990000">25000</font><font color="#000000">)</font><font color="#000000">;</font><br />
|
||||
<font color="#ffffff"> </font><font color="#000000">Document doc = </font><font color="#7f0055"><b>new </b></font><font color="#000000">Document</font><font color="#000000">()</font><font color="#000000">;</font><br />
|
||||
|
@ -33,6 +31,7 @@ to check if the results are what we expect):</p>
|
|||
<font color="#ffffff"> </font><font color="#000000">doc.add</font><font color="#000000">(</font><font color="#7f0055"><b>new </b></font><font color="#000000">Field</font><font color="#000000">(</font><font color="#2a00ff">"fieldname"</font><font color="#000000">, text, Field.Store.YES,</font><br />
|
||||
<font color="#ffffff"> </font><font color="#000000">Field.Index.TOKENIZED</font><font color="#000000">))</font><font color="#000000">;</font><br />
|
||||
<font color="#ffffff"> </font><font color="#000000">iwriter.addDocument</font><font color="#000000">(</font><font color="#000000">doc</font><font color="#000000">)</font><font color="#000000">;</font><br />
|
||||
<font color="#ffffff"> </font><font color="#000000">iwriter.optimize</font><font color="#000000">()</font><font color="#000000">;</font><br />
|
||||
<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 />
|
||||
|
|
Loading…
Reference in New Issue