Apache Lucene open-source search software
Modified lastmodified field to use DateTools instead of the deprecated DateField, and added an antlib.xml file to make Ant integration easier
Erik Hatcher04ca37fb49df
diff --git a/contrib/ant/build.xml b/contrib/ant/build.xmlindex 4a0b4e749fd..e0fc1ec7b34 100644--- a/contrib/ant/build.xml+++ b/contrib/ant/build.xml@@ -15,5 +15,11 @@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"/></project>diff --git a/contrib/ant/src/java/org/apache/lucene/ant/IndexTask.java b/contrib/ant/src/java/org/apache/lucene/ant/IndexTask.javaindex 02dcac6d712..1ca8dc9b3c9 100644--- a/contrib/ant/src/java/org/apache/lucene/ant/IndexTask.java+++ b/contrib/ant/src/java/org/apache/lucene/ant/IndexTask.java@@ -21,9 +21,9 @@ import org.apache.lucene.analysis.StopAnalyzer;import org.apache.lucene.analysis.SimpleAnalyzer;import org.apache.lucene.analysis.WhitespaceAnalyzer;import org.apache.lucene.analysis.standard.StandardAnalyzer;-import org.apache.lucene.document.DateField;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;+import org.apache.lucene.document.DateTools;import org.apache.lucene.index.IndexWriter;import org.apache.lucene.index.Term;import org.apache.lucene.search.Hits;@@ -46,6 +46,7 @@ import java.util.Map;import java.util.HashMap;import java.util.Set;import java.util.ArrayList;+import java.text.ParseException;/*** Ant task to index files with Lucene@@ -139,7 +140,7 @@ public class IndexTask extends Task {/*** If creating a new index and this is set to true, the* index will be created in compound format.- */+ */public void setUseCompoundIndex(boolean useCompoundIndex) {this.useCompoundIndex = useCompoundIndex;}@@ -302,8 +303,13 @@ public class IndexTask extends Task {String indexModified =doc.get("modified").trim();if (indexModified != null) {- if (DateField.stringToTime(indexModified)- == file.lastModified()) {+ long lastModified = 0;+ try {+ lastModified = DateTools.stringToTime(indexModified);+ } catch (ParseException e) {+ // if modified time is not parsable, skip+ }+ if (lastModified == file.lastModified()) {// TODO: remove existing documentindexIt = false;}@@ -328,7 +334,7 @@ public class IndexTask extends Task {// 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// 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);totalIndexed++;diff --git a/contrib/ant/src/java/org/apache/lucene/ant/antlib.xml b/contrib/ant/src/java/org/apache/lucene/ant/antlib.xmlnew file mode 100644index 00000000000..1dd8a9bae59--- /dev/null+++ b/contrib/ant/src/java/org/apache/lucene/ant/antlib.xml@@ -0,0 +1,4 @@+<?xml version="1.0"?>+<antlib>+ <taskdef name="index" classname="org.apache.lucene.ant.IndexTask"/>+</antlib>