lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [25/27] lucenenet git commit: Lucene.Net.Codecs/Lucene.Net.Core: Fixed bugs in the GetTerms() method of several codecs that were trying to get a value from a dictionary without first checking whether the key exists. Made the implementations more consiste
Date Thu, 02 Mar 2017 01:11:08 GMT
Lucene.Net.Codecs/Lucene.Net.Core: Fixed bugs in the GetTerms() method of several codecs that
were trying to get a value from a dictionary without first checking whether the key exists.
Made the implementations more consistent between codecs.


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

Branch: refs/heads/api-work
Commit: 8c97a243cf5e745ff8693fc6a362959a8e2d21e3
Parents: eaf01d1
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Thu Mar 2 04:01:29 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Thu Mar 2 08:09:05 2017 +0700

----------------------------------------------------------------------
 .../BlockTerms/BlockTermsReader.cs              |  4 +++-
 .../Bloom/BloomFilteringPostingsFormat.cs       | 14 ++++++++-----
 .../Memory/DirectPostingsFormat.cs              |  4 +++-
 .../Memory/FSTOrdTermsReader.cs                 |  4 +++-
 src/Lucene.Net.Codecs/Memory/FSTTermsReader.cs  |  4 +++-
 .../Memory/MemoryPostingsFormat.cs              |  4 +++-
 .../SimpleText/SimpleTextFieldsReader.cs        | 21 ++++++++++----------
 .../SimpleText/SimpleTextTermVectorsReader.cs   |  4 +++-
 .../Codecs/Lucene3x/Lucene3xFields.cs           |  6 +++---
 .../Codecs/PerField/PerFieldPostingsFormat.cs   |  8 ++++++--
 src/Lucene.Net.Core/Index/MultiFields.cs        |  3 +--
 .../Index/ParallelAtomicReader.cs               |  6 +++---
 .../Codecs/RAMOnly/RAMOnlyPostingsFormat.cs     |  4 +++-
 13 files changed, 54 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8c97a243/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs b/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs
index 9999cf6..c884725 100644
--- a/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs
+++ b/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs
@@ -252,7 +252,9 @@ namespace Lucene.Net.Codecs.BlockTerms
         {
             Debug.Assert(field != null);
 
-            return _fields[field];
+            FieldReader result;
+            _fields.TryGetValue(field, out result);
+            return result;
         }
 
         public override int Count

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8c97a243/src/Lucene.Net.Codecs/Bloom/BloomFilteringPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Bloom/BloomFilteringPostingsFormat.cs b/src/Lucene.Net.Codecs/Bloom/BloomFilteringPostingsFormat.cs
index ad33a0c..463c7a2 100644
--- a/src/Lucene.Net.Codecs/Bloom/BloomFilteringPostingsFormat.cs
+++ b/src/Lucene.Net.Codecs/Bloom/BloomFilteringPostingsFormat.cs
@@ -192,12 +192,16 @@ namespace Lucene.Net.Codecs.Bloom
 
             public override Terms GetTerms(string field)
             {
-                var filter = _bloomsByFieldName[field];
-                if (filter == null)
+                FuzzySet filter;
+                if (!_bloomsByFieldName.TryGetValue(field, out filter) || filter == null)
+                {
                     return _delegateFieldsProducer.GetTerms(field);
-                
-                var result = _delegateFieldsProducer.GetTerms(field);
-                return result == null ? null : new BloomFilteredTerms(result, filter);
+                }
+                else
+                {
+                    var result = _delegateFieldsProducer.GetTerms(field);
+                    return result == null ? null : new BloomFilteredTerms(result, filter);
+                }
             }
 
             public override int Count

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8c97a243/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs b/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs
index 1f10f28..349cab1 100644
--- a/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs
+++ b/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs
@@ -150,7 +150,9 @@ namespace Lucene.Net.Codecs.Memory
 
             public override Terms GetTerms(string field)
             {
-                return fields[field];
+                DirectField result;
+                fields.TryGetValue(field, out result);
+                return result;
             }
 
             public override int Count

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8c97a243/src/Lucene.Net.Codecs/Memory/FSTOrdTermsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/FSTOrdTermsReader.cs b/src/Lucene.Net.Codecs/Memory/FSTOrdTermsReader.cs
index 168e298..ac5633e 100644
--- a/src/Lucene.Net.Codecs/Memory/FSTOrdTermsReader.cs
+++ b/src/Lucene.Net.Codecs/Memory/FSTOrdTermsReader.cs
@@ -163,7 +163,9 @@ namespace Lucene.Net.Codecs.Memory
         public override Terms GetTerms(string field)
         {
             Debug.Assert(field != null);
-            return fields[field];
+            TermsReader result;
+            fields.TryGetValue(field, out result);
+            return result;
         }
 
         public override int Count

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8c97a243/src/Lucene.Net.Codecs/Memory/FSTTermsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/FSTTermsReader.cs b/src/Lucene.Net.Codecs/Memory/FSTTermsReader.cs
index 059a99e..af00287 100644
--- a/src/Lucene.Net.Codecs/Memory/FSTTermsReader.cs
+++ b/src/Lucene.Net.Codecs/Memory/FSTTermsReader.cs
@@ -165,7 +165,9 @@ namespace Lucene.Net.Codecs.Memory
         public override Terms GetTerms(string field)
         {
             Debug.Assert(field != null);
-            return fields[field];
+            TermsReader result;
+            fields.TryGetValue(field, out result);
+            return result;
         }
 
         public override int Count

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8c97a243/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs b/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs
index 70803cf..752e870 100644
--- a/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs
+++ b/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs
@@ -1073,7 +1073,9 @@ namespace Lucene.Net.Codecs.Memory
 
             public override Terms GetTerms(string field)
             {
-                return _fields[field];
+                TermsReader result;
+                _fields.TryGetValue(field, out result);
+                return result;
             }
 
             public override int Count

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8c97a243/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs
index 139a2af..0342ed2 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs
@@ -739,19 +739,20 @@ namespace Lucene.Net.Codecs.SimpleText
             lock (this)
             {
                 SimpleTextTerms terms;
-                if (_termsCache.TryGetValue(field, out terms))
+                if (!_termsCache.TryGetValue(field, out terms) || terms == null)
                 {
-                    return terms;
-                }
-
-                long? fp;
-                if (!_fields.TryGetValue(field, out fp) || !fp.HasValue)
-                {
-                    return null;
+                    long? fp;
+                    if (!_fields.TryGetValue(field, out fp) || !fp.HasValue)
+                    {
+                        return null;
+                    }
+                    else
+                    {
+                        terms = new SimpleTextTerms(this, field, fp.Value, _maxDoc);
+                        _termsCache[field] = terms;
+                    }
                 }
 
-                terms = new SimpleTextTerms(this, field, fp.Value, _maxDoc);
-                _termsCache[field] = (SimpleTextTerms) terms;
                 return terms;
             }
         }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8c97a243/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs
index 900cf42..29fe3d1 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs
@@ -290,7 +290,9 @@ namespace Lucene.Net.Codecs.SimpleText
 
             public override Terms GetTerms(string field)
             {
-                return _fields.ContainsKey(field) ? _fields[field] : null;
+                SimpleTVTerms result;
+                _fields.TryGetValue(field, out result);
+                return result;
             }
 
             public override int Count

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8c97a243/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xFields.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xFields.cs b/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xFields.cs
index 9ea1fdf..3100d1e 100644
--- a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xFields.cs
+++ b/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xFields.cs
@@ -150,9 +150,9 @@ namespace Lucene.Net.Codecs.Lucene3x
 
         public override Terms GetTerms(string field)
         {
-            Terms ret;
-            preTerms.TryGetValue(field, out ret);
-            return ret;
+            Terms result;
+            preTerms.TryGetValue(field, out result);
+            return result;
         }
 
         public override int Count

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8c97a243/src/Lucene.Net.Core/Codecs/PerField/PerFieldPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/PerField/PerFieldPostingsFormat.cs b/src/Lucene.Net.Core/Codecs/PerField/PerFieldPostingsFormat.cs
index 7880ead..d030111 100644
--- a/src/Lucene.Net.Core/Codecs/PerField/PerFieldPostingsFormat.cs
+++ b/src/Lucene.Net.Core/Codecs/PerField/PerFieldPostingsFormat.cs
@@ -239,8 +239,12 @@ namespace Lucene.Net.Codecs.PerField
             public override Terms GetTerms(string field)
             {
                 FieldsProducer fieldsProducer;
-                fields.TryGetValue(field, out fieldsProducer);
-                return fieldsProducer == null ? null : fieldsProducer.GetTerms(field);
+                if (fields.TryGetValue(field, out fieldsProducer) && fieldsProducer
!= null)
+                {
+                    return fieldsProducer.GetTerms(field);
+                }
+                
+                return null;
             }
 
             public override int Count

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8c97a243/src/Lucene.Net.Core/Index/MultiFields.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/MultiFields.cs b/src/Lucene.Net.Core/Index/MultiFields.cs
index 1b0ce69..54be7c4 100644
--- a/src/Lucene.Net.Core/Index/MultiFields.cs
+++ b/src/Lucene.Net.Core/Index/MultiFields.cs
@@ -247,8 +247,7 @@ namespace Lucene.Net.Index
         public override Terms GetTerms(string field)
         {
             Terms result;
-            terms.TryGetValue(field, out result);
-            if (result != null)
+            if (terms.TryGetValue(field, out result) && result != null)
             {
                 return result;
             }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8c97a243/src/Lucene.Net.Core/Index/ParallelAtomicReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/ParallelAtomicReader.cs b/src/Lucene.Net.Core/Index/ParallelAtomicReader.cs
index 3e89924..3206a70 100644
--- a/src/Lucene.Net.Core/Index/ParallelAtomicReader.cs
+++ b/src/Lucene.Net.Core/Index/ParallelAtomicReader.cs
@@ -210,9 +210,9 @@ namespace Lucene.Net.Index
 
             public override Terms GetTerms(string field)
             {
-                Terms ret;
-                fields.TryGetValue(field, out ret);
-                return ret;
+                Terms result;
+                fields.TryGetValue(field, out result);
+                return result;
             }
 
             public override int Count

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8c97a243/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs b/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs
index 1ec6525..8a77fa5 100644
--- a/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs
+++ b/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs
@@ -111,7 +111,9 @@ namespace Lucene.Net.Codecs.RAMOnly
 
             public override Terms GetTerms(string field)
             {
-                return FieldToTerms[field];
+                RAMField result;
+                FieldToTerms.TryGetValue(field, out result);
+                return result;
             }
 
             public override int Count


Mime
View raw message