Modified lastmodified field to use DateTools instead of the deprecated DateField, and added an antlib.xml file to make Ant integration easier

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@384336 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2006-03-08 21:32:04 +00:00
parent d07f7eea12
commit 04ca37fb49
3 changed files with 21 additions and 5 deletions

View File

@ -15,5 +15,11 @@
refid="additional.dependencies" refid="additional.dependencies"
/> />
<target name="compile-core" depends="common.compile-core">
<copy todir="${build.dir}/classes/java">
<fileset dir="src/java" includes="**/*.xml"/>
</copy>
</target>
<import file="../contrib-build.xml"/> <import file="../contrib-build.xml"/>
</project> </project>

View File

@ -21,9 +21,9 @@ import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.analysis.SimpleAnalyzer; import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.analysis.WhitespaceAnalyzer; import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.DateField;
import org.apache.lucene.document.Document; import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field; import org.apache.lucene.document.Field;
import org.apache.lucene.document.DateTools;
import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
import org.apache.lucene.search.Hits; import org.apache.lucene.search.Hits;
@ -46,6 +46,7 @@ import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.util.Set; import java.util.Set;
import java.util.ArrayList; import java.util.ArrayList;
import java.text.ParseException;
/** /**
* Ant task to index files with Lucene * Ant task to index files with Lucene
@ -302,8 +303,13 @@ public class IndexTask extends Task {
String indexModified = String indexModified =
doc.get("modified").trim(); doc.get("modified").trim();
if (indexModified != null) { if (indexModified != null) {
if (DateField.stringToTime(indexModified) long lastModified = 0;
== file.lastModified()) { try {
lastModified = DateTools.stringToTime(indexModified);
} catch (ParseException e) {
// if modified time is not parsable, skip
}
if (lastModified == file.lastModified()) {
// TODO: remove existing document // TODO: remove existing document
indexIt = false; indexIt = false;
} }
@ -328,7 +334,7 @@ public class IndexTask extends Task {
// 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 a
// Keyword field, so that it's searchable, but so that no attempt is made // Keyword field, so that it's searchable, but so that no attempt is made
// to tokenize the field into words. // to tokenize the field into words.
doc.add(new Field("modified", DateField.timeToString(file.lastModified()), Field.Store.YES, Field.Index.UN_TOKENIZED)); doc.add(new Field("modified", DateTools.timeToString(file.lastModified(), DateTools.Resolution.MILLISECOND), Field.Store.YES, Field.Index.UN_TOKENIZED));
writer.addDocument(doc); writer.addDocument(doc);
totalIndexed++; totalIndexed++;

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<antlib>
<taskdef name="index" classname="org.apache.lucene.ant.IndexTask"/>
</antlib>