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 2016/10/04 20:02:02 UTC

[32/46] lucenenet git commit: Changed Facet.FacetsCollector.GetMatchingDocs back to a method (non-deterministic), modified it to return a List instead of IList and modified related members OriginalMatchingDocs and CreateSampledDocs() similarly.

Changed Facet.FacetsCollector.GetMatchingDocs back to a method (non-deterministic), modified it to return a List<T> instead of IList<T> and modified related members OriginalMatchingDocs and CreateSampledDocs() similarly.


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

Branch: refs/heads/master
Commit: fd13e8e5e8e6032cc4ec9b8e4bcb8ff320b7d01c
Parents: 03d05b3
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Sun Sep 25 16:07:13 2016 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Mon Oct 3 23:31:51 2016 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Facet/FacetsCollector.cs         | 21 +++--
 .../RandomSamplingFacetsCollector.cs            | 81 +++++++++-----------
 .../Range/DoubleRangeFacetCounts.cs             |  2 +-
 .../Range/LongRangeFacetCounts.cs               |  2 +-
 .../SortedSet/SortedSetDocValuesFacetCounts.cs  |  2 +-
 .../Taxonomy/FastTaxonomyFacetCounts.cs         |  2 +-
 .../Taxonomy/TaxonomyFacetCounts.cs             |  2 +-
 .../TaxonomyFacetSumFloatAssociations.cs        |  2 +-
 .../Taxonomy/TaxonomyFacetSumIntAssociations.cs |  2 +-
 .../Taxonomy/TaxonomyFacetSumValueSource.cs     |  2 +-
 .../WriterCache/TestCompactLabelToOrdinal.cs    |  4 +-
 .../TestRandomSamplingFacetsCollector.cs        |  4 +-
 12 files changed, 59 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fd13e8e5/src/Lucene.Net.Facet/FacetsCollector.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Facet/FacetsCollector.cs b/src/Lucene.Net.Facet/FacetsCollector.cs
index d7be2f0..0b225d0 100644
--- a/src/Lucene.Net.Facet/FacetsCollector.cs
+++ b/src/Lucene.Net.Facet/FacetsCollector.cs
@@ -38,7 +38,7 @@ namespace Lucene.Net.Facet
         private int totalHits;
         private float[] scores;
         private readonly bool keepScores;
-        private readonly IList<MatchingDocs> matchingDocs = new List<MatchingDocs>();
+        private readonly List<MatchingDocs> matchingDocs = new List<MatchingDocs>();
         private Docs docs;
 
         /// <summary>
@@ -166,20 +166,17 @@ namespace Lucene.Net.Facet
         /// Returns the documents matched by the query, one <seealso cref="GetMatchingDocs"/> per
         /// visited segment.
         /// </summary>
-        public virtual IList<MatchingDocs> GetMatchingDocs
+        public virtual List<MatchingDocs> GetMatchingDocs()
         {
-            get
+            if (docs != null)
             {
-                if (docs != null)
-                {
-                    matchingDocs.Add(new MatchingDocs(this.context, docs.DocIdSet, totalHits, scores));
-                    docs = null;
-                    scores = null;
-                    context = null;
-                }
-
-                return matchingDocs;
+                matchingDocs.Add(new MatchingDocs(this.context, docs.DocIdSet, totalHits, scores));
+                docs = null;
+                scores = null;
+                context = null;
             }
+
+            return matchingDocs;
         }
 
         public override sealed bool AcceptsDocsOutOfOrder()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fd13e8e5/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs b/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs
index 6c00c40..491cf5e 100644
--- a/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs
+++ b/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs
@@ -1,25 +1,26 @@
 \ufeffusing System;
 using System.Collections.Generic;
 using System.IO;
+using System.Linq;
 
 namespace Lucene.Net.Facet
 {
     /*
-     * Licensed to the Apache Software Foundation (ASF) under one or more
-     * contributor license agreements.  See the NOTICE file distributed with
-     * this work for additional information regarding copyright ownership.
-     * The ASF licenses this file to You under the Apache License, Version 2.0
-     * (the "License"); you may not use this file except in compliance with
-     * the License.  You may obtain a copy of the License at
-     *
-     *     http://www.apache.org/licenses/LICENSE-2.0
-     *
-     * Unless required by applicable law or agreed to in writing, software
-     * distributed under the License is distributed on an "AS IS" BASIS,
-     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     * See the License for the specific language governing permissions and
-     * limitations under the License.
-     */
+    * Licensed to the Apache Software Foundation (ASF) under one or more
+    * contributor license agreements.  See the NOTICE file distributed with
+    * this work for additional information regarding copyright ownership.
+    * The ASF licenses this file to You under the Apache License, Version 2.0
+    * (the "License"); you may not use this file except in compliance with
+    * the License.  You may obtain a copy of the License at
+    *
+    *     http://www.apache.org/licenses/LICENSE-2.0
+    *
+    * Unless required by applicable law or agreed to in writing, software
+    * distributed under the License is distributed on an "AS IS" BASIS,
+    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    * See the License for the specific language governing permissions and
+    * limitations under the License.
+    */
 
     using DimConfig = FacetsConfig.DimConfig;
     using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator;
@@ -86,7 +87,7 @@ namespace Lucene.Net.Facet
         private readonly XORShift64Random random;
 
         private double samplingRate;
-        private IList<MatchingDocs> sampledDocs;
+        private List<MatchingDocs> sampledDocs;
         private int totalHits = NOT_CALCULATED;
         private int leftoverBin = NOT_CALCULATED;
         private int leftoverIndex = NOT_CALCULATED;
@@ -132,50 +133,44 @@ namespace Lucene.Net.Facet
         /// MatchingDocs, scores is set to {@code null}
         /// </para>
         /// </summary>
-        public override IList<MatchingDocs> GetMatchingDocs
+        public override List<MatchingDocs> GetMatchingDocs()
         {
-            get
-            {
-                IList<MatchingDocs> matchingDocs = base.GetMatchingDocs;
+            List<MatchingDocs> matchingDocs = base.GetMatchingDocs();
 
-                if (totalHits == NOT_CALCULATED)
+            if (totalHits == NOT_CALCULATED)
+            {
+                totalHits = 0;
+                foreach (MatchingDocs md in matchingDocs)
                 {
-                    totalHits = 0;
-                    foreach (MatchingDocs md in matchingDocs)
-                    {
-                        totalHits += md.TotalHits;
-                    }
+                    totalHits += md.TotalHits;
                 }
+            }
 
-                if (totalHits <= sampleSize)
-                {
-                    return matchingDocs;
-                }
+            if (totalHits <= sampleSize)
+            {
+                return matchingDocs;
+            }
 
-                if (sampledDocs == null)
-                {
-                    samplingRate = (1.0 * sampleSize) / totalHits;
-                    sampledDocs = CreateSampledDocs(matchingDocs);
-                }
-                return sampledDocs;
+            if (sampledDocs == null)
+            {
+                samplingRate = (1.0 * sampleSize) / totalHits;
+                sampledDocs = CreateSampledDocs(matchingDocs);
             }
+            return sampledDocs;
         }
 
         /// <summary>
         /// Returns the original matching documents. </summary>
-        public virtual IList<MatchingDocs> OriginalMatchingDocs
+        public virtual List<MatchingDocs> GetOriginalMatchingDocs()
         {
-            get
-            {
-                return base.GetMatchingDocs;
-            }
+            return base.GetMatchingDocs();
         }
 
         /// <summary>
         /// Create a sampled copy of the matching documents list. </summary>
-        private IList<MatchingDocs> CreateSampledDocs(IList<MatchingDocs> matchingDocsList)
+        private List<MatchingDocs> CreateSampledDocs(IEnumerable<MatchingDocs> matchingDocsList)
         {
-            IList<MatchingDocs> sampledDocsList = new List<MatchingDocs>(matchingDocsList.Count);
+            List<MatchingDocs> sampledDocsList = new List<MatchingDocs>(matchingDocsList.Count());
             foreach (MatchingDocs docs in matchingDocsList)
             {
                 sampledDocsList.Add(CreateSample(docs));

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fd13e8e5/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs b/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs
index 52a3ad5..7905086 100644
--- a/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs
+++ b/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs
@@ -79,7 +79,7 @@ namespace Lucene.Net.Facet.Range
         public DoubleRangeFacetCounts(string field, ValueSource valueSource, FacetsCollector hits, Filter fastMatchFilter, DoubleRange[] ranges)
             : base(field, ranges, fastMatchFilter)
         {
-            Count(valueSource, hits.GetMatchingDocs);
+            Count(valueSource, hits.GetMatchingDocs());
         }
 
         private void Count(ValueSource valueSource, IEnumerable<MatchingDocs> matchingDocs)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fd13e8e5/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs b/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs
index d906cf8..60451c4 100644
--- a/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs
+++ b/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs
@@ -72,7 +72,7 @@ namespace Lucene.Net.Facet.Range
             FacetsCollector hits, Filter fastMatchFilter, params LongRange[] ranges)
             : base(field, ranges, fastMatchFilter)
         {
-            Count(valueSource, hits.GetMatchingDocs);
+            Count(valueSource, hits.GetMatchingDocs());
         }
 
         private void Count(ValueSource valueSource, IList<MatchingDocs> matchingDocs)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fd13e8e5/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs
index b32d430..c1a1da9 100644
--- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs
+++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs
@@ -69,7 +69,7 @@ namespace Lucene.Net.Facet.SortedSet
             dv = state.DocValues;
             counts = new int[state.Size];
             //System.out.println("field=" + field);
-            Count(hits.GetMatchingDocs);
+            Count(hits.GetMatchingDocs());
         }
 
         public override FacetResult GetTopChildren(int topN, string dim, params string[] path)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fd13e8e5/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs b/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs
index e303394..3511af8 100644
--- a/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs
+++ b/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs
@@ -51,7 +51,7 @@ namespace Lucene.Net.Facet.Taxonomy
         public FastTaxonomyFacetCounts(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc)
             : base(indexFieldName, taxoReader, config)
         {
-            Count(fc.GetMatchingDocs);
+            Count(fc.GetMatchingDocs());
         }
 
         private void Count(IList<FacetsCollector.MatchingDocs> matchingDocs)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fd13e8e5/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs
index 059822c..b86c924 100644
--- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs
+++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs
@@ -45,7 +45,7 @@ namespace Lucene.Net.Facet.Taxonomy
             : base(ordinalsReader.IndexFieldName, taxoReader, config)
         {
             this.ordinalsReader = ordinalsReader;
-            Count(fc.GetMatchingDocs);
+            Count(fc.GetMatchingDocs());
         }
 
         private void Count(IList<FacetsCollector.MatchingDocs> matchingDocs)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fd13e8e5/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs
index b943004..e30cef2 100644
--- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs
+++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs
@@ -50,7 +50,7 @@ namespace Lucene.Net.Facet.Taxonomy
         public TaxonomyFacetSumFloatAssociations(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc)
             : base(indexFieldName, taxoReader, config)
         {
-            SumValues(fc.GetMatchingDocs);
+            SumValues(fc.GetMatchingDocs());
         }
 
         private void SumValues(IList<FacetsCollector.MatchingDocs> matchingDocs)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fd13e8e5/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs
index d053dfe..7ff982b 100644
--- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs
+++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs
@@ -49,7 +49,7 @@ namespace Lucene.Net.Facet.Taxonomy
         public TaxonomyFacetSumIntAssociations(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc)
             : base(indexFieldName, taxoReader, config)
         {
-            SumValues(fc.GetMatchingDocs);
+            SumValues(fc.GetMatchingDocs());
         }
 
         private void SumValues(IList<FacetsCollector.MatchingDocs> matchingDocs)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fd13e8e5/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs
index 2ae0f49..99dbed1 100644
--- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs
+++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs
@@ -66,7 +66,7 @@ namespace Lucene.Net.Facet.Taxonomy
             : base(ordinalsReader.IndexFieldName, taxoReader, config)
         {
             this.ordinalsReader = ordinalsReader;
-            SumValues(fc.GetMatchingDocs, fc.KeepScores, valueSource);
+            SumValues(fc.GetMatchingDocs(), fc.KeepScores, valueSource);
         }
 
         private sealed class FakeScorer : Scorer

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fd13e8e5/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs
index eafdd62..82c0bdd 100644
--- a/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs
+++ b/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs
@@ -108,7 +108,7 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache
 
                 if (ord1 == LabelToOrdinal.INVALID_ORDINAL)
                 {
-                    ord1 = compact.NextOrdinal;
+                    ord1 = compact.GetNextOrdinal();
                     map.AddLabel(label, ord1);
                     compact.AddLabel(label, ord1);
                 }
@@ -224,7 +224,7 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache
 
                     if (ord1 == LabelToOrdinal.INVALID_ORDINAL)
                     {
-                        ord1 = compact.NextOrdinal;
+                        ord1 = compact.GetNextOrdinal();
                         map.AddLabel(label, ord1);
                         compact.AddLabel(label, ord1);
                     }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fd13e8e5/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs b/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs
index 2969436..b98b283 100644
--- a/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs
+++ b/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs
@@ -75,10 +75,10 @@ namespace Lucene.Net.Facet
             searcher.Search(new TermQuery(new Term("EvenOdd", "NeverMatches")), collectRandomZeroResults);
 
             // There should be no divisions by zero and no null result
-            Assert.NotNull(collectRandomZeroResults.GetMatchingDocs);
+            Assert.NotNull(collectRandomZeroResults.GetMatchingDocs());
 
             // There should be no results at all
-            foreach (MatchingDocs doc in collectRandomZeroResults.GetMatchingDocs)
+            foreach (MatchingDocs doc in collectRandomZeroResults.GetMatchingDocs())
             {
                 Assert.AreEqual(0, doc.TotalHits);
             }