incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [2/2] git commit: Fixed BLUR-288
Date Thu, 24 Oct 2013 19:18:31 GMT
Fixed BLUR-288


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/6f6b9b73
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/6f6b9b73
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/6f6b9b73

Branch: refs/heads/master
Commit: 6f6b9b733e4e01c983291719478325e6a4695d08
Parents: 11796bf
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Thu Oct 24 15:17:37 2013 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Thu Oct 24 15:18:27 2013 -0400

----------------------------------------------------------------------
 .../apache/blur/analysis/BaseFieldManager.java  | 10 +++++++++
 .../org/apache/blur/analysis/FieldManager.java  | 10 +++++++++
 .../blur/analysis/FieldTypeDefinition.java      |  2 ++
 .../type/CustomFieldTypeDefinition.java         | 11 ++++++++++
 .../type/FieldLessFieldTypeDefinition.java      |  5 +++++
 .../type/NumericFieldTypeDefinition.java        |  7 ++++++-
 .../type/StoredFieldTypeDefinition.java         |  5 +++++
 .../type/StringFieldTypeDefinition.java         | 11 +++++++---
 .../analysis/type/TextFieldTypeDefinition.java  |  5 +++++
 .../blur/lucene/search/BlurQueryParser.java     | 22 +++++++++++++++++---
 10 files changed, 81 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6f6b9b73/blur-query/src/main/java/org/apache/blur/analysis/BaseFieldManager.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/analysis/BaseFieldManager.java b/blur-query/src/main/java/org/apache/blur/analysis/BaseFieldManager.java
index 56e2e53..36e4202 100644
--- a/blur-query/src/main/java/org/apache/blur/analysis/BaseFieldManager.java
+++ b/blur-query/src/main/java/org/apache/blur/analysis/BaseFieldManager.java
@@ -545,6 +545,16 @@ public abstract class BaseFieldManager extends FieldManager {
     }
     return fieldTypeDefinition.checkSupportForWildcardQuery();
   }
+  
+  @Override
+  public Boolean checkSupportForRegexQuery(String field) throws IOException {
+    FieldTypeDefinition fieldTypeDefinition = getFieldTypeDefinition(field);
+    if (fieldTypeDefinition == null) {
+      return null;
+    }
+    return fieldTypeDefinition.checkSupportForRegexQuery();
+  }
+
 
   @Override
   public Boolean checkSupportForCustomQuery(String field) throws IOException {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6f6b9b73/blur-query/src/main/java/org/apache/blur/analysis/FieldManager.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/analysis/FieldManager.java b/blur-query/src/main/java/org/apache/blur/analysis/FieldManager.java
index b8cc592..52b4062 100644
--- a/blur-query/src/main/java/org/apache/blur/analysis/FieldManager.java
+++ b/blur-query/src/main/java/org/apache/blur/analysis/FieldManager.java
@@ -130,6 +130,16 @@ public abstract class FieldManager {
    * @throws IOException
    */
   public abstract Boolean checkSupportForWildcardQuery(String field) throws IOException;
+  
+  /**
+   * Checks if this field supports regex queries.
+   * 
+   * @param field
+   *          the field name.
+   * @return Boolean null if unknown.
+   * @throws IOException
+   */
+  public abstract Boolean checkSupportForRegexQuery(String field) throws IOException;
 
   /**
    * Checks to see if the field will deal with creating it's own query objects.

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6f6b9b73/blur-query/src/main/java/org/apache/blur/analysis/FieldTypeDefinition.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/analysis/FieldTypeDefinition.java b/blur-query/src/main/java/org/apache/blur/analysis/FieldTypeDefinition.java
index 9898ff2..d92c246 100644
--- a/blur-query/src/main/java/org/apache/blur/analysis/FieldTypeDefinition.java
+++ b/blur-query/src/main/java/org/apache/blur/analysis/FieldTypeDefinition.java
@@ -165,6 +165,8 @@ public abstract class FieldTypeDefinition {
   public abstract boolean checkSupportForWildcardQuery();
 
   public abstract boolean checkSupportForPrefixQuery();
+  
+  public abstract boolean checkSupportForRegexQuery();
 
   public abstract boolean isNumeric();
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6f6b9b73/blur-query/src/main/java/org/apache/blur/analysis/type/CustomFieldTypeDefinition.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/CustomFieldTypeDefinition.java
b/blur-query/src/main/java/org/apache/blur/analysis/type/CustomFieldTypeDefinition.java
index d098b86..7e3ecf2 100644
--- a/blur-query/src/main/java/org/apache/blur/analysis/type/CustomFieldTypeDefinition.java
+++ b/blur-query/src/main/java/org/apache/blur/analysis/type/CustomFieldTypeDefinition.java
@@ -20,6 +20,7 @@ import org.apache.blur.analysis.FieldTypeDefinition;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.core.KeywordAnalyzer;
 import org.apache.lucene.index.IndexableField;
+import org.apache.lucene.sandbox.queries.regex.RegexQuery;
 import org.apache.lucene.search.FuzzyQuery;
 import org.apache.lucene.search.PrefixQuery;
 import org.apache.lucene.search.Query;
@@ -86,6 +87,16 @@ public abstract class CustomFieldTypeDefinition extends FieldTypeDefinition
{
   public final boolean checkSupportForPrefixQuery() {
     return false;
   }
+  
+  /**
+   * Custom query types do not support {@link RegexQuery}.
+   * 
+   * @return false.
+   */
+  @Override
+  public final boolean checkSupportForRegexQuery() {
+    return false;
+  }
 
   /**
    * Checks whether this type is numeric or not. If so you need this type to be

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6f6b9b73/blur-query/src/main/java/org/apache/blur/analysis/type/FieldLessFieldTypeDefinition.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/FieldLessFieldTypeDefinition.java
b/blur-query/src/main/java/org/apache/blur/analysis/type/FieldLessFieldTypeDefinition.java
index 3d76e72..6225160 100644
--- a/blur-query/src/main/java/org/apache/blur/analysis/type/FieldLessFieldTypeDefinition.java
+++ b/blur-query/src/main/java/org/apache/blur/analysis/type/FieldLessFieldTypeDefinition.java
@@ -88,6 +88,11 @@ public class FieldLessFieldTypeDefinition extends FieldTypeDefinition {
   }
 
   @Override
+  public boolean checkSupportForRegexQuery() {
+    return true;
+  }
+
+  @Override
   public boolean isNumeric() {
     return false;
   }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6f6b9b73/blur-query/src/main/java/org/apache/blur/analysis/type/NumericFieldTypeDefinition.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/NumericFieldTypeDefinition.java
b/blur-query/src/main/java/org/apache/blur/analysis/type/NumericFieldTypeDefinition.java
index 008cf5f..eaac400 100644
--- a/blur-query/src/main/java/org/apache/blur/analysis/type/NumericFieldTypeDefinition.java
+++ b/blur-query/src/main/java/org/apache/blur/analysis/type/NumericFieldTypeDefinition.java
@@ -25,7 +25,7 @@ import org.apache.lucene.util.NumericUtils;
 public abstract class NumericFieldTypeDefinition extends FieldTypeDefinition {
 
   protected static final String NUMERIC_PRECISION_STEP = "numericPrecisionStep";
-  
+
   protected static final String MAX = "max";
   protected static final String MIN = "min";
 
@@ -58,6 +58,11 @@ public abstract class NumericFieldTypeDefinition extends FieldTypeDefinition
{
   }
 
   @Override
+  public final boolean checkSupportForRegexQuery() {
+    return false;
+  }
+
+  @Override
   public final boolean isNumeric() {
     return true;
   }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6f6b9b73/blur-query/src/main/java/org/apache/blur/analysis/type/StoredFieldTypeDefinition.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/StoredFieldTypeDefinition.java
b/blur-query/src/main/java/org/apache/blur/analysis/type/StoredFieldTypeDefinition.java
index 0f40d79..f6f4b80 100644
--- a/blur-query/src/main/java/org/apache/blur/analysis/type/StoredFieldTypeDefinition.java
+++ b/blur-query/src/main/java/org/apache/blur/analysis/type/StoredFieldTypeDefinition.java
@@ -78,6 +78,11 @@ public class StoredFieldTypeDefinition extends FieldTypeDefinition {
   public boolean checkSupportForPrefixQuery() {
     return false;
   }
+  
+  @Override
+  public boolean checkSupportForRegexQuery() {
+    return false;
+  }
 
   @Override
   public boolean isNumeric() {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6f6b9b73/blur-query/src/main/java/org/apache/blur/analysis/type/StringFieldTypeDefinition.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/StringFieldTypeDefinition.java
b/blur-query/src/main/java/org/apache/blur/analysis/type/StringFieldTypeDefinition.java
index 8791905..6dac261 100644
--- a/blur-query/src/main/java/org/apache/blur/analysis/type/StringFieldTypeDefinition.java
+++ b/blur-query/src/main/java/org/apache/blur/analysis/type/StringFieldTypeDefinition.java
@@ -67,17 +67,17 @@ public class StringFieldTypeDefinition extends FieldTypeDefinition {
 
   @Override
   public boolean checkSupportForFuzzyQuery() {
-    return false;
+    return true;
   }
 
   @Override
   public boolean checkSupportForWildcardQuery() {
-    return false;
+    return true;
   }
 
   @Override
   public boolean checkSupportForPrefixQuery() {
-    return false;
+    return true;
   }
 
   @Override
@@ -89,4 +89,9 @@ public class StringFieldTypeDefinition extends FieldTypeDefinition {
   public boolean checkSupportForCustomQuery() {
     return false;
   }
+  
+  @Override
+  public boolean checkSupportForRegexQuery() {
+    return true;
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6f6b9b73/blur-query/src/main/java/org/apache/blur/analysis/type/TextFieldTypeDefinition.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/TextFieldTypeDefinition.java
b/blur-query/src/main/java/org/apache/blur/analysis/type/TextFieldTypeDefinition.java
index dd1a515..6b40101 100644
--- a/blur-query/src/main/java/org/apache/blur/analysis/type/TextFieldTypeDefinition.java
+++ b/blur-query/src/main/java/org/apache/blur/analysis/type/TextFieldTypeDefinition.java
@@ -114,6 +114,11 @@ public class TextFieldTypeDefinition extends FieldTypeDefinition {
   public boolean checkSupportForPrefixQuery() {
     return true;
   }
+  
+  @Override
+  public boolean checkSupportForRegexQuery() {
+    return true;
+  }
 
   @Override
   public boolean isNumeric() {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6f6b9b73/blur-query/src/main/java/org/apache/blur/lucene/search/BlurQueryParser.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/lucene/search/BlurQueryParser.java b/blur-query/src/main/java/org/apache/blur/lucene/search/BlurQueryParser.java
index 9666cc9..2a04772 100644
--- a/blur-query/src/main/java/org/apache/blur/lucene/search/BlurQueryParser.java
+++ b/blur-query/src/main/java/org/apache/blur/lucene/search/BlurQueryParser.java
@@ -91,7 +91,7 @@ public class BlurQueryParser extends QueryParser {
       }
     };
   }
-  
+
   @Override
   protected Query newPrefixQuery(Term prefix) {
     String field = prefix.field();
@@ -126,7 +126,7 @@ public class BlurQueryParser extends QueryParser {
   private void customQueryCheck(String field) {
     try {
       Boolean b = _fieldManager.checkSupportForCustomQuery(field);
-      if (b !=null && b) {
+      if (b != null && b) {
         throw new RuntimeException("Field [" + field + "] is type [" + _fieldManager.getFieldTypeDefinition(field)
             + "] queries should exist with \" around them.");
       }
@@ -152,7 +152,7 @@ public class BlurQueryParser extends QueryParser {
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
-    
+
     if (q != null) {
       return addField(q, field);
     }
@@ -178,6 +178,22 @@ public class BlurQueryParser extends QueryParser {
     return addField(super.newWildcardQuery(t), t.field());
   }
 
+  @Override
+  protected Query newRegexpQuery(Term t) {
+    String field = t.field();
+    try {
+      Boolean b = _fieldManager.checkSupportForRegexQuery(field);
+      if (!(b == null || b)) {
+        throw new RuntimeException("Field [" + field + "] is type [" + _fieldManager.getFieldTypeDefinition(field)
+            + "] which does not support wildcard queries.");
+      }
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+    customQueryCheck(field);
+    return addField(super.newRegexpQuery(t), t.field());
+  }
+
   private Query addField(Query q, String field) {
     _fieldNames.put(q, field);
     return q;


Mime
View raw message