You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2015/04/26 14:18:11 UTC

lucenenet git commit: make sure to invoke appropriate CompareValues via FieldComparator

Repository: lucenenet
Updated Branches:
  refs/heads/master fdda2059b -> 38139379b


make sure to invoke appropriate CompareValues via FieldComparator


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

Branch: refs/heads/master
Commit: 38139379ba44e582b014fe8a5817779fa112be0a
Parents: fdda205
Author: Laimonas Simutis <la...@gmail.com>
Authored: Sun Apr 26 07:32:17 2015 -0400
Committer: Laimonas Simutis <la...@gmail.com>
Committed: Sun Apr 26 07:32:17 2015 -0400

----------------------------------------------------------------------
 src/Lucene.Net.Core/Search/FieldComparator.cs        | 15 +++++++++------
 src/Lucene.Net.Core/Search/FieldDoc.cs               |  6 +++---
 .../core/Search/TestElevationComparator.cs           |  5 +++++
 3 files changed, 17 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/38139379/src/Lucene.Net.Core/Search/FieldComparator.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Search/FieldComparator.cs b/src/Lucene.Net.Core/Search/FieldComparator.cs
index 32bf9f0..5eb1933 100644
--- a/src/Lucene.Net.Core/Search/FieldComparator.cs
+++ b/src/Lucene.Net.Core/Search/FieldComparator.cs
@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Generic;
 using System.Diagnostics;
 
 namespace Lucene.Net.Search
@@ -199,15 +200,22 @@ namespace Lucene.Net.Search
             }
             else
             {
-                return ((IComparable<T>)first).CompareTo(second);
+                return Comparer<T>.Default.Compare(first, second);
             }
         }
+
+        public override int CompareValues(object first, object second)
+        {
+            return CompareValues((T)first, (T)second);
+        }
     }
 
     // .NET Port: Using a non-generic class here so that we avoid having to use the
     // type parameter to access these nested types. Also moving non-generic methods here for casting without generics.
     public abstract class FieldComparator
     {
+        public abstract int CompareValues(object first, object second);
+
         //Set up abstract methods
         /// <summary>
         /// Compare hit at slot1 with hit at slot2.
@@ -313,11 +321,6 @@ namespace Lucene.Net.Search
         /// <returns> value in this slot </returns>
         public abstract IComparable Value(int slot);
 
-        public int CompareValues(IComparable first, IComparable second)
-        {
-            return (first).CompareTo(second);
-        }
-
         /// <summary>
         /// Base FieldComparator class for numeric types
         /// </summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/38139379/src/Lucene.Net.Core/Search/FieldDoc.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Search/FieldDoc.cs b/src/Lucene.Net.Core/Search/FieldDoc.cs
index 8f7a4ea..e7d942b 100644
--- a/src/Lucene.Net.Core/Search/FieldDoc.cs
+++ b/src/Lucene.Net.Core/Search/FieldDoc.cs
@@ -49,7 +49,7 @@ namespace Lucene.Net.Search
         /// FieldComparator used to sort this field. </summary>
         /// <seealso cref= Sort </seealso>
         /// <seealso cref= IndexSearcher#search(Query,Filter,int,Sort) </seealso>
-        public IComparable[] Fields;
+        public Object[] Fields;
 
         /// <summary>
         /// Expert: Creates one of these objects with empty sort information. </summary>
@@ -60,7 +60,7 @@ namespace Lucene.Net.Search
 
         /// <summary>
         /// Expert: Creates one of these objects with the given sort information. </summary>
-        public FieldDoc(int doc, float score, IComparable[] fields)
+        public FieldDoc(int doc, float score, Object[] fields)
             : base(doc, score)
         {
             this.Fields = fields;
@@ -68,7 +68,7 @@ namespace Lucene.Net.Search
 
         /// <summary>
         /// Expert: Creates one of these objects with the given sort information. </summary>
-        public FieldDoc(int doc, float score, IComparable[] fields, int shardIndex)
+        public FieldDoc(int doc, float score, Object[] fields, int shardIndex)
             : base(doc, score, shardIndex)
         {
             this.Fields = fields;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/38139379/src/Lucene.Net.Tests/core/Search/TestElevationComparator.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestElevationComparator.cs b/src/Lucene.Net.Tests/core/Search/TestElevationComparator.cs
index c42295a..6e2d617 100644
--- a/src/Lucene.Net.Tests/core/Search/TestElevationComparator.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestElevationComparator.cs
@@ -170,6 +170,11 @@ namespace Lucene.Net.Search
             private readonly BytesRef tempBR;
             internal int bottomVal;
 
+            public override int CompareValues(object first, object second)
+            {
+                return ((IComparable) first).CompareTo(second);
+            }
+
             public override int Compare(int slot1, int slot2)
             {
                 return values[slot2] - values[slot1]; // values will be small enough that there is no overflow concern