cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject git commit: CXF-5549: Introduce Tika Search Visitor. Enhanced date/timestamp handling implementation.
Date Mon, 30 Jun 2014 13:58:57 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 16cff265e -> d607b8cd8


CXF-5549: Introduce Tika Search Visitor. Enhanced date/timestamp handling implementation.


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/d607b8cd
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/d607b8cd
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/d607b8cd

Branch: refs/heads/master
Commit: d607b8cd828a7f9226746639fce82cc084231555
Parents: 16cff26
Author: reta <drreta@gmail.com>
Authored: Mon Jun 30 09:58:46 2014 -0400
Committer: reta <drreta@gmail.com>
Committed: Mon Jun 30 09:58:46 2014 -0400

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/ext/search/SearchUtils.java   | 10 ++++++++--
 .../ext/search/lucene/LuceneQueryVisitor.java      | 17 ++++++++---------
 .../tika/TikaLuceneContentExtractorTest.java       |  8 +++++++-
 3 files changed, 23 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/d607b8cd/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
index c85d9cb..a5f6128 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
@@ -30,6 +30,8 @@ import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.jaxrs.ext.search.sql.SQLPrinterVisitor;
 
 public final class SearchUtils {
+    public static final String TIMESTAMP_WITH_TIMEZONE = "yyyy-MM-dd'T'HH:mm:ss";
+    public static final String TIMESTAMP = "yyyy-MM-dd'T'HH:mm:ssZ";
     public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
     public static final String DATE_FORMAT_PROPERTY = "search.date-format";
     public static final String TIMEZONE_SUPPORT_PROPERTY = "search.timezone.support";
@@ -150,10 +152,14 @@ public final class SearchUtils {
     }
     
     public static Date timestampFromString(final String value) {
-        Date date = timestampFromString(value, "yyyy-MM-dd'T'HH:mm:ssZ");
+        Date date = timestampFromString(value, TIMESTAMP);
         
         if (date == null) {
-            date = timestampFromString(value, "yyyy-MM-dd'T'HH:mm:ss");
+            date = timestampFromString(value, TIMESTAMP_WITH_TIMEZONE);
+        }
+        
+        if (date == null) {
+            date = timestampFromString(value, DEFAULT_DATE_FORMAT);
         }
         
         return date;

http://git-wip-us.apache.org/repos/asf/cxf/blob/d607b8cd/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
index 2d2f16b..e485380 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
@@ -183,8 +183,11 @@ public class LuceneQueryVisitor<T> extends AbstractSearchConditionVisitor<T,
Que
         return fieldName;
     }
     
-    private Query createRangeQuery(Class<?> cls, String name, Object value,
-                                   ConditionType type) {
+    private Query createRangeQuery(Class<?> cls, String name, Object value, ConditionType
type) {
+        
+        boolean minInclusive = type == ConditionType.GREATER_OR_EQUALS || type == ConditionType.EQUALS;
+        boolean maxInclusive = type == ConditionType.LESS_OR_EQUALS || type == ConditionType.EQUALS;
+        
         if (String.class.isAssignableFrom(cls) || Number.class.isAssignableFrom(cls)) {
             // If needed, long and double can be supported too
             // Also, perhaps Strings may optionally be compared with string comparators 
@@ -192,10 +195,6 @@ public class LuceneQueryVisitor<T> extends AbstractSearchConditionVisitor<T,
Que
             Integer min = type == ConditionType.LESS_THAN || type == ConditionType.LESS_OR_EQUALS
? null : intValue;
             Integer max = type == ConditionType.GREATER_THAN || type == ConditionType.GREATER_OR_EQUALS

                 ? null : intValue;
-            boolean minInclusive = 
-                type == ConditionType.GREATER_OR_EQUALS || type == ConditionType.EQUALS;
-            boolean maxInclusive =
-                type == ConditionType.LESS_OR_EQUALS || type == ConditionType.EQUALS;
             Query query = NumericRangeQuery.newIntRange(name, min, max, 
                                                         minInclusive, maxInclusive);
             return query;
@@ -206,11 +205,11 @@ public class LuceneQueryVisitor<T> extends AbstractSearchConditionVisitor<T,
Que
             final String luceneDateValue = (date != null) 
                 ? DateTools.dateToString(date, Resolution.MILLISECOND) : value.toString();
                 
-            if (type == ConditionType.LESS_THAN) {
-                return TermRangeQuery.newStringRange(name, "", luceneDateValue, true, false);
+            if (type == ConditionType.LESS_THAN || type == ConditionType.LESS_OR_EQUALS)
{
+                return TermRangeQuery.newStringRange(name, "", luceneDateValue, minInclusive,
maxInclusive);
             } else {
                 return TermRangeQuery.newStringRange(name, luceneDateValue, 
-                    DateTools.dateToString(new Date(), Resolution.MILLISECOND), true, false);
+                    DateTools.dateToString(new Date(), Resolution.MILLISECOND), minInclusive,
maxInclusive);
             }
         } else {
             return null;

http://git-wip-us.apache.org/repos/asf/cxf/blob/d607b8cd/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractorTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractorTest.java
b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractorTest.java
index 0fbede1..5574806 100644
--- a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractorTest.java
+++ b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractorTest.java
@@ -80,7 +80,7 @@ public class TikaLuceneContentExtractorTest extends Assert {
     }
 
     @Test
-    public void testExtractedTextContentMatchesTypesAndSearchCriteria() throws Exception
{
+    public void testExtractedTextContentMatchesTypesAndDateSearchCriteria() throws Exception
{
         final LuceneDocumentMetadata documentMetadata = new LuceneDocumentMetadata("contents")
             .withField("modified", Date.class);
         
@@ -92,6 +92,12 @@ public class TikaLuceneContentExtractorTest extends Assert {
         writer.commit();
 
         assertEquals(1, getHits("modified=gt=2007-09-14T09:02:31", documentMetadata.getFieldTypes()).length);
+        assertEquals(1, getHits("modified=le=2007-09-15T09:02:31", documentMetadata.getFieldTypes()).length);
+        assertEquals(1, getHits("modified=ge=2007-09-15", documentMetadata.getFieldTypes()).length);
+        assertEquals(1, getHits("modified==2007-09-15", documentMetadata.getFieldTypes()).length);
+        assertEquals(0, getHits("modified==2007-09-16", documentMetadata.getFieldTypes()).length);
+        assertEquals(0, getHits("modified=gt=2007-09-16", documentMetadata.getFieldTypes()).length);
+        assertEquals(0, getHits("modified=lt=2007-09-15", documentMetadata.getFieldTypes()).length);
         assertEquals(0, getHits("modified=gt=2007-09-16T09:02:31", documentMetadata.getFieldTypes()).length);
         assertEquals(0, getHits("modified=lt=2007-09-01T09:02:31", documentMetadata.getFieldTypes()).length);
     }


Mime
View raw message