You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2017/03/17 22:28:43 UTC
[13/33] lucenenet git commit: Lucene.Net.Core.Documents.NumericType
refactor: Added NONE option and refactored all types that use NumericType to
use NONE instead of null.
Lucene.Net.Core.Documents.NumericType refactor: Added NONE option and refactored all types that use NumericType to use NONE instead of null.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/021f5577
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/021f5577
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/021f5577
Branch: refs/heads/api-work
Commit: 021f55775223af281feaa04380c0f16a34828776
Parents: 0169d4a
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Fri Mar 17 08:29:42 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Fri Mar 17 08:29:42 2017 +0700
----------------------------------------------------------------------
src/Lucene.Net.Core/Document/DoubleField.cs | 4 ++--
src/Lucene.Net.Core/Document/Field.cs | 6 +++---
src/Lucene.Net.Core/Document/FieldType.cs | 16 ++++++++++++----
src/Lucene.Net.Core/Document/FloatField.cs | 4 ++--
src/Lucene.Net.Core/Document/IntField.cs | 4 ++--
src/Lucene.Net.Core/Document/LongField.cs | 4 ++--
src/Lucene.Net.Core/Index/IndexableFieldType.cs | 2 --
.../Standard/Nodes/NumericRangeQueryNode.cs | 10 +++++-----
src/Lucene.Net.TestFramework/Util/TestUtil.cs | 4 ++--
.../Flexible/Standard/TestNumericQueryParser.cs | 20 ++++++++++++++++++++
10 files changed, 50 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/021f5577/src/Lucene.Net.Core/Document/DoubleField.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Document/DoubleField.cs b/src/Lucene.Net.Core/Document/DoubleField.cs
index 5aaf2aa..bb4171c 100644
--- a/src/Lucene.Net.Core/Document/DoubleField.cs
+++ b/src/Lucene.Net.Core/Document/DoubleField.cs
@@ -163,13 +163,13 @@ namespace Lucene.Net.Documents
/// <param name="type"> customized field type: must have <see cref="FieldType.NumericType"/>
/// of <see cref="NumericType.DOUBLE"/>. </param>
/// <exception cref="ArgumentNullException"> if the field name or type is <c>null</c>, or
- /// if the field type does not have a DOUBLE <see cref="FieldType.NumericType"/> </exception>
+ /// if the field type does not have a <see cref="NumericType.DOUBLE"/> <see cref="FieldType.NumericType"/> </exception>
public DoubleField(string name, double value, FieldType type)
: base(name, type)
{
if (type.NumericType != NumericType.DOUBLE)
{
- throw new System.ArgumentException("type.numericType() must be DOUBLE but got " + type.NumericType);
+ throw new System.ArgumentException("type.NumericType must be NumericType.DOUBLE but got " + type.NumericType);
}
m_fieldsData = Convert.ToDouble(value);
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/021f5577/src/Lucene.Net.Core/Document/Field.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Document/Field.cs b/src/Lucene.Net.Core/Document/Field.cs
index 72a778c..1fca651 100644
--- a/src/Lucene.Net.Core/Document/Field.cs
+++ b/src/Lucene.Net.Core/Document/Field.cs
@@ -476,7 +476,7 @@ namespace Lucene.Net.Documents
{
throw new System.ArgumentException("TokenStream fields must be indexed and tokenized");
}
- if (m_type.NumericType != null)
+ if (m_type.NumericType != NumericType.NONE)
{
throw new System.ArgumentException("cannot set private TokenStream on numeric fields");
}
@@ -576,8 +576,8 @@ namespace Lucene.Net.Documents
{
return null;
}
- NumericType? numericType = ((FieldType)FieldType).NumericType;
- if (numericType != null)
+ NumericType numericType = ((FieldType)FieldType).NumericType;
+ if (numericType != NumericType.NONE)
{
if (!(internalTokenStream is NumericTokenStream))
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/021f5577/src/Lucene.Net.Core/Document/FieldType.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Document/FieldType.cs b/src/Lucene.Net.Core/Document/FieldType.cs
index f12696e..4211e7d 100644
--- a/src/Lucene.Net.Core/Document/FieldType.cs
+++ b/src/Lucene.Net.Core/Document/FieldType.cs
@@ -38,7 +38,7 @@ namespace Lucene.Net.Documents
private bool storeTermVectorPayloads;
private bool omitNorms;
private IndexOptions indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
- private NumericType? numericType;
+ private NumericType numericType;
private bool frozen;
private int numericPrecisionStep = NumericUtils.PRECISION_STEP_DEFAULT;
private DocValuesType docValueType;
@@ -255,7 +255,7 @@ namespace Lucene.Net.Documents
/// </summary>
/// <exception cref="InvalidOperationException"> if this <see cref="FieldType"/> is frozen against
/// future modifications. </exception>
- public virtual NumericType? NumericType
+ public virtual NumericType NumericType
{
get
{
@@ -271,7 +271,7 @@ namespace Lucene.Net.Documents
/// <summary>
/// Sets the numeric precision step for the field.
/// <para/>
- /// This has no effect if <see cref="NumericType"/> returns <c>null</c>.
+ /// This has no effect if <see cref="NumericType"/> returns <see cref="NumericType.NONE"/>.
/// <para/>
/// The default is <see cref="NumericUtils.PRECISION_STEP_DEFAULT"/>.
/// </summary>
@@ -341,7 +341,7 @@ namespace Lucene.Net.Documents
// LUCENENET: duplcate what would happen if you print a null indexOptions in Java
result.Append(indexOptions != IndexOptions.NONE ? indexOptions.ToString() : string.Empty);
}
- if (numericType != null)
+ if (numericType != NumericType.NONE)
{
result.Append(",numericType=");
result.Append(numericType);
@@ -391,6 +391,14 @@ namespace Lucene.Net.Documents
public enum NumericType
{
/// <summary>
+ /// No numeric type will be used.
+ /// <para/>
+ /// NOTE: This is the same as setting to <c>null</c> in Lucene
+ /// </summary>
+ // LUCENENET specific
+ NONE,
+
+ /// <summary>
/// 32-bit integer numeric type
/// <para/>
/// NOTE: This was INT in Lucene
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/021f5577/src/Lucene.Net.Core/Document/FloatField.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Document/FloatField.cs b/src/Lucene.Net.Core/Document/FloatField.cs
index 6490eea..cc2c7d6 100644
--- a/src/Lucene.Net.Core/Document/FloatField.cs
+++ b/src/Lucene.Net.Core/Document/FloatField.cs
@@ -166,14 +166,14 @@ namespace Lucene.Net.Documents
/// <param name="value"> 32-bit <see cref="float"/> value </param>
/// <param name="type"> customized field type: must have <see cref="FieldType.NumericType"/>
/// of <see cref="NumericType.SINGLE"/>. </param>
- /// <exception cref="ArgumentNullException"> if the field <paramref name="name"/> or <paramref name="type"/> is <c>null</c> </exception>
+ /// <exception cref="ArgumentNullException"> if the field <paramref name="name"/> or <paramref name="type"/> is <see cref="NumericType.NONE"/> </exception>
/// <exception cref="ArgumentException">if the field type does not have a <see cref="NumericType.SINGLE"/> <see cref="FieldType.NumericType"/></exception>
public SingleField(string name, float value, FieldType type)
: base(name, type)
{
if (type.NumericType != NumericType.SINGLE)
{
- throw new System.ArgumentException("type.NumericType must be NumericType.Single but got " + type.NumericType);
+ throw new System.ArgumentException("type.NumericType must be NumericType.SINGLE but got " + type.NumericType);
}
m_fieldsData = Convert.ToSingle(value);
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/021f5577/src/Lucene.Net.Core/Document/IntField.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Document/IntField.cs b/src/Lucene.Net.Core/Document/IntField.cs
index 422de1b..7d78855 100644
--- a/src/Lucene.Net.Core/Document/IntField.cs
+++ b/src/Lucene.Net.Core/Document/IntField.cs
@@ -166,7 +166,7 @@ namespace Lucene.Net.Documents
/// <param name="value"> 32-bit <see cref="int"/> value </param>
/// <param name="type"> customized field type: must have <see cref="FieldType.NumericType"/>
/// of <see cref="NumericType.INT32"/>. </param>
- /// <exception cref="ArgumentNullException"> if the field <paramref name="name"/> or <paramref name="type"/> is <c>null</c> </exception>
+ /// <exception cref="ArgumentNullException"> if the field <paramref name="name"/> or <paramref name="type"/> is <see cref="NumericType.NONE"/> </exception>
/// <exception cref="ArgumentException">if the field type does not have a
/// <see cref="FieldType.NumericType"/> of <see cref="NumericType.INT32"/> </exception>
public Int32Field(string name, int value, FieldType type)
@@ -174,7 +174,7 @@ namespace Lucene.Net.Documents
{
if (type.NumericType != NumericType.INT32)
{
- throw new System.ArgumentException("type.NumericType must be INT but got " + type.NumericType);
+ throw new System.ArgumentException("type.NumericType must be NumericType.INT32 but got " + type.NumericType);
}
m_fieldsData = Convert.ToInt32(value);
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/021f5577/src/Lucene.Net.Core/Document/LongField.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Document/LongField.cs b/src/Lucene.Net.Core/Document/LongField.cs
index b11aff1..7163bb7 100644
--- a/src/Lucene.Net.Core/Document/LongField.cs
+++ b/src/Lucene.Net.Core/Document/LongField.cs
@@ -176,7 +176,7 @@ namespace Lucene.Net.Documents
/// <param name="value"> 64-bit <see cref="long"/> value </param>
/// <param name="type"> customized field type: must have <see cref="FieldType.NumericType"/>
/// of <see cref="NumericType.INT64"/>. </param>
- /// <exception cref="ArgumentNullException"> if the field <paramref name="name"/> or <paramref name="type"/> is <c>null</c> </exception>
+ /// <exception cref="ArgumentNullException"> if the field <paramref name="name"/> or <paramref name="type"/> is <see cref="NumericType.NONE"/> </exception>
/// <exception cref="ArgumentException"> if the field type does not have a
/// <see cref="FieldType.NumericType"/> of <see cref="NumericType.INT64"/> </exception>
public Int64Field(string name, long value, FieldType type)
@@ -184,7 +184,7 @@ namespace Lucene.Net.Documents
{
if (type.NumericType != NumericType.INT64)
{
- throw new System.ArgumentException("type.numericType() must be LONG but got " + type.NumericType);
+ throw new System.ArgumentException("type.NumericType must be NumericType.INT64 but got " + type.NumericType);
}
m_fieldsData = Convert.ToInt64(value);
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/021f5577/src/Lucene.Net.Core/Index/IndexableFieldType.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/IndexableFieldType.cs b/src/Lucene.Net.Core/Index/IndexableFieldType.cs
index e87f192..e61cbde 100644
--- a/src/Lucene.Net.Core/Index/IndexableFieldType.cs
+++ b/src/Lucene.Net.Core/Index/IndexableFieldType.cs
@@ -94,8 +94,6 @@ namespace Lucene.Net.Index
/// </summary>
IndexOptions IndexOptions { get; }
- //NumericType? NumericType { get; }
-
/// <summary>
/// DocValues <see cref="DocValuesType"/>: if not <see cref="DocValuesType.NONE"/> then the field's value
/// will be indexed into docValues.
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/021f5577/src/Lucene.Net.QueryParser/Flexible/Standard/Nodes/NumericRangeQueryNode.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Nodes/NumericRangeQueryNode.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Nodes/NumericRangeQueryNode.cs
index 8c2d2bb..1653499 100644
--- a/src/Lucene.Net.QueryParser/Flexible/Standard/Nodes/NumericRangeQueryNode.cs
+++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Nodes/NumericRangeQueryNode.cs
@@ -96,7 +96,7 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Nodes
throw new ArgumentException("numericConfig cannot be null!");
}
- NumericType? lowerNumberType, upperNumberType;
+ NumericType lowerNumberType, upperNumberType;
if (lower != null && lower.Value != null)
{
@@ -104,7 +104,7 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Nodes
}
else
{
- lowerNumberType = null;
+ lowerNumberType = NumericType.NONE;
}
if (upper != null && upper.Value != null)
@@ -113,10 +113,10 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Nodes
}
else
{
- upperNumberType = null;
+ upperNumberType = NumericType.NONE;
}
- if (lowerNumberType != null
+ if (lowerNumberType != NumericType.NONE
&& !lowerNumberType.Equals(numericConfig.Type))
{
throw new ArgumentException(
@@ -124,7 +124,7 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Nodes
+ lowerNumberType + " != " + numericConfig.Type);
}
- if (upperNumberType != null
+ if (upperNumberType != NumericType.NONE
&& !upperNumberType.Equals(numericConfig.Type))
{
throw new ArgumentException(
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/021f5577/src/Lucene.Net.TestFramework/Util/TestUtil.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Util/TestUtil.cs b/src/Lucene.Net.TestFramework/Util/TestUtil.cs
index 2340162..a36d17c 100644
--- a/src/Lucene.Net.TestFramework/Util/TestUtil.cs
+++ b/src/Lucene.Net.TestFramework/Util/TestUtil.cs
@@ -1036,7 +1036,7 @@ namespace Lucene.Net.Util
Field field1 = (Field)f;
Field field2;
DocValuesType dvType = field1.FieldType.DocValueType;
- Documents.NumericType? numType = ((FieldType)field1.FieldType).NumericType;
+ NumericType numType = ((FieldType)field1.FieldType).NumericType;
if (dvType != DocValuesType.NONE)
{
switch (dvType)
@@ -1057,7 +1057,7 @@ namespace Lucene.Net.Util
throw new InvalidOperationException("unknown Type: " + dvType);
}
}
- else if (numType != null)
+ else if (numType != NumericType.NONE)
{
switch (numType)
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/021f5577/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestNumericQueryParser.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestNumericQueryParser.cs b/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestNumericQueryParser.cs
index 83f4a3c..d8d0841 100644
--- a/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestNumericQueryParser.cs
+++ b/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestNumericQueryParser.cs
@@ -197,6 +197,11 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard
foreach (NumericType type in Enum.GetValues(typeof(NumericType)))
{
+ if (type == NumericType.NONE)
+ {
+ continue;
+ }
+
numericConfigMap.Put(type.ToString(), new NumericConfig(PRECISION_STEP,
NUMBER_FORMAT, type));
@@ -437,6 +442,11 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard
foreach (NumericType type in Enum.GetValues(typeof(NumericType)))
{
+ if (type == NumericType.NONE)
+ {
+ continue;
+ }
+
String lowerStr = NumberToString(GetNumberType(lowerType, type.ToString()));
String upperStr = NumberToString(GetNumberType(upperType, type.ToString()));
@@ -501,6 +511,11 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard
foreach (NumericType type in Enum.GetValues(typeof(NumericType)))
{
+ if (type == NumericType.NONE)
+ {
+ continue;
+ }
+
String boundStr = NumberToString(GetNumberType(boundType, type.ToString()));
sb.append("+").append(type.ToString()).append(@operator).append('"').append(boundStr).append('"').append(' ');
@@ -527,6 +542,11 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard
foreach (NumericType type in Enum.GetValues(typeof(NumericType)))
{
+ if (type == NumericType.NONE)
+ {
+ continue;
+ }
+
String numberStr = NumberToString(GetNumberType(numberType, type.ToString()));
sb.append('+').append(type.ToString()).append(":\"").append(numberStr)
.append("\" ");