start using the non-deprecated API

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150478 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Daniel Naber 2004-09-02 21:23:14 +00:00
parent 1bd047313c
commit dcc9f58e24
1 changed files with 11 additions and 12 deletions

View File

@ -47,23 +47,22 @@ public class FileDocument {
// make a new, empty document // make a new, empty document
Document doc = new Document(); Document doc = new Document();
// Add the path of the file as a field named "path". Use a // Add the path of the file as a field named "path". Use a field that is
// Keyword field, so that it's searchable, but so that no attempt is made // indexed (i.e. searchable), but don't tokenize the field into words.
// to tokenize the field into words. doc.add(new Field("path", f.getPath(), Field.Store.YES, Field.Index.UN_TOKENIZED));
doc.add(Field.Keyword("path", f.getPath()));
// Add the last modified date of the file a field named "modified". Use a // Add the last modified date of the file a field named "modified". Use
// Keyword field, so that it's searchable, but so that no attempt is made // a field that is indexed (i.e. searchable), but don't tokenize the field
// to tokenize the field into words. // into words.
doc.add(Field.Keyword("modified", doc.add(new Field("modified", DateField.timeToString(f.lastModified()),
DateField.timeToString(f.lastModified()))); Field.Store.YES, Field.Index.UN_TOKENIZED));
// Add the contents of the file a field named "contents". Use a Text // Add the contents of the file to a field named "contents". Specify a Reader,
// field, specifying a Reader, so that the text of the file is tokenized. // so that the text of the file is tokenized and indexed, but not stored.
// ?? why doesn't FileReader work here ?? // ?? why doesn't FileReader work here ??
FileInputStream is = new FileInputStream(f); FileInputStream is = new FileInputStream(f);
Reader reader = new BufferedReader(new InputStreamReader(is)); Reader reader = new BufferedReader(new InputStreamReader(is));
doc.add(Field.Text("contents", reader)); doc.add(new Field("contents", reader));
// return the document // return the document
return doc; return doc;