LUCENE-1244: don't use hard-coded path in AnalysisTest

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@640741 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2008-03-25 08:35:51 +00:00
parent 8b0b533472
commit 0bd6f8ec04
3 changed files with 15 additions and 6 deletions

View File

@ -18,7 +18,7 @@ package org.apache.lucene.analysis;
*/
import org.apache.lucene.index.Payload;
import org.apache.lucene.index.TermPositions;
import org.apache.lucene.index.TermPositions; // for javadoc
/** A Token is an occurence of a term from the text of a field. It consists of
a term's text, the start and end offset of the term in the text of the field,
@ -226,8 +226,12 @@ public class Token implements Cloneable {
/** Returns the Token's term text.
*
* @deprecated Use {@link #termBuffer()} and {@link
* #termLength()} instead. */
* @deprecated This method now has a performance penalty
* because the text is stored internally in a char[]. If
* possible, use {@link #termBuffer()} and {@link
* #termLength()} directly instead. If you really need a
* String, use <b>new String(token.termBuffer(), 0, token.termLength())</b>
*/
public final String termText() {
if (termText == null && termBuffer != null)
termText = new String(termBuffer, 0, termLength);

View File

@ -18,6 +18,9 @@ package org.apache.lucene.document;
*/
import java.util.*; // for javadoc
import org.apache.lucene.search.Hits; // for javadoc
import org.apache.lucene.search.Searcher; // for javadoc
import org.apache.lucene.index.IndexReader; // for javadoc
/** Documents are the unit of indexing and search.
*

View File

@ -31,15 +31,17 @@ import java.io.InputStreamReader;
import java.util.Date;
class AnalysisTest {
static File tmpFile;
public static void main(String[] args) {
try {
test("This is a test", true);
// FIXME: OG: what's with this hard-coded file name??
test(new File("words.txt"), false);
tmpFile = File.createTempFile("words", ".txt");
test(tmpFile, false);
} catch (Exception e) {
System.out.println(" caught a " + e.getClass() +
"\n with message: " + e.getMessage());
}
tmpFile.deleteOnExit();
}
static void test(File file, boolean verbose)
@ -70,7 +72,7 @@ class AnalysisTest {
int count = 0;
for (Token t = stream.next(); t!=null; t = stream.next()) {
if (verbose) {
System.out.println("Text=" + t.termText()
System.out.println("Text=" + new String(t.termBuffer(), 0, t.termLength())
+ " start=" + t.startOffset()
+ " end=" + t.endOffset());
}