You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by la...@apache.org on 2023/04/13 19:13:47 UTC

[lucenenet] branch master updated: Workaround for virtual call issue for WithinPrefixTreeFilter (#828)

This is an automated email from the ASF dual-hosted git repository.

laimis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git


The following commit(s) were added to refs/heads/master by this push:
     new 50e93fcf4 Workaround for virtual call issue for WithinPrefixTreeFilter (#828)
50e93fcf4 is described below

commit 50e93fcf4ca85089ca12b161dc6e4d076dc34213
Author: Laimonas Simutis <la...@gmail.com>
AuthorDate: Thu Apr 13 12:13:41 2023 -0700

    Workaround for virtual call issue for WithinPrefixTreeFilter (#828)
---
 .../Prefix/WithinPrefixTreeFilter.cs               | 23 +++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/Lucene.Net.Spatial/Prefix/WithinPrefixTreeFilter.cs b/src/Lucene.Net.Spatial/Prefix/WithinPrefixTreeFilter.cs
index ca882222e..2a14c3c6f 100644
--- a/src/Lucene.Net.Spatial/Prefix/WithinPrefixTreeFilter.cs
+++ b/src/Lucene.Net.Spatial/Prefix/WithinPrefixTreeFilter.cs
@@ -8,6 +8,7 @@ using Spatial4n.Distance;
 using Spatial4n.Shapes;
 using System;
 using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
 using System.IO;
 
 namespace Lucene.Net.Spatial.Prefix
@@ -50,7 +51,8 @@ namespace Lucene.Net.Spatial.Prefix
         //  minimal query buffer by looking in a DocValues cache holding a representative
         //  point of each disjoint component of a document's shape(s).
 
-        private readonly IShape? bufferedQueryShape;//if null then the whole world
+        // LUCENENET specific - made protected to allow subclasses to access if needed
+        protected readonly IShape? m_bufferedQueryShape;//if null then the whole world
 
         /// <summary>
         /// See <see cref="AbstractVisitingPrefixTreeFilter(IShape, string, SpatialPrefixTree, int, int)"/>.
@@ -58,20 +60,31 @@ namespace Lucene.Net.Spatial.Prefix
         /// where non-matching documents are looked for so they can be excluded. If
         /// -1 is used then the whole world is examined (a good default for correctness).
         /// </summary>
+        [SuppressMessage("CodeQuality", "IDE0079:Remove unnecessary suppression", Justification = "This is a SonarCloud issue")]
+        [SuppressMessage("CodeQuality", "S1699:Constructors should only call non-overridable methods", Justification = "Required for continuity with Lucene's design")]
         public WithinPrefixTreeFilter(IShape queryShape, string fieldName, SpatialPrefixTree grid, 
                                       int detailLevel, int prefixGridScanLevel, double queryBuffer)
-            : base(queryShape, fieldName, grid, detailLevel, prefixGridScanLevel)
+            : this(queryShape, fieldName, grid, detailLevel, prefixGridScanLevel, bufferedQueryShape: null)
         {
             if (queryBuffer == -1)
             {
-                bufferedQueryShape = null;
+                m_bufferedQueryShape = null;
             }
             else
             {
-                bufferedQueryShape = BufferShape(queryShape, queryBuffer);
+                m_bufferedQueryShape = BufferShape(queryShape, queryBuffer);
             }
         }
 
+        // LUCENENET specific - subclasses can use this class to override the behavior of
+        // BufferShape method in a way that's safe and called from the subclass constructor
+        protected WithinPrefixTreeFilter(IShape queryShape, string fieldName, SpatialPrefixTree grid, 
+                                      int detailLevel, int prefixGridScanLevel, IShape? bufferedQueryShape)
+            : base(queryShape, fieldName, grid, detailLevel, prefixGridScanLevel)
+        {
+            m_bufferedQueryShape = bufferedQueryShape;
+        }
+
         /// <summary>
         /// Returns a new shape that is larger than shape by at distErr.
         /// </summary>
@@ -179,7 +192,7 @@ namespace Lucene.Net.Spatial.Prefix
                     throw new ArgumentNullException(nameof(cell));
 
                 //use buffered query shape instead of orig.  Works with null too.
-                return cell.GetSubCells(((WithinPrefixTreeFilter)m_filter).bufferedQueryShape).GetEnumerator();
+                return cell.GetSubCells(((WithinPrefixTreeFilter)m_filter).m_bufferedQueryShape).GetEnumerator();
             }
 
             protected override bool Visit(Cell cell)