From 1ca08dfb1609699219da6922138a523b007dff3b Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Fri, 23 Sep 2016 21:07:16 +0700 Subject: [PATCH 01/41] Fixed Facet.Taxonomy.LRUHashMap implementation to correctly remove the eldest item from the cache when an item is added (test passing). --- .../Directory/DirectoryTaxonomyReader.cs | 35 ++-- src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs | 162 +++++++++++------- .../Taxonomy/TestLRUHashMap.cs | 2 +- 3 files changed, 118 insertions(+), 81 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs index a5672108a2..da82cbf4af 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs @@ -353,24 +353,21 @@ public override FacetLabel GetPath(int ordinal) // TODO: can we use an int-based hash impl, such as IntToObjectMap, // wrapped as LRU? - int catIDInteger = Convert.ToInt32(ordinal); - lock (categoryCache) + + // LUCENENET NOTE: We don't need to convert int to int here. + // Also, our cache implementation is thread safe, so we can nix the + // locks. + FacetLabel res; + if (categoryCache.TryGetValue(ordinal, out res)) { - var res = categoryCache.Get(catIDInteger,false); - if (res != null) - { - return res; - } + return res; } Document doc = indexReader.Document(ordinal); - FacetLabel ret = new FacetLabel(FacetsConfig.StringToPath(doc.Get(Consts.FULL))); - lock (categoryCache) - { - categoryCache.Put(catIDInteger, ret); - } + res = new FacetLabel(FacetsConfig.StringToPath(doc.Get(Consts.FULL))); + categoryCache.Put(ordinal, res); - return ret; + return res; } public override int Size @@ -395,14 +392,10 @@ public virtual int CacheSize set { EnsureOpen(); - lock (categoryCache) - { - categoryCache.MaxSize = value; - } - lock (ordinalCache) - { - ordinalCache.MaxSize = value; - } + // LUCENENET NOTE: No locking required here, + // since our LRU implementation is thread-safe + categoryCache.MaxSize = value; + ordinalCache.MaxSize = value; } } diff --git a/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs b/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs index d4429925ba..5d51036a27 100644 --- a/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs +++ b/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs @@ -1,13 +1,9 @@ using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; -using System.Threading; -using Lucene.Net.Support; namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -25,7 +21,6 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ - /// /// LRUHashMap is an extension of Java's HashMap, which has a bounded size(); /// When it reaches that size, each time a new element is added, the least @@ -58,97 +53,146 @@ namespace Lucene.Net.Facet.Taxonomy /// @lucene.experimental /// /// - public class LRUHashMap where TU : class //this is implementation of LRU Cache + public class LRUHashMap where TValue : class //this is implementation of LRU Cache { - - public int MaxSize { get; set; } - private int CleanSize; - private TimeSpan MaxDuration; - - - private readonly ConcurrentDictionary> _cache = new ConcurrentDictionary>(); - - public LRUHashMap(int maxSize = 50000, int cleanPercentage = 30, TimeSpan maxDuration = default(TimeSpan)) + private readonly Dictionary cache; + // We can't use a ReaderWriterLockSlim because every read is also a + // write, so we gain nothing by doing so + private readonly object syncLock = new object(); + // Record last access so we can tie break if 2 calls make it in within + // the same millisecond. + private long lastAccess; + private int maxSize; + + public LRUHashMap(int maxSize) { - MaxSize = maxSize; - CleanSize = (int)Math.Max(MaxSize * (1.0 * cleanPercentage / 100), 1); - if (maxDuration == default(TimeSpan)) + if (maxSize < 1) { - MaxDuration = TimeSpan.FromDays(1); + throw new ArgumentOutOfRangeException("maxSize must be at least 1"); } - else + this.maxSize = maxSize; + this.cache = new Dictionary(maxSize); + } + + public virtual int MaxSize + { + get { return maxSize; } + set { - MaxDuration = maxDuration; + if (value < 1) + { + throw new ArgumentOutOfRangeException("MaxSize must be at least 1"); + } + maxSize = value; } } - - public bool Put(TV cacheKey, TU value) + public bool Put(TKey key, TValue value) { - return AddToCache(cacheKey, value); + lock (syncLock) + { + CacheDataObject cdo; + if (cache.TryGetValue(key, out cdo)) + { + // Item already exists, update our last access time + cdo.Timestamp = GetTimestamp(); + } + else + { + cache[key] = new CacheDataObject + { + Value = value, + Timestamp = GetTimestamp() + }; + // We have added a new item, so we may need to remove the eldest + if (cache.Count > MaxSize) + { + // Remove the eldest item (lowest timestamp) from the cache + cache.Remove(cache.OrderBy(x => x.Value.Timestamp).First().Key); + } + } + } + return true; } - public bool AddToCache(TV cacheKey, TU value) + public TValue Get(TKey key) { - var cachedResult = new CacheDataObject - { - Usage = 1, //value == null ? 1 : value.Usage + 1, - Value = value, - Timestamp = DateTime.UtcNow - }; - - _cache.AddOrUpdate(cacheKey, cachedResult, (_, __) => cachedResult); - if (_cache.Count > MaxSize) + lock (syncLock) { - foreach (var source in _cache - .OrderByDescending(x => x.Value.Usage) - .ThenBy(x => x.Value.Timestamp) - .Skip(MaxSize - CleanSize)) + CacheDataObject cdo; + if (cache.TryGetValue(key, out cdo)) { - if (EqualityComparer.Default.Equals(source.Key, cacheKey)) - continue; // we don't want to remove the one we just added - CacheDataObject ignored; - _cache.TryRemove(source.Key, out ignored); + // Write our last access time + cdo.Timestamp = GetTimestamp(); + + return cdo.Value; } } - return true; + return null; } - public TU Get(TV cacheKey, bool increment = false) + public bool TryGetValue(TKey key, out TValue value) { - CacheDataObject value; - if (_cache.TryGetValue(cacheKey, out value) && (DateTime.UtcNow - value.Timestamp) <= MaxDuration) + lock (syncLock) { - if (increment) + CacheDataObject cdo; + if (cache.TryGetValue(key, out cdo)) { - Interlocked.Increment(ref value.Usage); + // Write our last access time + cdo.Timestamp = GetTimestamp(); + value = cdo.Value; + + return true; } - return value.Value; + + value = null; + return false; } - return null; } - public bool IsExistInCache(TV cacheKey) + public bool ContainsKey(TKey key) { - return (_cache.ContainsKey(cacheKey)); + return cache.ContainsKey(key); } + // LUCENENET TODO: Rename to Count (.NETify) public int Size() { - return _cache.Count; + return cache.Count; + } + + private long GetTimestamp() + { + long ticks = DateTime.UtcNow.Ticks; + if (ticks <= lastAccess) + { + // Tie break by incrementing + // when 2 calls happen within the + // same millisecond + ticks = ++lastAccess; + } + else + { + lastAccess = ticks; + } + return ticks; } + #region Nested type: CacheDataObject - private class CacheDataObject where T : class + private class CacheDataObject { - public DateTime Timestamp; - public int Usage; - public T Value; + // Ticks representing the last access time + public long Timestamp; + public TValue Value; + + public override string ToString() + { + return "Last Access: " + Timestamp.ToString() + " - " + Value.ToString(); + } } #endregion - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs index 71b62c565c..c08bca86c3 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs @@ -30,7 +30,7 @@ public class TestLRUHashMap : FacetTestCase [Test] public virtual void TestLru() { - LRUHashMap lru = new LRUHashMap(3,1); + LRUHashMap lru = new LRUHashMap(3); Assert.AreEqual(0, lru.Size()); lru.Put("one", "Hello world"); Assert.AreEqual(1, lru.Size()); From bcbfad58f7c6b3c3c26f20d72e87e4a06c798e37 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Fri, 23 Sep 2016 22:32:08 +0700 Subject: [PATCH 02/41] Fixed bug in Facet.Taxonomy.SearcherTaxonomyManager - wrong exception being thrown. --- src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs b/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs index d543aad260..7abc055e14 100644 --- a/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs +++ b/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs @@ -32,6 +32,7 @@ namespace Lucene.Net.Facet.Taxonomy using SearcherManager = Lucene.Net.Search.SearcherManager; using Directory = Lucene.Net.Store.Directory; using IOUtils = Lucene.Net.Util.IOUtils; + using System; /// /// Manages near-real-time reopen of both an IndexSearcher @@ -163,7 +164,7 @@ protected override SearcherAndTaxonomy RefreshIfNeeded(SearcherAndTaxonomy @ref) else if (taxoWriter != null && taxoWriter.TaxonomyEpoch != taxoEpoch) { IOUtils.Close(newReader, tr); - throw new ThreadStateException("DirectoryTaxonomyWriter.replaceTaxonomy was called, which is not allowed when using SearcherTaxonomyManager"); + throw new InvalidOperationException("DirectoryTaxonomyWriter.replaceTaxonomy was called, which is not allowed when using SearcherTaxonomyManager"); } return new SearcherAndTaxonomy(SearcherManager.GetSearcher(searcherFactory, newReader), tr); From 861aa7377a915465fac212c8db66b1a76996b28e Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Fri, 23 Sep 2016 23:38:42 +0700 Subject: [PATCH 03/41] Finished implementation of Facet.Taxonomy.WriterCache.TestCharBlockArray test and fixed the implementation of CharBlockArray and CompactLabelToOrdinal to make the test pass. --- src/Lucene.Net.Core/Support/StreamUtils.cs | 11 ++-- .../Properties/AssemblyInfo.cs | 3 + .../Taxonomy/WriterCache/CharBlockArray.cs | 18 +++--- .../WriterCache/CompactLabelToOrdinal.cs | 26 +++------ .../WriterCache/TestCharBlockArray.cs | 58 ++++++++----------- 5 files changed, 48 insertions(+), 68 deletions(-) diff --git a/src/Lucene.Net.Core/Support/StreamUtils.cs b/src/Lucene.Net.Core/Support/StreamUtils.cs index 75e7d157ce..7e05717669 100644 --- a/src/Lucene.Net.Core/Support/StreamUtils.cs +++ b/src/Lucene.Net.Core/Support/StreamUtils.cs @@ -13,13 +13,12 @@ public static class StreamUtils { static readonly BinaryFormatter Formatter = new BinaryFormatter(); - public static MemoryStream SerializeToStream(object o) + public static void SerializeToStream(object o, Stream outputStream) { - using (var stream = new MemoryStream()) - { - Formatter.Serialize(stream, o); - return stream; - } + // LUCENENET TODO: It would probably be better to serialize to + // XML so this works across .NET framework versions or alternatively + // find/create an alternative binary formatter implementation that works that way. + Formatter.Serialize(outputStream, o); } public static object DeserializeFromStream(Stream stream) diff --git a/src/Lucene.Net.Facet/Properties/AssemblyInfo.cs b/src/Lucene.Net.Facet/Properties/AssemblyInfo.cs index 741693dc1b..7325e4c21a 100644 --- a/src/Lucene.Net.Facet/Properties/AssemblyInfo.cs +++ b/src/Lucene.Net.Facet/Properties/AssemblyInfo.cs @@ -22,6 +22,9 @@ // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("8dd11ab2-c5b3-4691-99da-2941f27e0e10")] +// for testing +[assembly: InternalsVisibleTo("Lucene.Net.Tests.Facet")] + // Version information for an assembly consists of the following four values: // // Major Version diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs index a6a60e7d02..a38329b1c0 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs @@ -54,7 +54,10 @@ internal Block(int size) public object Clone() { - throw new NotImplementedException(); + var clone = new Block(chars.Length); + clone.length = length; + Array.Copy(chars, clone.chars, chars.Length); + return clone; } } @@ -214,21 +217,14 @@ public override string ToString() return sb.ToString(); } - internal virtual void Flush(OutputStreamDataOutput @out) + internal virtual void Flush(Stream @out) { - - using (var ms = StreamUtils.SerializeToStream(this)) - { - var bytes = ms.ToArray(); - @out.WriteBytes(bytes, 0, bytes.Length); - } + StreamUtils.SerializeToStream(this, @out); } - public static CharBlockArray Open(BinaryReader @in) + public static CharBlockArray Open(Stream @in) { return StreamUtils.DeserializeFromStream(@in) as CharBlockArray; } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs index 07bd162374..f717fb1a2b 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs @@ -396,7 +396,7 @@ internal virtual int MemoryUsage /// Opens the file and reloads the CompactLabelToOrdinal. The file it expects /// is generated from the command. /// - public static CompactLabelToOrdinal Open(string file, float loadFactor, int numHashArrays) + internal static CompactLabelToOrdinal Open(string file, float loadFactor, int numHashArrays) { /// /// Part of the file is the labelRepository, which needs to be rehashed @@ -422,7 +422,7 @@ public static CompactLabelToOrdinal Open(string file, float loadFactor, int numH l2o.Init(); // now read the chars - l2o.labelRepository = CharBlockArray.Open(dis); + l2o.labelRepository = CharBlockArray.Open(dis.BaseStream); l2o.collisionMap = new CollisionMap(l2o.labelRepository); @@ -443,13 +443,13 @@ public static CompactLabelToOrdinal Open(string file, float loadFactor, int numH // identical code to CategoryPath.hashFromSerialized. since we need to // advance offset, we cannot call the method directly. perhaps if we // could pass a mutable Integer or something... - int length = (short)l2o.labelRepository.CharAt(offset++); + int length = (ushort)l2o.labelRepository.CharAt(offset++); int hash = length; if (length != 0) { for (int i = 0; i < length; i++) { - int len = (short)l2o.labelRepository.CharAt(offset++); + int len = (ushort)l2o.labelRepository.CharAt(offset++); hash = hash * 31 + l2o.labelRepository.SubSequence(offset, offset + len).GetHashCode(); offset += len; } @@ -482,24 +482,14 @@ public static CompactLabelToOrdinal Open(string file, float loadFactor, int numH } - public virtual void Flush(Stream stream) + internal virtual void Flush(FileStream stream) { - - OutputStreamDataOutput dos = new OutputStreamDataOutput(stream); - - try + using (BinaryWriter dos = new BinaryWriter(stream)) { - dos.WriteInt(this.counter); + dos.Write(this.counter); // write the labelRepository - this.labelRepository.Flush(dos); - // Closes the data output stream - dos.Dispose(); - - } - finally - { - dos.Dispose(); + this.labelRepository.Flush(dos.BaseStream); } } diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCharBlockArray.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCharBlockArray.cs index f4be988174..f059a79048 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCharBlockArray.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCharBlockArray.cs @@ -1,13 +1,9 @@ -using System.Text; -using Lucene.Net.Support; -using NUnit.Framework; +using NUnit.Framework; +using System.IO; +using System.Text; namespace Lucene.Net.Facet.Taxonomy.WriterCache { - - - using TestUtil = Lucene.Net.Util.TestUtil; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -24,14 +20,13 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache * See the License for the specific language governing permissions and * limitations under the License. */ + [TestFixture] public class TestCharBlockArray : FacetTestCase { - /* not finished yet because of missing charset decoder */ - - /* - public virtual void testArray() + [Test] + public virtual void TestArray() { CharBlockArray array = new CharBlockArray(); StringBuilder builder = new StringBuilder(); @@ -47,9 +42,8 @@ public virtual void testArray() // This test is turning random bytes into a string, // this is asking for trouble. - CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onUnmappableCharacter(CodingErrorAction.REPLACE).onMalformedInput(CodingErrorAction.REPLACE); - string s = decoder.Decode(ByteBuffer.Wrap(buffer, 0, size)).ToString(); - array.append(s); + string s = Encoding.UTF8.GetString(buffer, 0, size); + array.Append(s); builder.Append(s); } @@ -59,9 +53,8 @@ public virtual void testArray() int size = 1 + Random().Next(50); // This test is turning random bytes into a string, // this is asking for trouble. - CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onUnmappableCharacter(CodingErrorAction.REPLACE).onMalformedInput(CodingErrorAction.REPLACE); - string s = decoder.decode(ByteBuffer.Wrap(buffer, 0, size)).ToString(); - array.append((CharSequence)s); + string s = Encoding.UTF8.GetString(buffer, 0, size); + array.Append(s); builder.Append(s); } @@ -71,29 +64,30 @@ public virtual void testArray() int size = 1 + Random().Next(50); // This test is turning random bytes into a string, // this is asking for trouble. - CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onUnmappableCharacter(CodingErrorAction.REPLACE).onMalformedInput(CodingErrorAction.REPLACE); - string s = decoder.decode(ByteBuffer.Wrap(buffer, 0, size)).ToString(); + string s = Encoding.UTF8.GetString(buffer, 0, size); for (int j = 0; j < s.Length; j++) { - array.append(s[j]); + array.Append(s[j]); } builder.Append(s); } AssertEqualsInternal("GrowingCharArray<->StringBuilder mismatch.", builder, array); - File tempDir = CreateTempDir("growingchararray"); - File f = new File(tempDir, "GrowingCharArrayTest.tmp"); - BufferedOutputStream @out = new BufferedOutputStream(new FileOutputStream(f)); - array.flush(@out); - @out.flush(); - @out.Close(); + DirectoryInfo tempDir = CreateTempDir("growingchararray"); + FileInfo f = new FileInfo(Path.Combine(tempDir.FullName, "GrowingCharArrayTest.tmp")); + using (Stream @out = new FileStream(f.FullName, FileMode.OpenOrCreate, FileAccess.Write)) + { + array.Flush(@out); + @out.Flush(); + } - BufferedInputStream @in = new BufferedInputStream(new FileInputStream(f)); - array = CharBlockArray.open(@in); - AssertEqualsInternal("GrowingCharArray<->StringBuilder mismatch after flush/load.", builder, array); - @in.Close(); - f.delete(); + using (Stream @in = new FileStream(f.FullName, FileMode.Open, FileAccess.Read)) + { + array = CharBlockArray.Open(@in); + AssertEqualsInternal("GrowingCharArray<->StringBuilder mismatch after flush/load.", builder, array); + } + f.Delete(); } private static void AssertEqualsInternal(string msg, StringBuilder expected, CharBlockArray actual) @@ -104,7 +98,5 @@ private static void AssertEqualsInternal(string msg, StringBuilder expected, Cha Assert.AreEqual(expected[i], actual.CharAt(i), msg); } } - */ } - } \ No newline at end of file From 08dfc1bd0e84712eed5d4d34dd629408998cd196 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sat, 24 Sep 2016 16:32:20 +0700 Subject: [PATCH 04/41] Finished port of Facet.Taxonomy.WriterCache.TestCompactLabelToOrdinal and fixed bugs with FacetLabel hash code, CategoryPathUtils.EqualsToSerialized(), CharBlockArray.SubSequence() and CompactLabelToOrdinal.Open() to make the tests pass. Added an extra non-random test to make debugging easier. --- src/Lucene.Net.Core/Support/StreamUtils.cs | 21 +- src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs | 7 +- .../Taxonomy/WriterCache/CategoryPathUtils.cs | 9 +- .../Taxonomy/WriterCache/CharBlockArray.cs | 12 +- .../WriterCache/CompactLabelToOrdinal.cs | 16 +- .../WriterCache/TestCharBlockArray.cs | 4 +- .../WriterCache/TestCompactLabelToOrdinal.cs | 183 +++++++++++++++--- 7 files changed, 189 insertions(+), 63 deletions(-) diff --git a/src/Lucene.Net.Core/Support/StreamUtils.cs b/src/Lucene.Net.Core/Support/StreamUtils.cs index 7e05717669..e6cd549688 100644 --- a/src/Lucene.Net.Core/Support/StreamUtils.cs +++ b/src/Lucene.Net.Core/Support/StreamUtils.cs @@ -1,11 +1,5 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.Serialization; +using System.IO; using System.Runtime.Serialization.Formatters.Binary; -using System.Text; -using System.Threading.Tasks; namespace Lucene.Net.Support { @@ -15,24 +9,23 @@ public static class StreamUtils public static void SerializeToStream(object o, Stream outputStream) { - // LUCENENET TODO: It would probably be better to serialize to - // XML so this works across .NET framework versions or alternatively - // find/create an alternative binary formatter implementation that works that way. Formatter.Serialize(outputStream, o); } + public static void SerializeToStream(object o, BinaryWriter writer) + { + Formatter.Serialize(writer.BaseStream, o); + } + public static object DeserializeFromStream(Stream stream) { - stream.Seek(0, SeekOrigin.Begin); object o = Formatter.Deserialize(stream); return o; } public static object DeserializeFromStream(BinaryReader reader) { - var stream = reader.BaseStream; - stream.Seek(0, SeekOrigin.Begin); - object o = Formatter.Deserialize(stream); + object o = Formatter.Deserialize(reader.BaseStream); return o; } } diff --git a/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs b/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs index a448d08b71..9a6884c821 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs @@ -162,7 +162,12 @@ public override int GetHashCode() return 0; } - return Arrays.GetHashCode(Components); + int hash = Length; + for (int i = 0; i < Length; i++) + { + hash = hash * 31 + Components[i].GetHashCode(); + } + return hash; } /// diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CategoryPathUtils.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CategoryPathUtils.cs index 24b0fa2b73..eb63f56708 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CategoryPathUtils.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CategoryPathUtils.cs @@ -1,6 +1,7 @@ -namespace Lucene.Net.Facet.Taxonomy.WriterCache -{ +using System; +namespace Lucene.Net.Facet.Taxonomy.WriterCache +{ /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -85,7 +86,7 @@ public static bool EqualsToSerialized(FacetLabel cp, CharBlockArray charBlockArr return false; } - if (!cp.Components[i].Equals(charBlockArray.SubSequence(offset, offset + len))) + if (!cp.Components[i].Equals(charBlockArray.SubSequence(offset, offset + len), StringComparison.Ordinal)) { return false; } @@ -93,7 +94,5 @@ public static bool EqualsToSerialized(FacetLabel cp, CharBlockArray charBlockArr } return true; } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs index a38329b1c0..c1c982545d 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs @@ -163,7 +163,7 @@ public virtual CharBlockArray Append(string s) { toCopy = remainingInBlock; } - s.CopyTo(offset, this.current.chars, this.current.length, offset + toCopy - offset); + s.CopyTo(offset, this.current.chars, this.current.length, toCopy); offset += toCopy; remain -= toCopy; this.current.length += toCopy; @@ -187,7 +187,7 @@ public char CharAt(int index) return b.chars[IndexInBlock(index)]; } - public ICharSequence SubSequence(int start, int end) + public string SubSequence(int start, int end) { int remaining = end - start; StringBuilder sb = new StringBuilder(remaining); @@ -201,11 +201,13 @@ public ICharSequence SubSequence(int start, int end) remaining -= numToAppend; indexInBlock = 0; // 2nd+ iterations read from start of the block } - return new StringCharSequenceWrapper(sb.ToString()); + return sb.ToString(); } - - + ICharSequence ICharSequence.SubSequence(int start, int end) + { + return new StringCharSequenceWrapper(this.SubSequence(start, end)); + } public override string ToString() { diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs index f717fb1a2b..d0cebe27b8 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs @@ -1,11 +1,9 @@ using System; -using System.Collections.Generic; using System.IO; -using Lucene.Net.Store; +using System.Runtime.Serialization; namespace Lucene.Net.Facet.Taxonomy.WriterCache { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -23,7 +21,6 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache * limitations under the License. */ - /// /// This is a very efficient LabelToOrdinal implementation that uses a /// CharBlockArray to store all labels and a configurable number of HashArrays to @@ -396,7 +393,7 @@ internal virtual int MemoryUsage /// Opens the file and reloads the CompactLabelToOrdinal. The file it expects /// is generated from the command. /// - internal static CompactLabelToOrdinal Open(string file, float loadFactor, int numHashArrays) + internal static CompactLabelToOrdinal Open(FileInfo file, float loadFactor, int numHashArrays) { /// /// Part of the file is the labelRepository, which needs to be rehashed @@ -411,7 +408,7 @@ internal static CompactLabelToOrdinal Open(string file, float loadFactor, int nu BinaryReader dis = null; try { - dis = new BinaryReader(new FileStream(file,FileMode.Open,FileAccess.Read)); + dis = new BinaryReader(new FileStream(file.FullName, FileMode.Open, FileAccess.Read)); // TaxiReader needs to load the "counter" or occupancy (L2O) to know // the next unique facet. we used to load the delimiter too, but @@ -465,9 +462,9 @@ internal static CompactLabelToOrdinal Open(string file, float loadFactor, int nu } } - catch (DllNotFoundException) + catch (SerializationException se) { - throw new IOException("Invalid file format. Cannot deserialize."); + throw new IOException("Invalid file format. Cannot deserialize.", se); } finally { @@ -482,7 +479,7 @@ internal static CompactLabelToOrdinal Open(string file, float loadFactor, int nu } - internal virtual void Flush(FileStream stream) + internal virtual void Flush(Stream stream) { using (BinaryWriter dos = new BinaryWriter(stream)) { @@ -508,5 +505,4 @@ internal HashArray(int c) } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCharBlockArray.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCharBlockArray.cs index f059a79048..a763f809d4 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCharBlockArray.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCharBlockArray.cs @@ -76,13 +76,13 @@ public virtual void TestArray() DirectoryInfo tempDir = CreateTempDir("growingchararray"); FileInfo f = new FileInfo(Path.Combine(tempDir.FullName, "GrowingCharArrayTest.tmp")); - using (Stream @out = new FileStream(f.FullName, FileMode.OpenOrCreate, FileAccess.Write)) + using (var @out = new FileStream(f.FullName, FileMode.OpenOrCreate, FileAccess.Write)) { array.Flush(@out); @out.Flush(); } - using (Stream @in = new FileStream(f.FullName, FileMode.Open, FileAccess.Read)) + using (var @in = new FileStream(f.FullName, FileMode.Open, FileAccess.Read)) { array = CharBlockArray.Open(@in); AssertEqualsInternal("GrowingCharArray<->StringBuilder mismatch after flush/load.", builder, array); diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs index 549bf095d3..eafdd62726 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs @@ -1,14 +1,12 @@ -using System; +using NUnit.Framework; +using System; using System.Collections.Generic; -using Lucene.Net.Support; -using NUnit.Framework; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; namespace Lucene.Net.Facet.Taxonomy.WriterCache { - - - using TestUtil = Lucene.Net.Util.TestUtil; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -25,11 +23,11 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache * See the License for the specific language governing permissions and * limitations under the License. */ + [TestFixture] public class TestCompactLabelToOrdinal : FacetTestCase { - /* not finished to porting yet because of missing decoder implementation */ - /* + [Test] public virtual void TestL2O() { LabelToOrdinal map = new LabelToOrdinalMap(); @@ -43,18 +41,17 @@ public virtual void TestL2O() byte[] buffer = new byte[50]; Random random = Random(); - for (int i = 0; i < numUniqueValues; ) + for (int i = 0; i < numUniqueValues;) { random.NextBytes(buffer); int size = 1 + random.Next(buffer.Length); // This test is turning random bytes into a string, // this is asking for trouble. - CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onUnmappableCharacter(CodingErrorAction.REPLACE).onMalformedInput(CodingErrorAction.REPLACE); - uniqueValues[i] = decoder.decode(ByteBuffer.Wrap(buffer, 0, size)).ToString(); + uniqueValues[i] = Encoding.UTF8.GetString(buffer, 0, size); // we cannot have empty path components, so eliminate all prefix as well // as middle consecutive delimiter chars. - uniqueValues[i] = uniqueValues[i].replaceAll("/+", "/"); + uniqueValues[i] = Regex.Replace(uniqueValues[i], "/+", "/"); if (uniqueValues[i].StartsWith("/", StringComparison.Ordinal)) { uniqueValues[i] = uniqueValues[i].Substring(1); @@ -66,16 +63,21 @@ public virtual void TestL2O() } var tmpDir = CreateTempDir("testLableToOrdinal"); - var f = new File(tmpDir, "CompactLabelToOrdinalTest.tmp"); + var f = new FileInfo(Path.Combine(tmpDir.FullName, "CompactLabelToOrdinalTest.tmp")); int flushInterval = 10; for (int i = 0; i < n; i++) { if (i > 0 && i % flushInterval == 0) { - compact.Flush(f); - compact = CompactLabelToOrdinal.open(f, 0.15f, 3); - Assert.True(f.delete()); + using (var fileStream = new FileStream(f.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite)) + { + compact.Flush(fileStream); + } + compact = CompactLabelToOrdinal.Open(f, 0.15f, 3); + //assertTrue(f.Delete()); + f.Delete(); + assertFalse(File.Exists(f.FullName)); if (flushInterval < (n / 10)) { flushInterval *= 10; @@ -97,7 +99,12 @@ public virtual void TestL2O() int ord1 = map.GetOrdinal(label); int ord2 = compact.GetOrdinal(label); - Assert.AreEqual(ord1, ord2); + if (VERBOSE) + { + Console.WriteLine("Testing label: " + label.ToString()); + } + + assertEquals(ord1, ord2); if (ord1 == LabelToOrdinal.INVALID_ORDINAL) { @@ -121,13 +128,136 @@ public virtual void TestL2O() } int ord1 = map.GetOrdinal(label); int ord2 = compact.GetOrdinal(label); - Assert.AreEqual(ord1, ord2); + + if (VERBOSE) + { + Console.WriteLine("Testing label 2: " + label.ToString()); + } + + assertEquals(ord1, ord2); + } + } + + /// + /// LUCENENET specific test similar to TestL2O without any randomness, useful for debugging + /// + [Test] + public virtual void TestL2OBasic() + { + LabelToOrdinal map = new LabelToOrdinalMap(); + + CompactLabelToOrdinal compact = new CompactLabelToOrdinal(200, 0.15f, 3); + + int n = 50; + + string[] uniqueValues = new string[] + { + @"�", + @"�r�G��F�\u0382�7\u0019�h�\u0015���#\u001d3\r{��q�_���Ԃ������", + "foo bar one", + new string(new char[] { (char)65533, (char)65533, (char)65, (char)65533, (char)45, (char)106, (char)40, (char)643, (char)65533, (char)11, (char)65533, (char)88, (char)65533, (char)78, (char)126, (char)56, (char)12, (char)71 }), + "foo bar two", + "foo bar three", + "foo bar four", + "foo bar five", + "foo bar six", + "foo bar seven", + "foo bar eight", + "foo bar nine", + "foo bar ten", + "foo/bar/one", + "foo/bar/two", + "foo/bar/three", + "foo/bar/four", + "foo/bar/five", + "foo/bar/six", + "foo/bar/seven", + "foo/bar/eight", + "foo/bar/nine", + "foo/bar/ten", + "" + }; + + var tmpDir = CreateTempDir("testLableToOrdinal"); + var f = new FileInfo(Path.Combine(tmpDir.FullName, "CompactLabelToOrdinalTest.tmp")); + int flushInterval = 10; + + for (int i = 0; i < n; i++) + { + if (i > 0 && i % flushInterval == 0) + { + using (var fileStream = new FileStream(f.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite)) + { + compact.Flush(fileStream); + } + compact = CompactLabelToOrdinal.Open(f, 0.15f, 3); + //assertTrue(f.Delete()); + f.Delete(); + assertFalse(File.Exists(f.FullName)); + if (flushInterval < (n / 10)) + { + flushInterval *= 10; + } + } + + FacetLabel label = new FacetLabel(); + foreach (string s in uniqueValues) + { + if (s.Length == 0) + { + label = new FacetLabel(); + } + else + { + label = new FacetLabel(s.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); + } + + int ord1 = map.GetOrdinal(label); + int ord2 = compact.GetOrdinal(label); + + if (VERBOSE) + { + Console.WriteLine("Testing label: " + label.ToString()); + } + + assertEquals(ord1, ord2); + + if (ord1 == LabelToOrdinal.INVALID_ORDINAL) + { + ord1 = compact.NextOrdinal; + map.AddLabel(label, ord1); + compact.AddLabel(label, ord1); + } + } + } + + for (int i = 0; i < uniqueValues.Length; i++) + { + FacetLabel label; + string s = uniqueValues[i]; + if (s.Length == 0) + { + label = new FacetLabel(); + } + else + { + label = new FacetLabel(s.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); + } + int ord1 = map.GetOrdinal(label); + int ord2 = compact.GetOrdinal(label); + + if (VERBOSE) + { + Console.WriteLine("Testing label 2: " + label.ToString()); + } + + assertEquals(ord1, ord2); } } private class LabelToOrdinalMap : LabelToOrdinal { - internal IDictionary map = new Dictionary(); + internal IDictionary map = new Dictionary(); internal LabelToOrdinalMap() { @@ -140,12 +270,13 @@ public override void AddLabel(FacetLabel label, int ordinal) public override int GetOrdinal(FacetLabel label) { - int? value = map[label]; - return (value != null) ? (int)value : LabelToOrdinal.INVALID_ORDINAL; + int value; + if (map.TryGetValue(label, out value)) + { + return value; + } + return LabelToOrdinal.INVALID_ORDINAL; } - - } */ - + } } - } \ No newline at end of file From 602bbccdffeb0dee470220893ad41383d54f68f3 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sat, 24 Sep 2016 16:33:54 +0700 Subject: [PATCH 05/41] Added reminder to .NETify the Size property. --- src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs index 55c8f272bf..f5cfc121b9 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs @@ -270,6 +270,7 @@ public int RefCount } } + // LUCENENET TODO: Rename to Count (.NETify) /// /// Returns the number of categories in the taxonomy. Note that the number of /// categories returned is often slightly higher than the number of categories From abf096ef554a2e3a5dcba3c83a71681792761816 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sat, 24 Sep 2016 17:32:38 +0700 Subject: [PATCH 06/41] Facet.FacetResult & Facet.LabelAndValue: Fixed string format bugs by adding extra constructors to track the underlying data type of return value and formatting accordingly in ToString(). --- src/Lucene.Net.Facet/FacetResult.cs | 42 +++++++++++++++++-- src/Lucene.Net.Facet/LabelAndValue.cs | 28 ++++++++++++- .../Taxonomy/FloatAssociationFacetField.cs | 3 +- 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/src/Lucene.Net.Facet/FacetResult.cs b/src/Lucene.Net.Facet/FacetResult.cs index be619b2d1d..924f8d5c78 100644 --- a/src/Lucene.Net.Facet/FacetResult.cs +++ b/src/Lucene.Net.Facet/FacetResult.cs @@ -1,6 +1,8 @@ using System.Text; using Lucene.Net.Support; using Lucene.Net.Util; +using System.Globalization; +using System; namespace Lucene.Net.Facet { @@ -51,12 +53,39 @@ public sealed class FacetResult public readonly LabelAndValue[] LabelValues; /// - /// Sole constructor. + /// The original data type of that was passed through the constructor. + /// + public readonly Type typeOfValue; + + /// + /// Constructor for . Makes the method + /// print the as a with at least 1 number after the decimal. + /// public FacetResult(string dim, string[] path, float value, LabelAndValue[] labelValues, int childCount) + : this(dim, path, labelValues, childCount) + { + this.Value = value; + this.typeOfValue = typeof(float); + } + + /// + /// Constructor for . Makes the method + /// print the as an with no decimal. + /// + public FacetResult(string dim, string[] path, int value, LabelAndValue[] labelValues, int childCount) + : this(dim, path, labelValues, childCount) + { + this.Value = value; + this.typeOfValue = typeof(int); + } + + /// + /// Private constructor for shared parameters to be called by public constructors. + /// + private FacetResult(string dim, string[] path, LabelAndValue[] labelValues, int childCount) { this.Dim = dim; this.Path = path; - this.Value = value; this.LabelValues = labelValues; this.ChildCount = childCount; } @@ -69,7 +98,14 @@ public override string ToString() sb.Append(" path="); sb.Append("[" + Arrays.ToString(Path) + "]"); sb.Append(" value="); - sb.Append(Value); + if (typeOfValue == typeof(int)) + { + sb.AppendFormat(CultureInfo.InvariantCulture, "{0:0}", Value); // No formatting (looks like int) + } + else + { + sb.AppendFormat(CultureInfo.InvariantCulture, "{0:0.0#####}", Value); // Decimal formatting + } sb.Append(" childCount="); sb.Append(ChildCount); sb.Append('\n'); diff --git a/src/Lucene.Net.Facet/LabelAndValue.cs b/src/Lucene.Net.Facet/LabelAndValue.cs index 0cbcddc34f..6cf1991553 100644 --- a/src/Lucene.Net.Facet/LabelAndValue.cs +++ b/src/Lucene.Net.Facet/LabelAndValue.cs @@ -1,4 +1,6 @@ using Lucene.Net.Support; +using System; +using System.Globalization; namespace Lucene.Net.Facet { @@ -35,16 +37,38 @@ public sealed class LabelAndValue public readonly float value; /// - /// Sole constructor. + /// The original data type of that was passed through the constructor. + /// + public readonly Type typeOfValue; + + /// + /// Constructor for . Makes the method + /// print the as a with at least 1 number after the decimal. + /// public LabelAndValue(string label, float value) { this.label = label; this.value = value; + this.typeOfValue = typeof(float); + } + + /// + /// Constructor for . Makes the method + /// print the as an with no decimal. + /// + public LabelAndValue(string label, int value) + { + this.label = label; + this.value = value; + this.typeOfValue = typeof(int); } public override string ToString() { - return label + " (" + value + ")"; + string valueString = (typeOfValue == typeof(int)) + ? value.ToString("0", CultureInfo.InvariantCulture) + : value.ToString("0.0#####", CultureInfo.InvariantCulture); + return label + " (" + valueString + ")"; } public override bool Equals(object _other) diff --git a/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs b/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs index cc90e61b91..54e8ef2053 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs @@ -1,4 +1,5 @@ using Lucene.Net.Support; +using System.Globalization; namespace Lucene.Net.Facet.Taxonomy { @@ -58,7 +59,7 @@ public static float bytesRefToFloat(BytesRef b) public override string ToString() { - return "FloatAssociationFacetField(dim=" + dim + " path=" + Arrays.ToString(path) + " value=" + bytesRefToFloat(assoc) + ")"; + return "FloatAssociationFacetField(dim=" + dim + " path=" + Arrays.ToString(path) + " value=" + bytesRefToFloat(assoc).ToString("0.0#####", CultureInfo.InvariantCulture) + ")"; } } From 4b87de01204d603d2de96e04fba6a62425bf6381 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sat, 24 Sep 2016 19:19:06 +0700 Subject: [PATCH 07/41] Fixed wrong exception thrown from Facet.SortedSet.SortedSetDocValuesFacetCounts as well as the wrong expected exception in its test. --- .../SortedSet/SortedSetDocValuesFacetCounts.cs | 4 +--- .../SortedSet/TestSortedSetDocValuesFacets.cs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs index 8ccb190cac..509b4737c8 100644 --- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs +++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading; -using Lucene.Net.Facet; namespace Lucene.Net.Facet.SortedSet { @@ -191,7 +189,7 @@ private void Count(IList matchingDocs) // AIOOBE can happen: if (!Equals(ReaderUtil.GetTopLevelContext(hits.context).Reader, origReader)) { - throw new ThreadStateException("the SortedSetDocValuesReaderState provided to this class does not match the reader being searched; you must create a new SortedSetDocValuesReaderState every time you open a new IndexReader"); + throw new InvalidOperationException("the SortedSetDocValuesReaderState provided to this class does not match the reader being searched; you must create a new SortedSetDocValuesReaderState every time you open a new IndexReader"); } SortedSetDocValues segValues = reader.GetSortedSetDocValues(field); diff --git a/src/Lucene.Net.Tests.Facet/SortedSet/TestSortedSetDocValuesFacets.cs b/src/Lucene.Net.Tests.Facet/SortedSet/TestSortedSetDocValuesFacets.cs index 7b42c5530e..75cf9d3ea7 100644 --- a/src/Lucene.Net.Tests.Facet/SortedSet/TestSortedSetDocValuesFacets.cs +++ b/src/Lucene.Net.Tests.Facet/SortedSet/TestSortedSetDocValuesFacets.cs @@ -135,7 +135,7 @@ public virtual void TestStaleState() new SortedSetDocValuesFacetCounts(state, c); Fail("did not hit expected exception"); } - catch (IllegalStateException) + catch (InvalidOperationException) { // expected } From 44f7d9c833ae4695bc643041d6e2c9083a721fb6 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sat, 24 Sep 2016 20:09:24 +0700 Subject: [PATCH 08/41] Fixed sorting bugs in Facet.FacetTestCase. Need to sort the list that was passed into the method, not create a new one. --- src/Lucene.Net.Tests.Facet/FacetTestCase.cs | 12 ++++-------- .../SortedSet/TestSortedSetDocValuesFacets.cs | 6 +++--- .../Taxonomy/TestTaxonomyFacetCounts.cs | 4 ++-- .../Taxonomy/TestTaxonomyFacetSumValueSource.cs | 4 ++-- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/Lucene.Net.Tests.Facet/FacetTestCase.cs b/src/Lucene.Net.Tests.Facet/FacetTestCase.cs index 977d13b5bb..0c71f32a04 100644 --- a/src/Lucene.Net.Tests.Facet/FacetTestCase.cs +++ b/src/Lucene.Net.Tests.Facet/FacetTestCase.cs @@ -182,11 +182,9 @@ public virtual int Compare(LabelAndValue a, LabelAndValue b) } } - protected internal virtual void SortLabelValues(IList labelValues) + protected internal virtual void SortLabelValues(List labelValues) { - var resArray = labelValues.ToArray(); - Array.Sort(resArray,new ComparatorAnonymousInnerClassHelper2(this)); - labelValues = resArray.ToList(); + labelValues.Sort(new ComparatorAnonymousInnerClassHelper2(this)); } private class ComparatorAnonymousInnerClassHelper2 : IComparer @@ -215,11 +213,9 @@ public virtual int Compare(LabelAndValue a, LabelAndValue b) } } - protected internal virtual void SortFacetResults(IList results) + protected internal virtual void SortFacetResults(List results) { - var resArray = results.ToArray(); - Array.Sort(resArray, new ComparatorAnonymousInnerClassHelper3(this)); - results = resArray.ToList(); + results.Sort(new ComparatorAnonymousInnerClassHelper3(this)); } private class ComparatorAnonymousInnerClassHelper3 : IComparer diff --git a/src/Lucene.Net.Tests.Facet/SortedSet/TestSortedSetDocValuesFacets.cs b/src/Lucene.Net.Tests.Facet/SortedSet/TestSortedSetDocValuesFacets.cs index 75cf9d3ea7..fe385d140e 100644 --- a/src/Lucene.Net.Tests.Facet/SortedSet/TestSortedSetDocValuesFacets.cs +++ b/src/Lucene.Net.Tests.Facet/SortedSet/TestSortedSetDocValuesFacets.cs @@ -359,10 +359,10 @@ public virtual void TestRandom() } } - IList expected = new List(); + List expected = new List(); for (int i = 0; i < numDims; i++) { - IList labelValues = new List(); + List labelValues = new List(); int totCount = 0; foreach (KeyValuePair ent in expectedCounts[i]) { @@ -384,7 +384,7 @@ public virtual void TestRandom() // Messy: fixup ties //sortTies(actual); - Assert.AreEqual(expected, actual); + CollectionAssert.AreEqual(expected, actual); } IOUtils.Close(w, searcher.IndexReader, indexDir, taxoDir); diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs index 72390e2353..e4ddc51d42 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs @@ -816,10 +816,10 @@ public virtual void TestRandom() } } - IList expected = new List(); + List expected = new List(); for (int i = 0; i < numDims; i++) { - IList labelValues = new List(); + List labelValues = new List(); int totCount = 0; foreach (KeyValuePair ent in expectedCounts[i]) { diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetSumValueSource.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetSumValueSource.cs index e05daa99f6..d8edbb5774 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetSumValueSource.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetSumValueSource.cs @@ -569,10 +569,10 @@ public virtual void TestRandom() } } - IList expected = new List(); + List expected = new List(); for (int i = 0; i < numDims; i++) { - IList labelValues = new List(); + List labelValues = new List(); float totValue = 0; foreach (KeyValuePair ent in expectedValues[i]) { From e9302a877437b8a5197756201a16d3a907301504 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sat, 24 Sep 2016 20:30:05 +0700 Subject: [PATCH 09/41] Fixed Facet.FacetTestCase.SortTies() to include a sort length rather than end index. --- src/Lucene.Net.Tests.Facet/FacetTestCase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Lucene.Net.Tests.Facet/FacetTestCase.cs b/src/Lucene.Net.Tests.Facet/FacetTestCase.cs index 0c71f32a04..ccc5cdfdb1 100644 --- a/src/Lucene.Net.Tests.Facet/FacetTestCase.cs +++ b/src/Lucene.Net.Tests.Facet/FacetTestCase.cs @@ -154,7 +154,7 @@ protected internal virtual void SortTies(LabelAndValue[] labelValues) { if (numInRow > 1) { - Array.Sort(labelValues, i - numInRow, i, new ComparatorAnonymousInnerClassHelper(this)); + Array.Sort(labelValues, i - numInRow, i - (i - numInRow), new ComparatorAnonymousInnerClassHelper(this)); } numInRow = 1; if (i < labelValues.Length) From 2b718fb47402f644b304c2e1c6ce6e617d08327d Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sat, 24 Sep 2016 22:42:56 +0700 Subject: [PATCH 10/41] Fixed bug in Facet.Taxonomy.TestTaxonomyFacetCounts.TestBasic() where the output wasn't being written to because of a missing StreamWriter. --- .../Taxonomy/TestTaxonomyFacetCounts.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs index e4ddc51d42..51d0794673 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs @@ -50,6 +50,8 @@ namespace Lucene.Net.Facet.Taxonomy using Directory = Lucene.Net.Store.Directory; using IOUtils = Lucene.Net.Util.IOUtils; using TestUtil = Lucene.Net.Util.TestUtil; + using System.Text; + [TestFixture] public class TestTaxonomyFacetCounts : FacetTestCase { @@ -128,9 +130,15 @@ public virtual void TestBasic() Assert.Null(facets.GetTopChildren(10, "Non exitent dim")); // Smoke test PrintTaxonomyStats: - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - PrintTaxonomyStats.PrintStats(taxoReader, Console.Out, true); - string result = bos.ToString(); + string result; + using (ByteArrayOutputStream bos = new ByteArrayOutputStream()) + { + using (StreamWriter w = new StreamWriter(bos, Encoding.UTF8, 2048, true) { AutoFlush = true }) + { + PrintTaxonomyStats.PrintStats(taxoReader, w, true); + } + result = bos.ToString(); + } Assert.True(result.IndexOf("/Author: 4 immediate children; 5 total categories", StringComparison.Ordinal) != -1); Assert.True(result.IndexOf("/Publish Date: 3 immediate children; 12 total categories", StringComparison.Ordinal) != -1); // Make sure at least a few nodes of the tree came out: From de9e8cec065d4fdae1169f39f4f4336100345f69 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sat, 24 Sep 2016 23:52:23 +0700 Subject: [PATCH 11/41] Fixed assert bug in Facet.TestDrillSideways.VerifyEquals() that caused random failures. --- src/Lucene.Net.Tests.Facet/TestDrillSideways.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Lucene.Net.Tests.Facet/TestDrillSideways.cs b/src/Lucene.Net.Tests.Facet/TestDrillSideways.cs index 366a16af59..719e2124a9 100644 --- a/src/Lucene.Net.Tests.Facet/TestDrillSideways.cs +++ b/src/Lucene.Net.Tests.Facet/TestDrillSideways.cs @@ -1259,7 +1259,7 @@ internal virtual void VerifyEquals(string[][] dimValues, IndexSearcher s, TestFa { // Tie-break facet labels are only in unicode // order with SortedSetDVFacets: - Assert.AreEqual("value @ idx=" + i, dimValues[dim][expectedOrd], fr.LabelValues[i].label); + assertEquals("value @ idx=" + i, dimValues[dim][expectedOrd], fr.LabelValues[i].label); } } } From c40662a239a4debbbbfd3e1756386e10b302f499 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sat, 24 Sep 2016 23:53:20 +0700 Subject: [PATCH 12/41] Fixed cache cleanup bug in Facet.Taxonomy.WriterCache.NameIntCacheLRU. --- .../Taxonomy/WriterCache/NameIntCacheLRU.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs index ce14f498cd..a761aea694 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; namespace Lucene.Net.Facet.Taxonomy.WriterCache { @@ -152,13 +153,13 @@ internal virtual bool MakeRoomLRU() { return false; } - IEnumerator it = cache.Keys.GetEnumerator(); - int i = 0; - - while (i < n && it.MoveNext()) + + // LUCENENET: Loop in reverse so we can safely delete + // a range of items (0 - n) without a + // "Collection was modified" conflict + for (int i = n - 1; i >= 0; i--) { - cache.Remove(it.Current); - i++; + cache.Remove(cache.Keys.ElementAt(i)); } return true; } From ae225b9eeec8ed5d3999b364b2e7a4f880347557 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 01:14:36 +0700 Subject: [PATCH 13/41] Facet: Normalized code formatting, license headers, and usings. --- src/Lucene.Net.Facet/DrillDownQuery.cs | 18 ++- src/Lucene.Net.Facet/DrillSideways.cs | 15 +-- src/Lucene.Net.Facet/DrillSidewaysQuery.cs | 16 ++- src/Lucene.Net.Facet/DrillSidewaysScorer.cs | 25 ++-- src/Lucene.Net.Facet/FacetField.cs | 2 - src/Lucene.Net.Facet/FacetResult.cs | 10 +- src/Lucene.Net.Facet/Facets.cs | 6 - src/Lucene.Net.Facet/FacetsCollector.cs | 11 +- src/Lucene.Net.Facet/FacetsConfig.cs | 28 ++--- src/Lucene.Net.Facet/LabelAndValue.cs | 9 +- src/Lucene.Net.Facet/MultiFacets.cs | 5 - .../RandomSamplingFacetsCollector.cs | 18 +-- src/Lucene.Net.Facet/Range/DoubleRange.cs | 18 +-- .../Range/DoubleRangeFacetCounts.cs | 23 ++-- src/Lucene.Net.Facet/Range/LongRange.cs | 15 +-- .../Range/LongRangeCounter.cs | 54 ++++----- .../Range/LongRangeFacetCounts.cs | 19 ++- src/Lucene.Net.Facet/Range/Range.cs | 10 +- .../Range/RangeFacetCounts.cs | 5 - .../DefaultSortedSetDocValuesReaderState.cs | 8 +- .../SortedSetDocValuesFacetCounts.cs | 17 +-- .../SortedSet/SortedSetDocValuesFacetField.cs | 3 - .../SortedSetDocValuesReaderState.cs | 5 - .../Taxonomy/AssociationFacetField.cs | 8 +- .../Taxonomy/CachedOrdinalsReader.cs | 13 +- src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs | 12 +- .../Taxonomy/Directory/Consts.cs | 6 +- .../Directory/DirectoryTaxonomyReader.cs | 30 +++-- .../Directory/DirectoryTaxonomyWriter.cs | 79 ++++++------ .../Taxonomy/Directory/TaxonomyIndexArrays.cs | 18 ++- .../Taxonomy/DocValuesOrdinalsReader.cs | 6 +- src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs | 6 +- .../Taxonomy/FastTaxonomyFacetCounts.cs | 10 +- .../Taxonomy/FloatAssociationFacetField.cs | 79 ++++++------ .../Taxonomy/FloatTaxonomyFacets.cs | 4 +- .../Taxonomy/IntAssociationFacetField.cs | 10 +- .../Taxonomy/IntTaxonomyFacets.cs | 3 - .../Taxonomy/OrdinalsReader.cs | 3 - .../Taxonomy/ParallelTaxonomyArrays.cs | 99 ++++++++-------- .../Taxonomy/PrintTaxonomyStats.cs | 6 +- .../Taxonomy/SearcherTaxonomyManager.cs | 26 ++-- .../Taxonomy/TaxonomyFacetCounts.cs | 6 +- .../TaxonomyFacetSumFloatAssociations.cs | 20 ++-- .../TaxonomyFacetSumIntAssociations.cs | 15 +-- .../Taxonomy/TaxonomyFacetSumValueSource.cs | 32 ++--- .../Taxonomy/TaxonomyFacets.cs | 5 - .../Taxonomy/TaxonomyReader.cs | 18 +-- .../Taxonomy/TaxonomyWriter.cs | 11 +- .../Taxonomy/WriterCache/CategoryPathUtils.cs | 1 - .../Taxonomy/WriterCache/CharBlockArray.cs | 6 +- .../WriterCache/Cl2oTaxonomyWriterCache.cs | 5 - .../Taxonomy/WriterCache/CollisionMap.cs | 8 +- .../WriterCache/CompactLabelToOrdinal.cs | 2 - .../Taxonomy/WriterCache/LabelToOrdinal.cs | 112 +++++++++--------- .../WriterCache/LruTaxonomyWriterCache.cs | 5 - .../WriterCache/NameHashIntCacheLRU.cs | 53 ++++----- .../Taxonomy/WriterCache/NameIntCacheLRU.cs | 23 ++-- .../WriterCache/TaxonomyWriterCache.cs | 8 +- src/Lucene.Net.Facet/TopOrdAndFloatQueue.cs | 98 ++++++++------- src/Lucene.Net.Facet/TopOrdAndIntQueue.cs | 6 - 60 files changed, 464 insertions(+), 728 deletions(-) diff --git a/src/Lucene.Net.Facet/DrillDownQuery.cs b/src/Lucene.Net.Facet/DrillDownQuery.cs index 82342826ea..d6fa03b322 100644 --- a/src/Lucene.Net.Facet/DrillDownQuery.cs +++ b/src/Lucene.Net.Facet/DrillDownQuery.cs @@ -1,12 +1,11 @@ -using System; -using System.Diagnostics; +using Lucene.Net.Support; +using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; -using Lucene.Net.Support; namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -24,17 +23,16 @@ namespace Lucene.Net.Facet * limitations under the License. */ - - using IndexReader = Lucene.Net.Index.IndexReader; - using Term = Lucene.Net.Index.Term; - using Occur = Lucene.Net.Search.BooleanClause.Occur; using BooleanClause = Lucene.Net.Search.BooleanClause; using BooleanQuery = Lucene.Net.Search.BooleanQuery; using ConstantScoreQuery = Lucene.Net.Search.ConstantScoreQuery; using Filter = Lucene.Net.Search.Filter; using FilteredQuery = Lucene.Net.Search.FilteredQuery; + using IndexReader = Lucene.Net.Index.IndexReader; using MatchAllDocsQuery = Lucene.Net.Search.MatchAllDocsQuery; + using Occur = Lucene.Net.Search.BooleanClause.Occur; using Query = Lucene.Net.Search.Query; + using Term = Lucene.Net.Index.Term; using TermQuery = Lucene.Net.Search.TermQuery; /// @@ -52,7 +50,6 @@ namespace Lucene.Net.Facet /// public sealed class DrillDownQuery : Query { - /// /// Creates a drill-down term. public static Term Term(string field, string dim, params string[] path) @@ -68,7 +65,7 @@ public static Term Term(string field, string dim, params string[] path) /// Used by clone() internal DrillDownQuery(FacetsConfig config, BooleanQuery query, IDictionary drillDownDims) { - this.query = (BooleanQuery) query.Clone(); + this.query = (BooleanQuery)query.Clone(); this.drillDownDims.AddAll(drillDownDims); this.config = config; } @@ -384,5 +381,4 @@ internal BooleanQuery BooleanQuery } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/DrillSideways.cs b/src/Lucene.Net.Facet/DrillSideways.cs index 5ba8f91153..2c71be448d 100644 --- a/src/Lucene.Net.Facet/DrillSideways.cs +++ b/src/Lucene.Net.Facet/DrillSideways.cs @@ -1,15 +1,13 @@ -using System; +using Lucene.Net.Facet.SortedSet; +using Lucene.Net.Facet.Taxonomy; +using Lucene.Net.Search; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Lucene.Net.Search; -using Lucene.Net.Facet; -using Lucene.Net.Facet.SortedSet; -using Lucene.Net.Facet.Taxonomy; namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -26,6 +24,7 @@ namespace Lucene.Net.Facet * See the License for the specific language governing permissions and * limitations under the License. */ + /// /// Computes drill down and sideways counts for the provided /// . Drill sideways counts include @@ -48,7 +47,6 @@ namespace Lucene.Net.Facet /// public class DrillSideways { - /// /// passed to constructor. protected internal readonly IndexSearcher searcher; @@ -97,7 +95,6 @@ public DrillSideways(IndexSearcher searcher, FacetsConfig config, TaxonomyReader this.state = state; } - /// /// Subclass can override to customize per-dim Facets /// impl. @@ -290,6 +287,4 @@ public DrillSidewaysResult(Facets facets, TopDocs hits) } } } - - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/DrillSidewaysQuery.cs b/src/Lucene.Net.Facet/DrillSidewaysQuery.cs index c8e782ee95..9b25dac8d8 100644 --- a/src/Lucene.Net.Facet/DrillSidewaysQuery.cs +++ b/src/Lucene.Net.Facet/DrillSidewaysQuery.cs @@ -1,9 +1,8 @@ -using System; -using Lucene.Net.Support; +using Lucene.Net.Support; +using System; namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -22,18 +21,18 @@ namespace Lucene.Net.Facet */ using AtomicReaderContext = Lucene.Net.Index.AtomicReaderContext; - using IndexReader = Lucene.Net.Index.IndexReader; + using Bits = Lucene.Net.Util.Bits; + using BulkScorer = Lucene.Net.Search.BulkScorer; using Collector = Lucene.Net.Search.Collector; using DocIdSet = Lucene.Net.Search.DocIdSet; using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; using Explanation = Lucene.Net.Search.Explanation; using Filter = Lucene.Net.Search.Filter; + using IndexReader = Lucene.Net.Index.IndexReader; using IndexSearcher = Lucene.Net.Search.IndexSearcher; using Query = Lucene.Net.Search.Query; using Scorer = Lucene.Net.Search.Scorer; - using BulkScorer = Lucene.Net.Search.BulkScorer; using Weight = Lucene.Net.Search.Weight; - using Bits = Lucene.Net.Util.Bits; /// /// Only purpose is to punch through and return a @@ -48,7 +47,8 @@ internal class DrillSidewaysQuery : Query internal readonly Query[] drillDownQueries; internal readonly bool scoreSubDocsAtOnce; - internal DrillSidewaysQuery(Query baseQuery, Collector drillDownCollector, Collector[] drillSidewaysCollectors, Query[] drillDownQueries, bool scoreSubDocsAtOnce) + internal DrillSidewaysQuery(Query baseQuery, Collector drillDownCollector, + Collector[] drillSidewaysCollectors, Query[] drillDownQueries, bool scoreSubDocsAtOnce) { this.baseQuery = baseQuery; this.drillDownCollector = drillDownCollector; @@ -162,7 +162,6 @@ public override Scorer Scorer(AtomicReaderContext context, Bits acceptDocs) public override BulkScorer BulkScorer(AtomicReaderContext context, bool scoreDocsInOrder, Bits acceptDocs) { - // TODO: it could be better if we take acceptDocs // into account instead of baseScorer? Scorer baseScorer = baseWeight.Scorer(context, acceptDocs); @@ -312,5 +311,4 @@ public override bool Equals(object obj) return true; } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/DrillSidewaysScorer.cs b/src/Lucene.Net.Facet/DrillSidewaysScorer.cs index bbd00c1a3f..bd045c3a3d 100644 --- a/src/Lucene.Net.Facet/DrillSidewaysScorer.cs +++ b/src/Lucene.Net.Facet/DrillSidewaysScorer.cs @@ -1,11 +1,9 @@ using System; -using System.Diagnostics; using System.Collections.Generic; -using Scorer = Lucene.Net.Search.Scorer; +using System.Diagnostics; namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -23,20 +21,18 @@ namespace Lucene.Net.Facet * limitations under the License. */ - using AtomicReaderContext = Lucene.Net.Index.AtomicReaderContext; - using DocsEnum = Lucene.Net.Index.DocsEnum; + using Bits = Lucene.Net.Util.Bits; + using BulkScorer = Lucene.Net.Search.BulkScorer; using Collector = Lucene.Net.Search.Collector; using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; + using DocsEnum = Lucene.Net.Index.DocsEnum; + using FixedBitSet = Lucene.Net.Util.FixedBitSet; using Scorer = Lucene.Net.Search.Scorer; - using BulkScorer = Lucene.Net.Search.BulkScorer; using Weight = Lucene.Net.Search.Weight; - using Bits = Lucene.Net.Util.Bits; - using FixedBitSet = Lucene.Net.Util.FixedBitSet; internal class DrillSidewaysScorer : BulkScorer { - //private static boolean DEBUG = false; private readonly Collector drillDownCollector; @@ -56,7 +52,8 @@ internal class DrillSidewaysScorer : BulkScorer private int collectDocID = -1; private float collectScore; - internal DrillSidewaysScorer(AtomicReaderContext context, Scorer baseScorer, Collector drillDownCollector, DocsAndCost[] dims, bool scoreSubDocsAtOnce) + internal DrillSidewaysScorer(AtomicReaderContext context, Scorer baseScorer, + Collector drillDownCollector, DocsAndCost[] dims, bool scoreSubDocsAtOnce) { this.dims = dims; this.context = context; @@ -177,7 +174,8 @@ public override bool Score(Collector collector, int maxDoc) /// this case we just .next() on base and .advance() on /// the dim filters. /// - private void DoQueryFirstScoring(Collector collector, DocIdSetIterator[] disis, Collector[] sidewaysCollectors, Bits[] bits, Collector[] bitsSidewaysCollectors) + private void DoQueryFirstScoring(Collector collector, DocIdSetIterator[] disis, + Collector[] sidewaysCollectors, Bits[] bits, Collector[] bitsSidewaysCollectors) { //if (DEBUG) { // System.out.println(" doQueryFirstScoring"); @@ -258,9 +256,9 @@ private void DoQueryFirstScoring(Collector collector, DocIdSetIterator[] disis, } docID = baseScorer.NextDoc(); - nextDocContinue: ; + nextDocContinue:; } - nextDocBreak: ; + nextDocBreak:; } /// @@ -822,5 +820,4 @@ public virtual int CompareTo(DocsAndCost other) } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/FacetField.cs b/src/Lucene.Net.Facet/FacetField.cs index a11e5cfc09..5c85936966 100644 --- a/src/Lucene.Net.Facet/FacetField.cs +++ b/src/Lucene.Net.Facet/FacetField.cs @@ -2,7 +2,6 @@ namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -87,5 +86,4 @@ public static void VerifyLabel(string label) } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/FacetResult.cs b/src/Lucene.Net.Facet/FacetResult.cs index 924f8d5c78..5699e6c0f2 100644 --- a/src/Lucene.Net.Facet/FacetResult.cs +++ b/src/Lucene.Net.Facet/FacetResult.cs @@ -1,12 +1,10 @@ -using System.Text; -using Lucene.Net.Support; -using Lucene.Net.Util; -using System.Globalization; +using Lucene.Net.Support; using System; +using System.Globalization; +using System.Text; namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -28,7 +26,6 @@ namespace Lucene.Net.Facet /// Counts or aggregates for a single dimension. public sealed class FacetResult { - /// /// Dimension that was requested. public readonly string Dim; @@ -136,5 +133,4 @@ public override int GetHashCode() return hashCode; } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Facets.cs b/src/Lucene.Net.Facet/Facets.cs index f0461273c9..405d1b3adf 100644 --- a/src/Lucene.Net.Facet/Facets.cs +++ b/src/Lucene.Net.Facet/Facets.cs @@ -1,10 +1,7 @@ using System.Collections.Generic; -using Lucene.Net.Support; -using Lucene.Net.Facet; namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -22,7 +19,6 @@ namespace Lucene.Net.Facet * limitations under the License. */ - /// /// Common base class for all facets implementations. /// @@ -30,7 +26,6 @@ namespace Lucene.Net.Facet /// public abstract class Facets { - /// /// Default constructor. public Facets() @@ -60,5 +55,4 @@ public Facets() /// public abstract IList GetAllDims(int topN); } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/FacetsCollector.cs b/src/Lucene.Net.Facet/FacetsCollector.cs index 4bbb76ffec..07393673b2 100644 --- a/src/Lucene.Net.Facet/FacetsCollector.cs +++ b/src/Lucene.Net.Facet/FacetsCollector.cs @@ -1,12 +1,11 @@ -using System; -using System.Collections.Generic; -using Lucene.Net.Index; +using Lucene.Net.Index; using Lucene.Net.Search; using Lucene.Net.Util; +using System; +using System.Collections.Generic; namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -23,6 +22,7 @@ namespace Lucene.Net.Facet * See the License for the specific language governing permissions and * limitations under the License. */ + /// /// Collects hits for subsequent faceting. Once you've run /// a search and collect hits into this, instantiate one of @@ -33,7 +33,6 @@ namespace Lucene.Net.Facet /// public class FacetsCollector : Collector { - private AtomicReaderContext context; private Scorer scorer; private int totalHits; @@ -233,7 +232,6 @@ public override sealed AtomicReaderContext NextReader } } - /// /// Utility method, to search and also collect all hits /// into the provided . @@ -368,5 +366,4 @@ private static TopDocs DoSearch(IndexSearcher searcher, ScoreDoc after, Query q, } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/FacetsConfig.cs b/src/Lucene.Net.Facet/FacetsConfig.cs index 97ed4cf1db..a62d625ac0 100644 --- a/src/Lucene.Net.Facet/FacetsConfig.cs +++ b/src/Lucene.Net.Facet/FacetsConfig.cs @@ -1,16 +1,13 @@ using System; -using System.Diagnostics; -using System.Collections.Generic; using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; -using Lucene.Net.Facet.SortedSet; -using Lucene.Net.Facet.Taxonomy; namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -28,23 +25,22 @@ namespace Lucene.Net.Facet * limitations under the License. */ - + using ArrayUtil = Lucene.Net.Util.ArrayUtil; + using AssociationFacetField = Lucene.Net.Facet.Taxonomy.AssociationFacetField; using BinaryDocValuesField = Lucene.Net.Documents.BinaryDocValuesField; + using BytesRef = Lucene.Net.Util.BytesRef; using Document = Lucene.Net.Documents.Document; - using Field = Lucene.Net.Documents.Field; - using SortedSetDocValuesField = Lucene.Net.Documents.SortedSetDocValuesField; - using StringField = Lucene.Net.Documents.StringField; - using SortedSetDocValuesFacetField = Lucene.Net.Facet.SortedSet.SortedSetDocValuesFacetField; - using AssociationFacetField = Lucene.Net.Facet.Taxonomy.AssociationFacetField; using FacetLabel = Lucene.Net.Facet.Taxonomy.FacetLabel; + using Field = Lucene.Net.Documents.Field; using FloatAssociationFacetField = Lucene.Net.Facet.Taxonomy.FloatAssociationFacetField; - using IntAssociationFacetField = Lucene.Net.Facet.Taxonomy.IntAssociationFacetField; - using TaxonomyWriter = Lucene.Net.Facet.Taxonomy.TaxonomyWriter; using IndexableField = Lucene.Net.Index.IndexableField; using IndexableFieldType = Lucene.Net.Index.IndexableFieldType; - using ArrayUtil = Lucene.Net.Util.ArrayUtil; - using BytesRef = Lucene.Net.Util.BytesRef; + using IntAssociationFacetField = Lucene.Net.Facet.Taxonomy.IntAssociationFacetField; using IntsRef = Lucene.Net.Util.IntsRef; + using SortedSetDocValuesFacetField = Lucene.Net.Facet.SortedSet.SortedSetDocValuesFacetField; + using SortedSetDocValuesField = Lucene.Net.Documents.SortedSetDocValuesField; + using StringField = Lucene.Net.Documents.StringField; + using TaxonomyWriter = Lucene.Net.Facet.Taxonomy.TaxonomyWriter; /// /// Records per-dimension configuration. By default a @@ -63,7 +59,6 @@ namespace Lucene.Net.Facet /// public class FacetsConfig { - /// /// Which Lucene field holds the drill-downs and ords (as /// doc values). @@ -708,5 +703,4 @@ public static string[] StringToPath(string s) return parts.ToArray(); } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/LabelAndValue.cs b/src/Lucene.Net.Facet/LabelAndValue.cs index 6cf1991553..1503e3e156 100644 --- a/src/Lucene.Net.Facet/LabelAndValue.cs +++ b/src/Lucene.Net.Facet/LabelAndValue.cs @@ -1,10 +1,8 @@ -using Lucene.Net.Support; -using System; +using System; using System.Globalization; namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -65,8 +63,8 @@ public LabelAndValue(string label, int value) public override string ToString() { - string valueString = (typeOfValue == typeof(int)) - ? value.ToString("0", CultureInfo.InvariantCulture) + string valueString = (typeOfValue == typeof(int)) + ? value.ToString("0", CultureInfo.InvariantCulture) : value.ToString("0.0#####", CultureInfo.InvariantCulture); return label + " (" + valueString + ")"; } @@ -86,5 +84,4 @@ public override int GetHashCode() return label.GetHashCode() + 1439 * value.GetHashCode(); } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/MultiFacets.cs b/src/Lucene.Net.Facet/MultiFacets.cs index b40772ed64..051de44946 100644 --- a/src/Lucene.Net.Facet/MultiFacets.cs +++ b/src/Lucene.Net.Facet/MultiFacets.cs @@ -1,10 +1,7 @@ using System.Collections.Generic; -using Lucene.Net.Facet; -using Lucene.Net.Support; namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -22,7 +19,6 @@ namespace Lucene.Net.Facet * limitations under the License. */ - /// /// Maps specified dims to provided Facets impls; else, uses /// the default Facets impl. @@ -99,5 +95,4 @@ public override IList GetAllDims(int topN) return results; } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs b/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs index 47bb029f9a..a662b6a958 100644 --- a/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs +++ b/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs @@ -1,12 +1,9 @@ using System; using System.Collections.Generic; using System.IO; -using Lucene.Net.Facet; -using Lucene.Net.Search; namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -24,13 +21,12 @@ namespace Lucene.Net.Facet * limitations under the License. */ - using DimConfig = FacetsConfig.DimConfig; - using IndexReader = Lucene.Net.Index.IndexReader; - using Term = Lucene.Net.Index.Term; using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; - using IndexSearcher = Lucene.Net.Search.IndexSearcher; using FixedBitSet = Lucene.Net.Util.FixedBitSet; + using IndexReader = Lucene.Net.Index.IndexReader; + using IndexSearcher = Lucene.Net.Search.IndexSearcher; + using Term = Lucene.Net.Index.Term; /// /// Collects hits for subsequent faceting, using sampling if needed. Once you've @@ -47,18 +43,15 @@ namespace Lucene.Net.Facet /// public class RandomSamplingFacetsCollector : FacetsCollector { - /// /// Faster alternative for java.util.Random, inspired by - /// http://dmurphy747.wordpress.com/2011/03/23/xorshift-vs-random- - /// performance-in-java/ + /// http://dmurphy747.wordpress.com/2011/03/23/xorshift-vs-random-performance-in-java/ /// /// Has a period of 2^64-1 /// /// private class XORShift64Random { - internal long x; /// @@ -85,7 +78,6 @@ public virtual int NextInt(int n) int res = (int)(RandomLong() % n); return (res < 0) ? -res : res; } - } private const int NOT_CALCULATED = -1; @@ -317,7 +309,5 @@ public virtual double SamplingRate return samplingRate; } } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Range/DoubleRange.cs b/src/Lucene.Net.Facet/Range/DoubleRange.cs index 8ad1439e88..28685d4e4e 100644 --- a/src/Lucene.Net.Facet/Range/DoubleRange.cs +++ b/src/Lucene.Net.Facet/Range/DoubleRange.cs @@ -1,10 +1,7 @@ -using System; -using System.Collections.Generic; -using Lucene.Net.Support; +using System.Collections.Generic; namespace Lucene.Net.Facet.Range { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -22,15 +19,14 @@ namespace Lucene.Net.Facet.Range * limitations under the License. */ - using AtomicReaderContext = Lucene.Net.Index.AtomicReaderContext; - using FunctionValues = Lucene.Net.Queries.Function.FunctionValues; - using ValueSource = Lucene.Net.Queries.Function.ValueSource; + using Bits = Lucene.Net.Util.Bits; using DocIdSet = Lucene.Net.Search.DocIdSet; using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; using Filter = Lucene.Net.Search.Filter; - using Bits = Lucene.Net.Util.Bits; + using FunctionValues = Lucene.Net.Queries.Function.FunctionValues; using NumericUtils = Lucene.Net.Util.NumericUtils; + using ValueSource = Lucene.Net.Queries.Function.ValueSource; /// /// Represents a range over double values. @@ -138,7 +134,6 @@ public FilterAnonymousInnerClassHelper(DoubleRange outerInstance, Filter fastMat this.valueSource = valueSource; } - public override string ToString() { return "Filter(" + outerInstance.ToString() + ")"; @@ -152,7 +147,7 @@ public override DocIdSet GetDocIdSet(AtomicReaderContext context, Bits acceptDoc // ValueSourceRangeFilter (solr); also, // https://issues.apache.org/jira/browse/LUCENE-4251 - var values = valueSource.GetValues(new Dictionary(), context); + var values = valueSource.GetValues(new Dictionary(), context); int maxDoc = context.Reader.MaxDoc; @@ -197,7 +192,6 @@ public DocIdSetAnonymousInnerClassHelper(FilterAnonymousInnerClassHelper outerIn this.fastMatchBits = fastMatchBits; } - public override Bits GetBits() { return new BitsAnonymousInnerClassHelper(this); @@ -238,6 +232,4 @@ public override DocIdSetIterator GetIterator() } } } - - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs b/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs index d0163d7345..1e3a99618f 100644 --- a/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs +++ b/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs @@ -1,10 +1,7 @@ using System.Collections.Generic; -using Lucene.Net.Facet; -using Lucene.Net.Support; namespace Lucene.Net.Facet.Range { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -22,19 +19,15 @@ namespace Lucene.Net.Facet.Range * limitations under the License. */ - - using DoubleDocValuesField = Lucene.Net.Documents.DoubleDocValuesField; // javadocs - using FloatDocValuesField = Lucene.Net.Documents.FloatDocValuesField; // javadocs - using MatchingDocs = FacetsCollector.MatchingDocs; - using FunctionValues = Lucene.Net.Queries.Function.FunctionValues; - using ValueSource = Lucene.Net.Queries.Function.ValueSource; - using DoubleFieldSource = Lucene.Net.Queries.Function.ValueSources.DoubleFieldSource; - using FloatFieldSource = Lucene.Net.Queries.Function.ValueSources.FloatFieldSource; // javadocs - using DocIdSet = Lucene.Net.Search.DocIdSet; - using Filter = Lucene.Net.Search.Filter; using Bits = Lucene.Net.Util.Bits; + using DocIdSet = Lucene.Net.Search.DocIdSet; using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; + using DoubleFieldSource = Lucene.Net.Queries.Function.ValueSources.DoubleFieldSource; + using Filter = Lucene.Net.Search.Filter; + using FunctionValues = Lucene.Net.Queries.Function.FunctionValues; + using MatchingDocs = FacetsCollector.MatchingDocs; using NumericUtils = Lucene.Net.Util.NumericUtils; + using ValueSource = Lucene.Net.Queries.Function.ValueSource; /// /// implementation that computes counts for @@ -58,7 +51,6 @@ namespace Lucene.Net.Facet.Range /// public class DoubleRangeFacetCounts : RangeFacetCounts { - /// /// Create {@code RangeFacetCounts}, using {@link /// DoubleFieldSource} from the specified field. @@ -107,7 +99,7 @@ private void Count(ValueSource valueSource, IEnumerable matchingDo int missingCount = 0; foreach (MatchingDocs hits in matchingDocs) { - FunctionValues fv = valueSource.GetValues(new Dictionary(), hits.context); + FunctionValues fv = valueSource.GetValues(new Dictionary(), hits.context); TotCount += hits.totalHits; Bits bits; @@ -156,5 +148,4 @@ private void Count(ValueSource valueSource, IEnumerable matchingDo TotCount -= missingCount; } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Range/LongRange.cs b/src/Lucene.Net.Facet/Range/LongRange.cs index 52da204cf2..7a4f0c1fa0 100644 --- a/src/Lucene.Net.Facet/Range/LongRange.cs +++ b/src/Lucene.Net.Facet/Range/LongRange.cs @@ -1,9 +1,7 @@ using System.Collections.Generic; -using Lucene.Net.Support; namespace Lucene.Net.Facet.Range { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -21,14 +19,13 @@ namespace Lucene.Net.Facet.Range * limitations under the License. */ - using AtomicReaderContext = Lucene.Net.Index.AtomicReaderContext; - using FunctionValues = Lucene.Net.Queries.Function.FunctionValues; - using ValueSource = Lucene.Net.Queries.Function.ValueSource; + using Bits = Lucene.Net.Util.Bits; using DocIdSet = Lucene.Net.Search.DocIdSet; using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; using Filter = Lucene.Net.Search.Filter; - using Bits = Lucene.Net.Util.Bits; + using FunctionValues = Lucene.Net.Queries.Function.FunctionValues; + using ValueSource = Lucene.Net.Queries.Function.ValueSource; /// /// Represents a range over long values. @@ -147,7 +144,7 @@ public override DocIdSet GetDocIdSet(AtomicReaderContext context, Bits acceptDoc // ValueSourceRangeFilter (solr); also, // https://issues.apache.org/jira/browse/LUCENE-4251 - FunctionValues values = valueSource.GetValues(new Dictionary(), context); + FunctionValues values = valueSource.GetValues(new Dictionary(), context); int maxDoc = context.Reader.MaxDoc; @@ -220,7 +217,7 @@ public virtual bool Get(int docID) return outerInstance.outerInstance.outerInstance.accept(outerInstance.values.LongVal(docID)); } - + public virtual int Length() { return outerInstance.maxDoc; @@ -231,9 +228,7 @@ public override DocIdSetIterator GetIterator() { throw new System.NotSupportedException("this filter can only be accessed via bits()"); } - } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Range/LongRangeCounter.cs b/src/Lucene.Net.Facet/Range/LongRangeCounter.cs index 98123c246c..43ef3b4652 100644 --- a/src/Lucene.Net.Facet/Range/LongRangeCounter.cs +++ b/src/Lucene.Net.Facet/Range/LongRangeCounter.cs @@ -1,10 +1,9 @@ -using System.Diagnostics; -using System.Collections.Generic; +using System.Collections.Generic; +using System.Diagnostics; using System.Text; namespace Lucene.Net.Facet.Range { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -22,7 +21,6 @@ namespace Lucene.Net.Facet.Range * limitations under the License. */ - /// /// Counts how many times each range was seen; /// per-hit it's just a binary search () @@ -32,7 +30,6 @@ namespace Lucene.Net.Facet.Range internal sealed class LongRangeCounter { - internal readonly LongRangeNode root; internal readonly long[] boundaries; internal readonly int[] leafCounts; @@ -56,7 +53,7 @@ public LongRangeCounter(LongRange[] ranges) foreach (LongRange range in ranges) { int? cur; - if (!endsMap.TryGetValue(range.minIncl,out cur)) + if (!endsMap.TryGetValue(range.minIncl, out cur)) { endsMap[range.minIncl] = 1; } @@ -64,8 +61,8 @@ public LongRangeCounter(LongRange[] ranges) { endsMap[range.minIncl] = (int)cur | 1; } - - if (!endsMap.TryGetValue(range.maxIncl,out cur)) + + if (!endsMap.TryGetValue(range.maxIncl, out cur)) { endsMap[range.maxIncl] = 2; } @@ -95,7 +92,7 @@ public LongRangeCounter(LongRange[] ranges) while (upto0 < endsList.Count) { - v = endsList[upto0].HasValue ? endsList[upto0].Value : 0; + v = endsList[upto0].HasValue ? endsList[upto0].Value : 0; int flags = endsMap[v].HasValue ? endsMap[v].Value : 0; //System.out.println(" v=" + v + " flags=" + flags); if (flags == 3) @@ -333,25 +330,25 @@ internal static void indent(StringBuilder sb, int depth) /// /// Recursively assigns range outputs to each node. internal void addOutputs(int index, LongRange range) - { - if (start >= range.minIncl && end <= range.maxIncl) - { - // Our range is fully included in the incoming - // range; add to our output list: - if (outputs == null) - { - outputs = new List(); - } - outputs.Add(index); - } - else if (left != null) - { - Debug.Assert(right != null); - // Recurse: - left.addOutputs(index, range); - right.addOutputs(index, range); - } - } + { + if (start >= range.minIncl && end <= range.maxIncl) + { + // Our range is fully included in the incoming + // range; add to our output list: + if (outputs == null) + { + outputs = new List(); + } + outputs.Add(index); + } + else if (left != null) + { + Debug.Assert(right != null); + // Recurse: + left.addOutputs(index, range); + right.addOutputs(index, range); + } + } internal void ToString(StringBuilder sb, int depth) { @@ -381,5 +378,4 @@ internal void ToString(StringBuilder sb, int depth) } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs b/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs index 8435bbed82..813757ded5 100644 --- a/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs +++ b/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs @@ -1,9 +1,7 @@ using System.Collections.Generic; -using Lucene.Net.Facet; namespace Lucene.Net.Facet.Range { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -21,15 +19,14 @@ namespace Lucene.Net.Facet.Range * limitations under the License. */ - - using MatchingDocs = FacetsCollector.MatchingDocs; - using FunctionValues = Lucene.Net.Queries.Function.FunctionValues; - using ValueSource = Lucene.Net.Queries.Function.ValueSource; - using LongFieldSource = Lucene.Net.Queries.Function.ValueSources.LongFieldSource; - using DocIdSet = Lucene.Net.Search.DocIdSet; - using Filter = Lucene.Net.Search.Filter; using Bits = Lucene.Net.Util.Bits; + using DocIdSet = Lucene.Net.Search.DocIdSet; using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; + using Filter = Lucene.Net.Search.Filter; + using FunctionValues = Lucene.Net.Queries.Function.FunctionValues; + using LongFieldSource = Lucene.Net.Queries.Function.ValueSources.LongFieldSource; + using MatchingDocs = FacetsCollector.MatchingDocs; + using ValueSource = Lucene.Net.Queries.Function.ValueSource; /// /// implementation that computes counts for @@ -71,7 +68,8 @@ public LongRangeFacetCounts(string field, ValueSource valueSource, FacetsCollect /// checked for the matching ranges. The filter must be /// random access (implement ). /// - public LongRangeFacetCounts(string field, ValueSource valueSource, FacetsCollector hits, Filter fastMatchFilter, params LongRange[] ranges) + public LongRangeFacetCounts(string field, ValueSource valueSource, + FacetsCollector hits, Filter fastMatchFilter, params LongRange[] ranges) : base(field, ranges, fastMatchFilter) { Count(valueSource, hits.GetMatchingDocs); @@ -139,5 +137,4 @@ private void Count(ValueSource valueSource, IList matchingDocs) TotCount -= missingCount; } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Range/Range.cs b/src/Lucene.Net.Facet/Range/Range.cs index 548b9155da..c207031ebf 100644 --- a/src/Lucene.Net.Facet/Range/Range.cs +++ b/src/Lucene.Net.Facet/Range/Range.cs @@ -1,8 +1,5 @@ -using Lucene.Net.Facet; - -namespace Lucene.Net.Facet.Range +namespace Lucene.Net.Facet.Range { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -20,10 +17,8 @@ namespace Lucene.Net.Facet.Range * limitations under the License. */ - using ValueSource = Lucene.Net.Queries.Function.ValueSource; using Filter = Lucene.Net.Search.Filter; - using FilteredQuery = Lucene.Net.Search.FilteredQuery; // javadocs - using Lucene.Net.Search; // javadocs + using ValueSource = Lucene.Net.Queries.Function.ValueSource; /// /// Base class for a single labeled range. @@ -86,5 +81,4 @@ protected internal virtual void FailNoMatch() throw new System.ArgumentException("range \"" + Label + "\" matches nothing"); } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Range/RangeFacetCounts.cs b/src/Lucene.Net.Facet/Range/RangeFacetCounts.cs index 29e02fb65a..53a4d26836 100644 --- a/src/Lucene.Net.Facet/Range/RangeFacetCounts.cs +++ b/src/Lucene.Net.Facet/Range/RangeFacetCounts.cs @@ -1,10 +1,7 @@ using System.Collections.Generic; -using Lucene.Net.Facet; -using Lucene.Net.Support; namespace Lucene.Net.Facet.Range { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -22,7 +19,6 @@ namespace Lucene.Net.Facet.Range * limitations under the License. */ - using Filter = Lucene.Net.Search.Filter; /// @@ -95,5 +91,4 @@ public override IList GetAllDims(int topN) return new[] { GetTopChildren(topN, null) }; } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs b/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs index 8113d80288..649135c673 100644 --- a/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs +++ b/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs @@ -1,8 +1,7 @@ -using System.Collections.Generic; -using Lucene.Net.Index; +using Lucene.Net.Index; using Lucene.Net.Support; using Lucene.Net.Util; -using Lucene.Net.Facet; +using System.Collections.Generic; namespace Lucene.Net.Facet.SortedSet { @@ -28,7 +27,6 @@ namespace Lucene.Net.Facet.SortedSet /// public class DefaultSortedSetDocValuesReaderState : SortedSetDocValuesReaderState { - private readonly string field; private readonly AtomicReader topReader; private readonly int valueCount; @@ -152,7 +150,5 @@ public override int Size return valueCount; } } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs index 509b4737c8..1039fffc67 100644 --- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs +++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs @@ -4,7 +4,6 @@ namespace Lucene.Net.Facet.SortedSet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -22,18 +21,13 @@ namespace Lucene.Net.Facet.SortedSet * limitations under the License. */ - - using MatchingDocs = FacetsCollector.MatchingDocs; - using OrdRange = Lucene.Net.Facet.SortedSet.SortedSetDocValuesReaderState.OrdRange; - using AtomicReader = Lucene.Net.Index.AtomicReader; + using BytesRef = Lucene.Net.Util.BytesRef; + using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; using IndexReader = Lucene.Net.Index.IndexReader; using MultiDocValues = Lucene.Net.Index.MultiDocValues; - using MultiSortedSetDocValues = Lucene.Net.Index.MultiDocValues.MultiSortedSetDocValues; + using OrdRange = Lucene.Net.Facet.SortedSet.SortedSetDocValuesReaderState.OrdRange; using ReaderUtil = Lucene.Net.Index.ReaderUtil; using SortedSetDocValues = Lucene.Net.Index.SortedSetDocValues; - using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; - using BytesRef = Lucene.Net.Util.BytesRef; - using LongValues = Lucene.Net.Util.LongValues; /// /// Compute facets counts from previously @@ -58,7 +52,6 @@ namespace Lucene.Net.Facet.SortedSet /// public class SortedSetDocValuesFacetCounts : Facets { - internal readonly SortedSetDocValuesReaderState state; internal readonly SortedSetDocValues dv; internal readonly string field; @@ -98,7 +91,6 @@ public override FacetResult GetTopChildren(int topN, string dim, params string[] private FacetResult GetDim(string dim, OrdRange ordRange, int topN) { - TopOrdAndIntQueue q = null; int bottomCount = 0; @@ -180,7 +172,6 @@ private void Count(IList matchingDocs) foreach (FacetsCollector.MatchingDocs hits in matchingDocs) { - var reader = hits.context.AtomicReader; //System.out.println(" reader=" + reader); // LUCENE-5090: make sure the provided reader context "matches" @@ -301,7 +292,6 @@ public override float GetSpecificValue(string dim, params string[] path) public override IList GetAllDims(int topN) { - IList results = new List(); foreach (KeyValuePair ent in state.PrefixToOrdRange) { @@ -344,5 +334,4 @@ public virtual int Compare(FacetResult a, FacetResult b) } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetField.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetField.cs index c860d561b3..372958393a 100644 --- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetField.cs +++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetField.cs @@ -1,6 +1,5 @@ namespace Lucene.Net.Facet.SortedSet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -27,7 +26,6 @@ /// public class SortedSetDocValuesFacetField : Field { - /// /// Indexed . public static readonly FieldType TYPE = new FieldType(); @@ -61,5 +59,4 @@ public override string ToString() return "SortedSetDocValuesFacetField(dim=" + Dim + " label=" + Label + ")"; } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesReaderState.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesReaderState.cs index ef7e0fec5d..2b3c2b17ea 100644 --- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesReaderState.cs +++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesReaderState.cs @@ -2,7 +2,6 @@ namespace Lucene.Net.Facet.SortedSet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -20,7 +19,6 @@ namespace Lucene.Net.Facet.SortedSet * limitations under the License. */ - using IndexReader = Lucene.Net.Index.IndexReader; using SortedSetDocValues = Lucene.Net.Index.SortedSetDocValues; @@ -42,10 +40,8 @@ namespace Lucene.Net.Facet.SortedSet /// for a given . /// /// - public abstract class SortedSetDocValuesReaderState { - /// /// Holds start/end range of ords, which maps to one /// dimension (someday we may generalize it to map to @@ -99,5 +95,4 @@ protected internal SortedSetDocValuesReaderState() /// Number of unique labels. public abstract int Size { get; } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/AssociationFacetField.cs b/src/Lucene.Net.Facet/Taxonomy/AssociationFacetField.cs index 6113eefdbb..6092f9aecf 100644 --- a/src/Lucene.Net.Facet/Taxonomy/AssociationFacetField.cs +++ b/src/Lucene.Net.Facet/Taxonomy/AssociationFacetField.cs @@ -1,9 +1,7 @@ -using Lucene.Net.Facet; -using Lucene.Net.Support; +using Lucene.Net.Support; namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -21,10 +19,10 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ + using BytesRef = Lucene.Net.Util.BytesRef; using Document = Lucene.Net.Documents.Document; // javadocs using Field = Lucene.Net.Documents.Field; using FieldType = Lucene.Net.Documents.FieldType; - using BytesRef = Lucene.Net.Util.BytesRef; /// /// Add an instance of this to your to add @@ -39,7 +37,6 @@ namespace Lucene.Net.Facet.Taxonomy /// public class AssociationFacetField : Field { - /// /// Indexed . public static readonly FieldType TYPE = new FieldType(); @@ -87,5 +84,4 @@ public override string ToString() return "AssociationFacetField(dim=" + dim + " path=" + Arrays.ToString(path) + " bytes=" + assoc + ")"; } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/CachedOrdinalsReader.cs b/src/Lucene.Net.Facet/Taxonomy/CachedOrdinalsReader.cs index 0471f65572..70bbd26069 100644 --- a/src/Lucene.Net.Facet/Taxonomy/CachedOrdinalsReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/CachedOrdinalsReader.cs @@ -1,11 +1,10 @@ -using System; +using Lucene.Net.Support; +using System; using System.Collections.Generic; using System.Threading; -using Lucene.Net.Support; namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -23,12 +22,11 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ - - using DocValuesFormat = Lucene.Net.Codecs.DocValuesFormat; - using AtomicReaderContext = Lucene.Net.Index.AtomicReaderContext; using BinaryDocValues = Lucene.Net.Index.BinaryDocValues; using Accountable = Lucene.Net.Util.Accountable; using ArrayUtil = Lucene.Net.Util.ArrayUtil; + using DocValuesFormat = Lucene.Net.Codecs.DocValuesFormat; + using AtomicReaderContext = Lucene.Net.Index.AtomicReaderContext; using IntsRef = Lucene.Net.Util.IntsRef; using RamUsageEstimator = Lucene.Net.Util.RamUsageEstimator; @@ -62,7 +60,6 @@ namespace Lucene.Net.Facet.Taxonomy /// public class CachedOrdinalsReader : OrdinalsReader, Accountable { - private readonly OrdinalsReader source; private readonly IDictionary ordsCache = new WeakDictionary(); @@ -128,7 +125,6 @@ public override void Get(int docID, IntsRef ordinals) /// Holds the cached ordinals in two parallel {@code int[]} arrays. public sealed class CachedOrds : Accountable { - /// /// Index into for each document. public readonly int[] offsets; @@ -204,5 +200,4 @@ public virtual long RamBytesUsed() } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs b/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs index df69862687..3709b58954 100644 --- a/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs +++ b/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs @@ -1,11 +1,10 @@ -using System; +using Lucene.Net.Support; +using System; using System.Diagnostics; using System.Text; -using Lucene.Net.Support; namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -23,7 +22,6 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ - /// /// Holds a sequence of string components, specifying the hierarchical name of a /// category. @@ -32,7 +30,6 @@ namespace Lucene.Net.Facet.Taxonomy /// public class CategoryPath : IComparable { - /// /// An empty public static readonly CategoryPath EMPTY = new CategoryPath(); @@ -154,7 +151,8 @@ public virtual int CompareTo(CategoryPath other) private void hasDelimiter(string offender, char delimiter) { - throw new System.ArgumentException("delimiter character '" + delimiter + "' (U+" + delimiter.ToString() + ") appears in path component \"" + offender + "\""); + throw new System.ArgumentException("delimiter character '" + delimiter + + "' (U+" + delimiter.ToString() + ") appears in path component \"" + offender + "\""); } private void noDelimiter(char[] buf, int offset, int len, char delimiter) @@ -310,7 +308,5 @@ public virtual string ToString(char delimiter) sb.Length = sb.Length - 1; // remove last delimiter return sb.ToString(); } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/Consts.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/Consts.cs index 5b6998591e..3660ff0f3e 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/Consts.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/Consts.cs @@ -1,8 +1,5 @@ namespace Lucene.Net.Facet.Taxonomy.Directory { - - using BytesRef = Lucene.Net.Util.BytesRef; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -20,6 +17,8 @@ * limitations under the License. */ + using BytesRef = Lucene.Net.Util.BytesRef; + /// /// @lucene.experimental /// @@ -30,5 +29,4 @@ internal abstract class Consts internal const string PAYLOAD_PARENT = "p"; internal static readonly BytesRef PAYLOAD_PARENT_BYTES_REF = new BytesRef(PAYLOAD_PARENT); } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs index da82cbf4af..e540a00861 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs @@ -2,22 +2,9 @@ using System.Collections.Generic; using System.IO; using System.Text; -using Lucene.Net.Store; namespace Lucene.Net.Facet.Taxonomy.Directory { - using Document = Lucene.Net.Documents.Document; - using Lucene.Net.Facet.Taxonomy; - using CorruptIndexException = Lucene.Net.Index.CorruptIndexException; // javadocs - using DirectoryReader = Lucene.Net.Index.DirectoryReader; - using DocsEnum = Lucene.Net.Index.DocsEnum; - using IndexWriter = Lucene.Net.Index.IndexWriter; - using MultiFields = Lucene.Net.Index.MultiFields; - using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; - using Directory = Lucene.Net.Store.Directory; - using BytesRef = Lucene.Net.Util.BytesRef; - using IOUtils = Lucene.Net.Util.IOUtils; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -35,6 +22,17 @@ namespace Lucene.Net.Facet.Taxonomy.Directory * limitations under the License. */ + using Lucene.Net.Facet.Taxonomy; + using BytesRef = Lucene.Net.Util.BytesRef; + using Directory = Lucene.Net.Store.Directory; + using DirectoryReader = Lucene.Net.Index.DirectoryReader; + using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; + using DocsEnum = Lucene.Net.Index.DocsEnum; + using Document = Lucene.Net.Documents.Document; + using IndexWriter = Lucene.Net.Index.IndexWriter; + using IOUtils = Lucene.Net.Util.IOUtils; + using MultiFields = Lucene.Net.Index.MultiFields; + /// /// A which retrieves stored taxonomy information from a /// . @@ -49,7 +47,6 @@ namespace Lucene.Net.Facet.Taxonomy.Directory /// public class DirectoryTaxonomyReader : TaxonomyReader, IDisposable { - public class IntClass { public int? IntItem { get; set; } @@ -71,7 +68,9 @@ public class IntClass /// recreated, you should pass {@code null} as the caches and parent/children /// arrays. /// - internal DirectoryTaxonomyReader(DirectoryReader indexReader, DirectoryTaxonomyWriter taxoWriter, LRUHashMap ordinalCache, LRUHashMap categoryCache, TaxonomyIndexArrays taxoArrays) + internal DirectoryTaxonomyReader(DirectoryReader indexReader, DirectoryTaxonomyWriter taxoWriter, + LRUHashMap ordinalCache, LRUHashMap categoryCache, + TaxonomyIndexArrays taxoArrays) { this.indexReader = indexReader; this.taxoWriter = taxoWriter; @@ -439,5 +438,4 @@ public void Dispose() Dispose(true); } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs index 8ead122f4a..c93d0e7991 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs @@ -1,50 +1,14 @@ -using System; -using System.Collections; -using System.Collections.Concurrent; -using System.Diagnostics; -using System.Collections.Generic; -using System.IO; -using Lucene.Net.Analysis.Tokenattributes; +using Lucene.Net.Analysis.Tokenattributes; using Lucene.Net.Store; using Lucene.Net.Support; using Lucene.Net.Util; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; namespace Lucene.Net.Facet.Taxonomy.Directory { - - using TokenStream = Lucene.Net.Analysis.TokenStream; - using CharTermAttribute = Lucene.Net.Analysis.Tokenattributes.CharTermAttribute; - using PositionIncrementAttribute = Lucene.Net.Analysis.Tokenattributes.PositionIncrementAttribute; - using Document = Lucene.Net.Documents.Document; - using Field = Lucene.Net.Documents.Field; - using FieldType = Lucene.Net.Documents.FieldType; - using StringField = Lucene.Net.Documents.StringField; - using TextField = Lucene.Net.Documents.TextField; - using TaxonomyWriterCache = Lucene.Net.Facet.Taxonomy.WriterCache.TaxonomyWriterCache; - using Cl2oTaxonomyWriterCache = Lucene.Net.Facet.Taxonomy.WriterCache.Cl2oTaxonomyWriterCache; - using LruTaxonomyWriterCache = Lucene.Net.Facet.Taxonomy.WriterCache.LruTaxonomyWriterCache; - using AtomicReader = Lucene.Net.Index.AtomicReader; - using AtomicReaderContext = Lucene.Net.Index.AtomicReaderContext; - using CorruptIndexException = Lucene.Net.Index.CorruptIndexException; // javadocs - using DirectoryReader = Lucene.Net.Index.DirectoryReader; - using DocsEnum = Lucene.Net.Index.DocsEnum; - using IndexReader = Lucene.Net.Index.IndexReader; - using IndexWriter = Lucene.Net.Index.IndexWriter; - using OpenMode = Lucene.Net.Index.IndexWriterConfig.OpenMode_e; - using IndexWriterConfig = Lucene.Net.Index.IndexWriterConfig; - using LogByteSizeMergePolicy = Lucene.Net.Index.LogByteSizeMergePolicy; - using ReaderManager = Lucene.Net.Index.ReaderManager; - using SegmentInfos = Lucene.Net.Index.SegmentInfos; - using Terms = Lucene.Net.Index.Terms; - using TermsEnum = Lucene.Net.Index.TermsEnum; - using TieredMergePolicy = Lucene.Net.Index.TieredMergePolicy; - using AlreadyClosedException = Lucene.Net.Store.AlreadyClosedException; - using Directory = Lucene.Net.Store.Directory; - using LockObtainFailedException = Lucene.Net.Store.LockObtainFailedException; // javadocs - using NativeFSLockFactory = Lucene.Net.Store.NativeFSLockFactory; - using SimpleFSLockFactory = Lucene.Net.Store.SimpleFSLockFactory; - using BytesRef = Lucene.Net.Util.BytesRef; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -62,6 +26,33 @@ namespace Lucene.Net.Facet.Taxonomy.Directory * limitations under the License. */ + using AlreadyClosedException = Lucene.Net.Store.AlreadyClosedException; + using AtomicReader = Lucene.Net.Index.AtomicReader; + using AtomicReaderContext = Lucene.Net.Index.AtomicReaderContext; + using LockObtainFailedException = Lucene.Net.Store.LockObtainFailedException; // javadocs + using BytesRef = Lucene.Net.Util.BytesRef; + using Cl2oTaxonomyWriterCache = Lucene.Net.Facet.Taxonomy.WriterCache.Cl2oTaxonomyWriterCache; + using Directory = Lucene.Net.Store.Directory; + using CorruptIndexException = Lucene.Net.Index.CorruptIndexException; // javadocs + using DirectoryReader = Lucene.Net.Index.DirectoryReader; + using DocsEnum = Lucene.Net.Index.DocsEnum; + using Document = Lucene.Net.Documents.Document; + using Field = Lucene.Net.Documents.Field; + using FieldType = Lucene.Net.Documents.FieldType; + using IndexWriter = Lucene.Net.Index.IndexWriter; + using IndexWriterConfig = Lucene.Net.Index.IndexWriterConfig; + using LogByteSizeMergePolicy = Lucene.Net.Index.LogByteSizeMergePolicy; + using OpenMode = Lucene.Net.Index.IndexWriterConfig.OpenMode_e; + using ReaderManager = Lucene.Net.Index.ReaderManager; + using SegmentInfos = Lucene.Net.Index.SegmentInfos; + using StringField = Lucene.Net.Documents.StringField; + using TaxonomyWriterCache = Lucene.Net.Facet.Taxonomy.WriterCache.TaxonomyWriterCache; + using Terms = Lucene.Net.Index.Terms; + using TermsEnum = Lucene.Net.Index.TermsEnum; + using TextField = Lucene.Net.Documents.TextField; + using TieredMergePolicy = Lucene.Net.Index.TieredMergePolicy; + using TokenStream = Lucene.Net.Analysis.TokenStream; + /// /// which uses a to store the taxonomy /// information on disk, and keeps an additional in-memory cache of some or all @@ -83,7 +74,6 @@ namespace Lucene.Net.Facet.Taxonomy.Directory /// public class DirectoryTaxonomyWriter : TaxonomyWriter { - /// /// Property name of user commit data that contains the index epoch. The epoch /// changes whenever the taxonomy is recreated (i.e. opened with @@ -184,9 +174,9 @@ public static void Unlock(Directory directory) /// removed using . /// /// if another error occurred. - public DirectoryTaxonomyWriter(Directory directory, OpenMode openMode, TaxonomyWriterCache cache) + public DirectoryTaxonomyWriter(Directory directory, OpenMode openMode, + TaxonomyWriterCache cache) { - dir = directory; IndexWriterConfig config = CreateIndexWriterConfig(openMode); indexWriter = OpenIndexWriter(dir, config); @@ -1198,5 +1188,4 @@ public long TaxonomyEpoch } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/TaxonomyIndexArrays.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/TaxonomyIndexArrays.cs index 9a99f4a3e2..2319550334 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/TaxonomyIndexArrays.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/TaxonomyIndexArrays.cs @@ -3,14 +3,6 @@ namespace Lucene.Net.Facet.Taxonomy.Directory { - - using CorruptIndexException = Lucene.Net.Index.CorruptIndexException; - using DocsAndPositionsEnum = Lucene.Net.Index.DocsAndPositionsEnum; - using IndexReader = Lucene.Net.Index.IndexReader; - using MultiFields = Lucene.Net.Index.MultiFields; - using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; - using ArrayUtil = Lucene.Net.Util.ArrayUtil; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -28,6 +20,13 @@ namespace Lucene.Net.Facet.Taxonomy.Directory * limitations under the License. */ + using ArrayUtil = Lucene.Net.Util.ArrayUtil; + using CorruptIndexException = Lucene.Net.Index.CorruptIndexException; + using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; + using DocsAndPositionsEnum = Lucene.Net.Index.DocsAndPositionsEnum; + using IndexReader = Lucene.Net.Index.IndexReader; + using MultiFields = Lucene.Net.Index.MultiFields; + /// /// A that are initialized from the taxonomy /// index. @@ -36,7 +35,6 @@ namespace Lucene.Net.Facet.Taxonomy.Directory /// internal class TaxonomyIndexArrays : ParallelTaxonomyArrays { - private readonly int[] parents_Renamed; // the following two arrays are lazily intialized. note that we only keep a @@ -246,7 +244,5 @@ public override int[] Siblings() // the array is guaranteed to be populated return siblings_Renamed; } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/DocValuesOrdinalsReader.cs b/src/Lucene.Net.Facet/Taxonomy/DocValuesOrdinalsReader.cs index 3d502757bb..3d5cc53963 100644 --- a/src/Lucene.Net.Facet/Taxonomy/DocValuesOrdinalsReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/DocValuesOrdinalsReader.cs @@ -1,6 +1,5 @@ namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -18,11 +17,11 @@ * limitations under the License. */ + using ArrayUtil = Lucene.Net.Util.ArrayUtil; using AtomicReaderContext = Lucene.Net.Index.AtomicReaderContext; using BinaryDocValues = Lucene.Net.Index.BinaryDocValues; - using DocValues = Lucene.Net.Index.DocValues; - using ArrayUtil = Lucene.Net.Util.ArrayUtil; using BytesRef = Lucene.Net.Util.BytesRef; + using DocValues = Lucene.Net.Index.DocValues; using IntsRef = Lucene.Net.Util.IntsRef; /// @@ -126,5 +125,4 @@ protected virtual void Decode(BytesRef buf, IntsRef ordinals) } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs b/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs index 9a6884c821..94eb2d6ab3 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs @@ -1,10 +1,9 @@ -using System; +using Lucene.Net.Support; +using System; using System.Diagnostics; -using Lucene.Net.Support; namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -220,5 +219,4 @@ public override string ToString() return "FacetLabel: [" + Arrays.ToString(parts) + "]"; } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs b/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs index f0d5fa0192..f54b70b41a 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs @@ -1,10 +1,7 @@ using System.Collections.Generic; -using Lucene.Net.Facet; -using Lucene.Net.Search; namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -22,11 +19,10 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ - using MatchingDocs = FacetsCollector.MatchingDocs; using BinaryDocValues = Lucene.Net.Index.BinaryDocValues; - using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; using BytesRef = Lucene.Net.Util.BytesRef; + using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; /// /// Computes facets counts, assuming the default encoding @@ -36,7 +32,6 @@ namespace Lucene.Net.Facet.Taxonomy /// public class FastTaxonomyFacetCounts : IntTaxonomyFacets { - /// /// Create {@code FastTaxonomyFacetCounts}, which also /// counts all facet labels. @@ -75,7 +70,7 @@ private void Count(IList matchingDocs) BytesRef bytesRef = new BytesRef(); while ((doc = docs.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { - dv.Get(doc,bytesRef); + dv.Get(doc, bytesRef); var bytes = bytesRef.Bytes; int end = bytesRef.Offset + bytesRef.Length; int ord = 0; @@ -101,5 +96,4 @@ private void Count(IList matchingDocs) Rollup(); } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs b/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs index 54e8ef2053..a1e6c88d04 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs @@ -3,8 +3,7 @@ namespace Lucene.Net.Facet.Taxonomy { - - /* + /* * 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. @@ -21,46 +20,46 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ - using Document = Lucene.Net.Documents.Document; - using BytesRef = Lucene.Net.Util.BytesRef; - - /// - /// Add an instance of this to your to add - /// a facet label associated with a float. Use {@link - /// TaxonomyFacetSumFloatAssociations} to aggregate float values - /// per facet label at search time. - /// - /// @lucene.experimental - /// - public class FloatAssociationFacetField : AssociationFacetField - { - - /// - /// Creates this from {@code dim} and {@code path} and a - /// float association - /// - public FloatAssociationFacetField(float assoc, string dim, params string[] path) : base(floatToBytesRef(assoc), dim, path) - { - } + using BytesRef = Lucene.Net.Util.BytesRef; + using Document = Lucene.Net.Documents.Document; - /// - /// Encodes a {@code float} as a 4-byte . - public static BytesRef floatToBytesRef(float v) - { - return IntAssociationFacetField.intToBytesRef(Number.FloatToIntBits(v)); - } + /// + /// Add an instance of this to your to add + /// a facet label associated with a float. Use {@link + /// TaxonomyFacetSumFloatAssociations} to aggregate float values + /// per facet label at search time. + /// + /// @lucene.experimental + /// + public class FloatAssociationFacetField : AssociationFacetField + { + /// + /// Creates this from {@code dim} and {@code path} and a + /// float association + /// + public FloatAssociationFacetField(float assoc, string dim, params string[] path) + : base(floatToBytesRef(assoc), dim, path) + { + } - /// - /// Decodes a previously encoded {@code float}. - public static float bytesRefToFloat(BytesRef b) - { - return Number.IntBitsToFloat(IntAssociationFacetField.bytesRefToInt(b)); - } + /// + /// Encodes a {@code float} as a 4-byte . + public static BytesRef floatToBytesRef(float v) + { + return IntAssociationFacetField.intToBytesRef(Number.FloatToIntBits(v)); + } - public override string ToString() - { - return "FloatAssociationFacetField(dim=" + dim + " path=" + Arrays.ToString(path) + " value=" + bytesRefToFloat(assoc).ToString("0.0#####", CultureInfo.InvariantCulture) + ")"; - } - } + /// + /// Decodes a previously encoded {@code float}. + public static float bytesRefToFloat(BytesRef b) + { + return Number.IntBitsToFloat(IntAssociationFacetField.bytesRefToInt(b)); + } + public override string ToString() + { + return "FloatAssociationFacetField(dim=" + dim + " path=" + Arrays.ToString(path) + + " value=" + bytesRefToFloat(assoc).ToString("0.0#####", CultureInfo.InvariantCulture) + ")"; + } + } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/FloatTaxonomyFacets.cs b/src/Lucene.Net.Facet/Taxonomy/FloatTaxonomyFacets.cs index 3921540d7a..e0b36886d6 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FloatTaxonomyFacets.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FloatTaxonomyFacets.cs @@ -1,10 +1,9 @@ using System; -using System.Diagnostics; using System.Collections.Generic; +using System.Diagnostics; namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -30,7 +29,6 @@ namespace Lucene.Net.Facet.Taxonomy /// public abstract class FloatTaxonomyFacets : TaxonomyFacets { - /// /// Per-ordinal value. protected readonly float[] values; diff --git a/src/Lucene.Net.Facet/Taxonomy/IntAssociationFacetField.cs b/src/Lucene.Net.Facet/Taxonomy/IntAssociationFacetField.cs index 61d81774cc..417fbd6a8c 100644 --- a/src/Lucene.Net.Facet/Taxonomy/IntAssociationFacetField.cs +++ b/src/Lucene.Net.Facet/Taxonomy/IntAssociationFacetField.cs @@ -2,7 +2,6 @@ namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -20,8 +19,8 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ - using Document = Lucene.Net.Documents.Document; using BytesRef = Lucene.Net.Util.BytesRef; + using Document = Lucene.Net.Documents.Document; /// /// Add an instance of this to your to add @@ -33,7 +32,6 @@ namespace Lucene.Net.Facet.Taxonomy /// public class IntAssociationFacetField : AssociationFacetField { - /// /// Creates this from {@code dim} and {@code path} and an /// int association @@ -49,7 +47,7 @@ public IntAssociationFacetField(int assoc, string dim, params string[] path) /// public static BytesRef intToBytesRef(int v) { - + byte[] bytes = new byte[4]; // big-endian: bytes[0] = (byte)(v >> 24); @@ -63,7 +61,8 @@ public static BytesRef intToBytesRef(int v) /// Decodes a previously encoded {@code int}. public static int bytesRefToInt(BytesRef b) { - return ((b.Bytes[b.Offset] & 0xFF) << 24) | ((b.Bytes[b.Offset + 1] & 0xFF) << 16) | ((b.Bytes[b.Offset + 2] & 0xFF) << 8) | (b.Bytes[b.Offset + 3] & 0xFF); + return ((b.Bytes[b.Offset] & 0xFF) << 24) | ((b.Bytes[b.Offset + 1] & 0xFF) << 16) | + ((b.Bytes[b.Offset + 2] & 0xFF) << 8) | (b.Bytes[b.Offset + 3] & 0xFF); } public override string ToString() @@ -71,5 +70,4 @@ public override string ToString() return "IntAssociationFacetField(dim=" + dim + " path=" + Arrays.ToString(path) + " value=" + bytesRefToInt(assoc) + ")"; } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/IntTaxonomyFacets.cs b/src/Lucene.Net.Facet/Taxonomy/IntTaxonomyFacets.cs index f73f167347..11f76f05a6 100644 --- a/src/Lucene.Net.Facet/Taxonomy/IntTaxonomyFacets.cs +++ b/src/Lucene.Net.Facet/Taxonomy/IntTaxonomyFacets.cs @@ -3,7 +3,6 @@ namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -21,7 +20,6 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ - using DimConfig = Lucene.Net.Facet.FacetsConfig.DimConfig; /// @@ -31,7 +29,6 @@ namespace Lucene.Net.Facet.Taxonomy public abstract class IntTaxonomyFacets : TaxonomyFacets { - /// /// Per-ordinal value. protected internal readonly int[] values; diff --git a/src/Lucene.Net.Facet/Taxonomy/OrdinalsReader.cs b/src/Lucene.Net.Facet/Taxonomy/OrdinalsReader.cs index 544a1efde8..c8e48432a0 100644 --- a/src/Lucene.Net.Facet/Taxonomy/OrdinalsReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/OrdinalsReader.cs @@ -1,6 +1,5 @@ namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -27,7 +26,6 @@ public abstract class OrdinalsReader { - /// /// Returns ordinals for documents in one segment. public abstract class OrdinalsSegmentReader @@ -64,5 +62,4 @@ public OrdinalsReader() /// public abstract string IndexFieldName { get; } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/ParallelTaxonomyArrays.cs b/src/Lucene.Net.Facet/Taxonomy/ParallelTaxonomyArrays.cs index 26f1d8a606..60e351e8c6 100644 --- a/src/Lucene.Net.Facet/Taxonomy/ParallelTaxonomyArrays.cs +++ b/src/Lucene.Net.Facet/Taxonomy/ParallelTaxonomyArrays.cs @@ -1,8 +1,6 @@ namespace Lucene.Net.Facet.Taxonomy { - - - /* + /* * 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. @@ -19,56 +17,53 @@ * limitations under the License. */ - /// - /// Returns 3 arrays for traversing the taxonomy: - ///
    - ///
  • {@code parents}: {@code parents[i]} denotes the parent of category - /// ordinal {@code i}.
  • - ///
  • {@code children}: {@code children[i]} denotes a child of category ordinal - /// {@code i}.
  • - ///
  • {@code siblings}: {@code siblings[i]} denotes the sibling of category - /// ordinal {@code i}.
  • - ///
- /// - /// To traverse the taxonomy tree, you typically start with {@code children[0]} - /// (ordinal 0 is reserved for ROOT), and then depends if you want to do DFS or - /// BFS, you call {@code children[children[0]]} or {@code siblings[children[0]]} - /// and so forth, respectively. - /// - /// - /// NOTE: you are not expected to modify the values of the arrays, since - /// the arrays are shared with other threads. - /// - /// @lucene.experimental - /// - ///
- public abstract class ParallelTaxonomyArrays - { - - /// - /// Sole constructor. - public ParallelTaxonomyArrays() - { - } - - /// - /// Returns the parents array, where {@code parents[i]} denotes the parent of - /// category ordinal {@code i}. - /// - public abstract int[] Parents(); - - /// - /// Returns the children array, where {@code children[i]} denotes a child of - /// category ordinal {@code i}. - /// - public abstract int[] Children(); + /// + /// Returns 3 arrays for traversing the taxonomy: + ///
    + ///
  • {@code parents}: {@code parents[i]} denotes the parent of category + /// ordinal {@code i}.
  • + ///
  • {@code children}: {@code children[i]} denotes a child of category ordinal + /// {@code i}.
  • + ///
  • {@code siblings}: {@code siblings[i]} denotes the sibling of category + /// ordinal {@code i}.
  • + ///
+ /// + /// To traverse the taxonomy tree, you typically start with {@code children[0]} + /// (ordinal 0 is reserved for ROOT), and then depends if you want to do DFS or + /// BFS, you call {@code children[children[0]]} or {@code siblings[children[0]]} + /// and so forth, respectively. + /// + /// + /// NOTE: you are not expected to modify the values of the arrays, since + /// the arrays are shared with other threads. + /// + /// @lucene.experimental + /// + ///
+ public abstract class ParallelTaxonomyArrays + { + /// + /// Sole constructor. + public ParallelTaxonomyArrays() + { + } - /// - /// Returns the siblings array, where {@code siblings[i]} denotes the sibling - /// of category ordinal {@code i}. - /// - public abstract int[] Siblings(); + /// + /// Returns the parents array, where {@code parents[i]} denotes the parent of + /// category ordinal {@code i}. + /// + public abstract int[] Parents(); - } + /// + /// Returns the children array, where {@code children[i]} denotes a child of + /// category ordinal {@code i}. + /// + public abstract int[] Children(); + /// + /// Returns the siblings array, where {@code siblings[i]} denotes the sibling + /// of category ordinal {@code i}. + /// + public abstract int[] Siblings(); + } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/PrintTaxonomyStats.cs b/src/Lucene.Net.Facet/Taxonomy/PrintTaxonomyStats.cs index a4b44aaf3f..e4b723b4ec 100644 --- a/src/Lucene.Net.Facet/Taxonomy/PrintTaxonomyStats.cs +++ b/src/Lucene.Net.Facet/Taxonomy/PrintTaxonomyStats.cs @@ -3,7 +3,6 @@ namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -21,10 +20,9 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ - using ChildrenIterator = Lucene.Net.Facet.Taxonomy.TaxonomyReader.ChildrenIterator; - using DirectoryTaxonomyReader = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader; using Directory = Lucene.Net.Store.Directory; + using DirectoryTaxonomyReader = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader; using FSDirectory = Lucene.Net.Store.FSDirectory; /// @@ -33,7 +31,6 @@ namespace Lucene.Net.Facet.Taxonomy // java -cp ../build/core/classes/java:../build/facet/classes/java org.apache.lucene.facet.util.PrintTaxonomyStats -printTree /s2/scratch/indices/wikibig.trunk.noparents.facets.Lucene41.nd1M/facets public class PrintTaxonomyStats { - /// /// Sole constructor. public PrintTaxonomyStats() @@ -117,5 +114,4 @@ private static void PrintAllChildren(TextWriter @out, TaxonomyReader r, int ord, } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs b/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs index 7abc055e14..6686188b12 100644 --- a/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs +++ b/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs @@ -1,9 +1,8 @@ -using System.Threading; -using Lucene.Net.Search; +using Lucene.Net.Search; +using System; namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -21,18 +20,16 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ + using Directory = Lucene.Net.Store.Directory; + using DirectoryReader = Lucene.Net.Index.DirectoryReader; using DirectoryTaxonomyReader = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader; using DirectoryTaxonomyWriter = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter; - using DirectoryReader = Lucene.Net.Index.DirectoryReader; using IndexReader = Lucene.Net.Index.IndexReader; - using IndexWriter = Lucene.Net.Index.IndexWriter; using IndexSearcher = Lucene.Net.Search.IndexSearcher; - using Lucene.Net.Search; + using IndexWriter = Lucene.Net.Index.IndexWriter; + using IOUtils = Lucene.Net.Util.IOUtils; using SearcherFactory = Lucene.Net.Search.SearcherFactory; using SearcherManager = Lucene.Net.Search.SearcherManager; - using Directory = Lucene.Net.Store.Directory; - using IOUtils = Lucene.Net.Util.IOUtils; - using System; /// /// Manages near-real-time reopen of both an IndexSearcher @@ -45,7 +42,6 @@ namespace Lucene.Net.Facet.Taxonomy /// public class SearcherTaxonomyManager : ReferenceManager { - /// /// Holds a matched pair of and /// @@ -77,7 +73,8 @@ public SearcherAndTaxonomy(IndexSearcher searcher, DirectoryTaxonomyReader taxon /// Creates near-real-time searcher and taxonomy reader /// from the corresponding writers. /// - public SearcherTaxonomyManager(IndexWriter writer, bool applyAllDeletes, SearcherFactory searcherFactory, DirectoryTaxonomyWriter taxoWriter) + public SearcherTaxonomyManager(IndexWriter writer, bool applyAllDeletes, + SearcherFactory searcherFactory, DirectoryTaxonomyWriter taxoWriter) { if (searcherFactory == null) { @@ -86,7 +83,8 @@ public SearcherTaxonomyManager(IndexWriter writer, bool applyAllDeletes, Searche this.searcherFactory = searcherFactory; this.taxoWriter = taxoWriter; var taxoReader = new DirectoryTaxonomyReader(taxoWriter); - Current = new SearcherAndTaxonomy(SearcherManager.GetSearcher(searcherFactory, DirectoryReader.Open(writer, applyAllDeletes)), taxoReader); + Current = new SearcherAndTaxonomy(SearcherManager.GetSearcher( + searcherFactory, DirectoryReader.Open(writer, applyAllDeletes)), taxoReader); this.taxoEpoch = taxoWriter.TaxonomyEpoch; } @@ -107,7 +105,8 @@ public SearcherTaxonomyManager(Store.Directory indexDir, Store.Directory taxoDir } this.searcherFactory = searcherFactory; var taxoReader = new DirectoryTaxonomyReader(taxoDir); - Current = new SearcherAndTaxonomy(SearcherManager.GetSearcher(searcherFactory, DirectoryReader.Open(indexDir)), taxoReader); + Current = new SearcherAndTaxonomy(SearcherManager.GetSearcher( + searcherFactory, DirectoryReader.Open(indexDir)), taxoReader); this.taxoWriter = null; taxoEpoch = -1; } @@ -176,5 +175,4 @@ protected override int GetRefCount(SearcherAndTaxonomy reference) return reference.searcher.IndexReader.RefCount; } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs index 49be83927e..af008c7985 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs @@ -1,9 +1,7 @@ using System.Collections.Generic; -using Lucene.Net.Facet; namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -21,11 +19,10 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ - - using MatchingDocs = FacetsCollector.MatchingDocs; using BinaryDocValues = Lucene.Net.Index.BinaryDocValues; using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; using IntsRef = Lucene.Net.Util.IntsRef; + using MatchingDocs = FacetsCollector.MatchingDocs; /// /// Reads from any ; use {@link @@ -73,5 +70,4 @@ private void Count(IList matchingDocs) Rollup(); } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs index 7d5188efde..821c942045 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs @@ -1,11 +1,8 @@ -using System.Collections.Generic; -using Lucene.Net.Facet; -using Lucene.Net.Search; -using Lucene.Net.Support; +using Lucene.Net.Support; +using System.Collections.Generic; namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -23,11 +20,10 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ - - using MatchingDocs = FacetsCollector.MatchingDocs; using BinaryDocValues = Lucene.Net.Index.BinaryDocValues; - using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; using BytesRef = Lucene.Net.Util.BytesRef; + using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; + using MatchingDocs = FacetsCollector.MatchingDocs; /// /// Aggregates sum of int values previously indexed with @@ -38,7 +34,6 @@ namespace Lucene.Net.Facet.Taxonomy /// public class TaxonomyFacetSumFloatAssociations : FloatTaxonomyFacets { - /// /// Create {@code TaxonomyFacetSumFloatAssociations} against /// the default index field. @@ -84,9 +79,11 @@ private void SumValues(IList matchingDocs) int offset = bytesRef.Offset; while (offset < end) { - int ord = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | ((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF); + int ord = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | + ((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF); offset += 4; - int value = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | ((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF); + int value = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | + ((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF); offset += 4; values[ord] += Number.IntBitsToFloat(value); } @@ -94,5 +91,4 @@ private void SumValues(IList matchingDocs) } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs index 9942be6c52..8d835fbc89 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs @@ -1,9 +1,7 @@ using System.Collections.Generic; -using Lucene.Net.Facet; namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -21,11 +19,10 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ - - using MatchingDocs = FacetsCollector.MatchingDocs; using BinaryDocValues = Lucene.Net.Index.BinaryDocValues; - using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; using BytesRef = Lucene.Net.Util.BytesRef; + using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; + using MatchingDocs = FacetsCollector.MatchingDocs; /// /// Aggregates sum of int values previously indexed with @@ -36,7 +33,6 @@ namespace Lucene.Net.Facet.Taxonomy /// public class TaxonomyFacetSumIntAssociations : IntTaxonomyFacets { - /// /// Create {@code TaxonomyFacetSumIntAssociations} against /// the default index field. @@ -82,9 +78,11 @@ private void SumValues(IList matchingDocs) int offset = bytesRef.Offset; while (offset < end) { - int ord = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | ((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF); + int ord = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | + ((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF); offset += 4; - int value = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | ((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF); + int value = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | + ((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF); offset += 4; values[ord] += value; } @@ -92,5 +90,4 @@ private void SumValues(IList matchingDocs) } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs index 4d4fc76c02..4981f336b8 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs @@ -1,13 +1,10 @@ using System; using System.Collections; using System.Collections.Generic; -using System.IO; using System.Threading; -using Lucene.Net.Facet; namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -25,16 +22,15 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ - - using MatchingDocs = FacetsCollector.MatchingDocs; using AtomicReaderContext = Lucene.Net.Index.AtomicReaderContext; - using FunctionValues = Lucene.Net.Queries.Function.FunctionValues; - using ValueSource = Lucene.Net.Queries.Function.ValueSource; - using DoubleDocValues = Lucene.Net.Queries.Function.DocValues.DoubleDocValues; using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; + using DoubleDocValues = Lucene.Net.Queries.Function.DocValues.DoubleDocValues; + using FunctionValues = Lucene.Net.Queries.Function.FunctionValues; + using IntsRef = Lucene.Net.Util.IntsRef; + using MatchingDocs = FacetsCollector.MatchingDocs; using Scorer = Lucene.Net.Search.Scorer; + using ValueSource = Lucene.Net.Queries.Function.ValueSource; using Weight = Lucene.Net.Search.Weight; - using IntsRef = Lucene.Net.Util.IntsRef; /// /// Aggregates sum of values from {@link @@ -53,8 +49,10 @@ public class TaxonomyFacetSumValueSource : FloatTaxonomyFacets /// facet field {@link /// FacetsConfig#DEFAULT_INDEX_FIELD_NAME}. /// - public TaxonomyFacetSumValueSource(TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc, ValueSource valueSource) - : this(new DocValuesOrdinalsReader(FacetsConfig.DEFAULT_INDEX_FIELD_NAME), taxoReader, config, fc, valueSource) + public TaxonomyFacetSumValueSource(TaxonomyReader taxoReader, FacetsConfig config, + FacetsCollector fc, ValueSource valueSource) + : this(new DocValuesOrdinalsReader(FacetsConfig.DEFAULT_INDEX_FIELD_NAME), + taxoReader, config, fc, valueSource) { } @@ -63,7 +61,8 @@ public TaxonomyFacetSumValueSource(TaxonomyReader taxoReader, FacetsConfig confi /// , and pulls ordinals from the /// provided . /// - public TaxonomyFacetSumValueSource(OrdinalsReader ordinalsReader, TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc, ValueSource valueSource) + public TaxonomyFacetSumValueSource(OrdinalsReader ordinalsReader, TaxonomyReader taxoReader, + FacetsConfig config, FacetsCollector fc, ValueSource valueSource) : base(ordinalsReader.IndexFieldName, taxoReader, config) { this.ordinalsReader = ordinalsReader; @@ -193,7 +192,6 @@ public DoubleDocValuesAnonymousInnerClassHelper(ScoreValueSource outerInstance, { this.outerInstance = outerInstance; this.scorer = scorer; - } public override double DoubleVal(int document) @@ -214,7 +212,7 @@ public override bool Equals(object o) if (ReferenceEquals(null, o)) return false; if (ReferenceEquals(this, o)) return true; if (o.GetType() != this.GetType()) return false; - return Equals((ScoreValueSource) o); + return Equals((ScoreValueSource)o); } protected bool Equals(ScoreValueSource other) @@ -229,19 +227,13 @@ public override int GetHashCode() private static readonly int hcode = typeof(DoubleDocValuesAnonymousInnerClassHelper).GetHashCode(); - - - public override string Description { get { return "score()"; } - } } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs index 355ff6c89d..03baa55efc 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs @@ -1,11 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; -using Lucene.Net.Facet; namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -23,14 +21,12 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ - using DimConfig = Lucene.Net.Facet.FacetsConfig.DimConfig; // javadocs /// /// Base class for all taxonomy-based facets impls. public abstract class TaxonomyFacets : Facets { - private static readonly IComparer BY_VALUE_THEN_DIM = new ComparatorAnonymousInnerClassHelper(); private class ComparatorAnonymousInnerClassHelper : IComparer @@ -132,6 +128,5 @@ public override IList GetAllDims(int topN) Array.Sort(resultArray, BY_VALUE_THEN_DIM); return resultArray; } - } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs index f5cfc121b9..f303abbb53 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs @@ -1,15 +1,11 @@ -using System; -using System.Diagnostics; +using Lucene.Net.Support; +using System; using System.Collections.Generic; +using System.Diagnostics; using System.Threading; -using Lucene.Net.Support; namespace Lucene.Net.Facet.Taxonomy { - - - using AlreadyClosedException = Lucene.Net.Store.AlreadyClosedException; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -27,6 +23,8 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ + using AlreadyClosedException = Lucene.Net.Store.AlreadyClosedException; + /// /// TaxonomyReader is the read-only interface with which the faceted-search /// library uses the taxonomy during search time. @@ -68,12 +66,10 @@ namespace Lucene.Net.Facet.Taxonomy /// public abstract class TaxonomyReader { - /// /// An iterator over a category's children. public class ChildrenIterator { - internal readonly int[] siblings; internal int child; @@ -96,7 +92,6 @@ public virtual int Next() } return res; } - } /// @@ -310,8 +305,5 @@ public bool TryIncRef() } return false; } - - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyWriter.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyWriter.cs index 26a3e10c0a..0487cbfcd7 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyWriter.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyWriter.cs @@ -1,13 +1,8 @@ using System; using System.Collections.Generic; -using Lucene.Net.Index; namespace Lucene.Net.Facet.Taxonomy { - - - using TwoPhaseCommit = Lucene.Net.Index.TwoPhaseCommit; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -25,6 +20,8 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ + using TwoPhaseCommit = Lucene.Net.Index.TwoPhaseCommit; + /// /// TaxonomyWriter is the interface which the faceted-search library uses /// to dynamically build the taxonomy at indexing time. @@ -56,7 +53,6 @@ namespace Lucene.Net.Facet.Taxonomy /// public interface TaxonomyWriter : IDisposable, TwoPhaseCommit { - /// /// addCategory() adds a category with a given path name to the taxonomy, /// and returns its ordinal. If the category was already present in @@ -118,8 +114,5 @@ public interface TaxonomyWriter : IDisposable, TwoPhaseCommit /// /// IDictionary CommitData { set; get; } - - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CategoryPathUtils.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CategoryPathUtils.cs index eb63f56708..800fda0653 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CategoryPathUtils.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CategoryPathUtils.cs @@ -23,7 +23,6 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache /// Utilities for use of by . internal class CategoryPathUtils { - /// /// Serializes the given to the . public static void Serialize(FacetLabel cp, CharBlockArray charBlockArray) diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs index c1c982545d..691ed4124e 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs @@ -1,9 +1,8 @@ -using System; +using Lucene.Net.Support; +using System; using System.Collections.Generic; using System.IO; using System.Text; -using Lucene.Net.Store; -using Lucene.Net.Support; namespace Lucene.Net.Facet.Taxonomy.WriterCache { @@ -33,7 +32,6 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache [Serializable] public class CharBlockArray : ICharSequence { - private const long serialVersionUID = 1L; private const int DefaultBlockSize = 32 * 1024; // 32 KB default size diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs index 1b8f0c3202..8e6ca98407 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs @@ -2,9 +2,6 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache { - - - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -117,7 +114,5 @@ public virtual int MemoryUsage return cache == null ? 0 : cache.MemoryUsage; } } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs index c315ec5426..9e8c1ad208 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs @@ -2,11 +2,8 @@ using System.Collections; using System.Collections.Generic; - namespace Lucene.Net.Facet.Taxonomy.WriterCache { - - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -32,7 +29,6 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache /// public class CollisionMap { - private int capacity_Renamed; private float loadFactor; private int size_Renamed; @@ -261,7 +257,7 @@ public Entry Next() Entry e = this.next_Renamed; if (e == null) { - throw new InvalidOperationException(this.GetType() + " cannot get next entry");; + throw new InvalidOperationException(this.GetType() + " cannot get next entry"); ; } Entry n = e.next; @@ -305,7 +301,5 @@ object IEnumerator.Current get { return Current; } } } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs index d0cebe27b8..28f93c4fc7 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs @@ -50,7 +50,6 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache /// public class CompactLabelToOrdinal : LabelToOrdinal { - /// /// Default maximum load factor. public const float DefaultLoadFactor = 0.15f; @@ -81,7 +80,6 @@ private CompactLabelToOrdinal() /// Sole constructor. public CompactLabelToOrdinal(int initialCapacity, float loadFactor, int numHashArrays) { - this.hashArrays = new HashArray[numHashArrays]; this.capacity = DetermineCapacity((int)Math.Pow(2, numHashArrays), initialCapacity); diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LabelToOrdinal.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LabelToOrdinal.cs index 495aa9ba43..600ecbbe82 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LabelToOrdinal.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LabelToOrdinal.cs @@ -1,7 +1,6 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache { - - /* + /* * 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. @@ -18,66 +17,63 @@ * limitations under the License. */ - /// - /// Abstract class for storing Label->Ordinal mappings in a taxonomy. - /// - /// @lucene.experimental - /// - public abstract class LabelToOrdinal - { - - /// - /// How many ordinals we've seen. - protected internal int counter; - - /// - /// Returned by when the label isn't - /// recognized. - /// - public const int INVALID_ORDINAL = -2; - - /// - /// Default constructor. - public LabelToOrdinal() - { - } + /// + /// Abstract class for storing Label->Ordinal mappings in a taxonomy. + /// + /// @lucene.experimental + /// + public abstract class LabelToOrdinal + { + /// + /// How many ordinals we've seen. + protected internal int counter; - /// - /// return the maximal Ordinal assigned so far - /// - public virtual int MaxOrdinal - { - get - { - return this.counter; - } - } + /// + /// Returned by when the label isn't + /// recognized. + /// + public const int INVALID_ORDINAL = -2; - /// - /// Returns the next unassigned ordinal. The default behavior of this method - /// is to simply increment a counter. - /// - public virtual int NextOrdinal - { - get - { - return this.counter++; - } - } + /// + /// Default constructor. + public LabelToOrdinal() + { + } - /// - /// Adds a new label if its not yet in the table. - /// Throws an if the same label with - /// a different ordinal was previoulsy added to this table. - /// - public abstract void AddLabel(FacetLabel label, int ordinal); + /// + /// return the maximal Ordinal assigned so far + /// + public virtual int MaxOrdinal + { + get + { + return this.counter; + } + } - /// - /// Returns the ordinal assigned to the given label, - /// or if the label cannot be found in this table. - /// - public abstract int GetOrdinal(FacetLabel label); + /// + /// Returns the next unassigned ordinal. The default behavior of this method + /// is to simply increment a counter. + /// + public virtual int NextOrdinal + { + get + { + return this.counter++; + } + } - } + /// + /// Adds a new label if its not yet in the table. + /// Throws an if the same label with + /// a different ordinal was previoulsy added to this table. + /// + public abstract void AddLabel(FacetLabel label, int ordinal); + /// + /// Returns the ordinal assigned to the given label, + /// or if the label cannot be found in this table. + /// + public abstract int GetOrdinal(FacetLabel label); + } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs index 74bf396d85..d74891bbc5 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs @@ -1,7 +1,5 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache { - - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -26,7 +24,6 @@ ///
public class LruTaxonomyWriterCache : TaxonomyWriterCache { - /// /// Determines cache type. /// For guaranteed correctness - not relying on no-collisions in the hash @@ -143,7 +140,5 @@ public virtual bool Put(FacetLabel categoryPath, int ordinal) return ret; } } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameHashIntCacheLRU.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameHashIntCacheLRU.cs index cf135ea44d..40d67f57f9 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameHashIntCacheLRU.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameHashIntCacheLRU.cs @@ -1,7 +1,6 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache { - - /* + /* * 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. @@ -18,32 +17,30 @@ * limitations under the License. */ - /// - /// An an LRU cache of mapping from name to int. - /// Used to cache Ordinals of category paths. - /// It uses as key, hash of the path instead of the path. - /// This way the cache takes less RAM, but correctness depends on - /// assuming no collisions. - /// - /// @lucene.experimental - /// - public class NameHashIntCacheLRU : NameIntCacheLRU - { - - internal NameHashIntCacheLRU(int maxCacheSize) : base(maxCacheSize) - { - } - - internal override object Key(FacetLabel name) - { - return new long?(name.LongHashCode()); - } - - internal override object Key(FacetLabel name, int prefixLen) - { - return new long?(name.Subpath(prefixLen).LongHashCode()); - } + /// + /// An an LRU cache of mapping from name to int. + /// Used to cache Ordinals of category paths. + /// It uses as key, hash of the path instead of the path. + /// This way the cache takes less RAM, but correctness depends on + /// assuming no collisions. + /// + /// @lucene.experimental + /// + public class NameHashIntCacheLRU : NameIntCacheLRU + { + internal NameHashIntCacheLRU(int maxCacheSize) + : base(maxCacheSize) + { + } - } + internal override object Key(FacetLabel name) + { + return new long?(name.LongHashCode()); + } + internal override object Key(FacetLabel name, int prefixLen) + { + return new long?(name.Subpath(prefixLen).LongHashCode()); + } + } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs index a761aea694..e5c81e5b47 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs @@ -30,7 +30,6 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache // synchronized so that no two methods of this class are called concurrently. public class NameIntCacheLRU { - private Dictionary cache; internal long nMisses = 0; // for debug internal long nHits = 0; // for debug @@ -63,16 +62,16 @@ public virtual int Size } private void CreateCache(int maxSize) - { - //if (maxSize < int.MaxValue) - //{ - // cache = new LRUHashMap(1000,true); //for LRU - //} - //else - { - cache = new Dictionary(1000); //no need for LRU - } - } + { + //if (maxSize < int.MaxValue) + //{ + // cache = new LRUHashMap(1000,true); //for LRU + //} + //else + { + cache = new Dictionary(1000); //no need for LRU + } + } internal virtual int? Get(FacetLabel name) { @@ -163,7 +162,5 @@ internal virtual bool MakeRoomLRU() } return true; } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs index a20dcd659e..b0d32b9701 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs @@ -1,8 +1,5 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache { - - using DirectoryTaxonomyWriter = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -20,6 +17,8 @@ * limitations under the License. */ + using DirectoryTaxonomyWriter = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter; + /// /// TaxonomyWriterCache is a relatively simple interface for a cache of /// category->ordinal mappings, used in TaxonomyWriter implementations (such as @@ -49,7 +48,6 @@ /// public interface TaxonomyWriterCache { - /// /// Let go of whatever resources the cache is holding. After a close(), /// this object can no longer be used. @@ -99,7 +97,5 @@ public interface TaxonomyWriterCache /// assume that the cache is still operable after this method returns. /// void Clear(); - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/TopOrdAndFloatQueue.cs b/src/Lucene.Net.Facet/TopOrdAndFloatQueue.cs index 6430624baa..4b4dad7210 100644 --- a/src/Lucene.Net.Facet/TopOrdAndFloatQueue.cs +++ b/src/Lucene.Net.Facet/TopOrdAndFloatQueue.cs @@ -1,7 +1,8 @@ -namespace Lucene.Net.Facet -{ +using Lucene.Net.Util; - /* +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. @@ -18,56 +19,51 @@ * limitations under the License. */ - using Lucene.Net.Util; - - /// - /// Keeps highest results, first by largest float value, - /// then tie break by smallest ord. - /// - public class TopOrdAndFloatQueue : PriorityQueue - { - - /// - /// Holds a single entry. - public sealed class OrdAndValue - { - - /// - /// Ordinal of the entry. - public int ord; - - /// - /// Value associated with the ordinal. - public float value; + /// + /// Keeps highest results, first by largest float value, + /// then tie break by smallest ord. + /// + public class TopOrdAndFloatQueue : PriorityQueue + { + /// + /// Holds a single entry. + public sealed class OrdAndValue + { + /// + /// Ordinal of the entry. + public int ord; - /// - /// Default constructor. - public OrdAndValue() - { - } - } + /// + /// Value associated with the ordinal. + public float value; - /// - /// Sole constructor. - public TopOrdAndFloatQueue(int topN) : base(topN, false) - { - } + /// + /// Default constructor. + public OrdAndValue() + { + } + } - public override bool LessThan(OrdAndValue a, OrdAndValue b) - { - if (a.value < b.value) - { - return true; - } - else if (a.value > b.value) - { - return false; - } - else - { - return a.ord > b.ord; - } - } - } + /// + /// Sole constructor. + public TopOrdAndFloatQueue(int topN) : base(topN, false) + { + } + public override bool LessThan(OrdAndValue a, OrdAndValue b) + { + if (a.value < b.value) + { + return true; + } + else if (a.value > b.value) + { + return false; + } + else + { + return a.ord > b.ord; + } + } + } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/TopOrdAndIntQueue.cs b/src/Lucene.Net.Facet/TopOrdAndIntQueue.cs index 08bdffbb34..80246e55a1 100644 --- a/src/Lucene.Net.Facet/TopOrdAndIntQueue.cs +++ b/src/Lucene.Net.Facet/TopOrdAndIntQueue.cs @@ -2,7 +2,6 @@ namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -20,20 +19,16 @@ namespace Lucene.Net.Facet * limitations under the License. */ - using Lucene.Net.Util; - /// /// Keeps highest results, first by largest int value, /// then tie break by smallest ord. /// public class TopOrdAndIntQueue : PriorityQueue { - /// /// Holds a single entry. public sealed class OrdAndValue { - /// /// Ordinal of the entry. public int Ord; @@ -72,5 +67,4 @@ public override bool LessThan(OrdAndValue a, OrdAndValue b) } } } - } \ No newline at end of file From 2e5bae058f8842dd01e01287473ad1c8783e7b6e Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 01:20:50 +0700 Subject: [PATCH 14/41] .NETify Facet: Interfaces should begin with an "I" --- src/Lucene.Net.Facet/FacetsConfig.cs | 12 +++++----- .../DefaultSortedSetDocValuesReaderState.cs | 2 +- .../Directory/DirectoryTaxonomyWriter.cs | 24 +++++++++---------- .../Taxonomy/TaxonomyWriter.cs | 4 ++-- .../WriterCache/Cl2oTaxonomyWriterCache.cs | 2 +- .../WriterCache/LruTaxonomyWriterCache.cs | 2 +- .../WriterCache/TaxonomyWriterCache.cs | 6 ++--- .../Taxonomy/Directory/TestAddTaxonomy.cs | 16 ++++++------- .../TestConcurrentFacetedIndexing.cs | 10 ++++---- .../Directory/TestDirectoryTaxonomyReader.cs | 2 +- .../Directory/TestDirectoryTaxonomyWriter.cs | 10 ++++---- .../Taxonomy/TestSearcherTaxonomyManager.cs | 4 ++-- .../Taxonomy/TestTaxonomyCombined.cs | 20 ++++++++-------- .../Taxonomy/TestTaxonomyFacetAssociations.cs | 6 ++--- .../Taxonomy/TestTaxonomyFacetCounts.cs | 6 ++--- .../Taxonomy/TestTaxonomyFacetCounts2.cs | 8 +++---- .../TestDrillDownQuery.cs | 4 ++-- .../TestMultipleIndexFields.cs | 6 ++--- 18 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/Lucene.Net.Facet/FacetsConfig.cs b/src/Lucene.Net.Facet/FacetsConfig.cs index a62d625ac0..99aaf6ca80 100644 --- a/src/Lucene.Net.Facet/FacetsConfig.cs +++ b/src/Lucene.Net.Facet/FacetsConfig.cs @@ -40,7 +40,7 @@ namespace Lucene.Net.Facet using SortedSetDocValuesFacetField = Lucene.Net.Facet.SortedSet.SortedSetDocValuesFacetField; using SortedSetDocValuesField = Lucene.Net.Documents.SortedSetDocValuesField; using StringField = Lucene.Net.Documents.StringField; - using TaxonomyWriter = Lucene.Net.Facet.Taxonomy.TaxonomyWriter; + using ITaxonomyWriter = Lucene.Net.Facet.Taxonomy.ITaxonomyWriter; /// /// Records per-dimension configuration. By default a @@ -270,7 +270,7 @@ public virtual Document Build(Document doc) /// input one! /// /// - public virtual Document Build(TaxonomyWriter taxoWriter, Document doc) + public virtual Document Build(ITaxonomyWriter taxoWriter, Document doc) { // Find all FacetFields, collated by the actual field: IDictionary> byField = new Dictionary>(); @@ -395,7 +395,7 @@ public virtual Document Build(TaxonomyWriter taxoWriter, Document doc) return result; } - private void ProcessFacetFields(TaxonomyWriter taxoWriter, IDictionary> byField, Document doc) + private void ProcessFacetFields(ITaxonomyWriter taxoWriter, IDictionary> byField, Document doc) { foreach (KeyValuePair> ent in byField) @@ -486,7 +486,7 @@ public void processSSDVFacetFields(IDictionary> byField, Document doc) + private void ProcessAssocFacetFields(ITaxonomyWriter taxoWriter, IDictionary> byField, Document doc) { foreach (KeyValuePair> ent in byField) { @@ -592,11 +592,11 @@ protected virtual BytesRef DedupAndEncode(IntsRef ordinals) return new BytesRef(bytes, 0, upto); } - private void checkTaxoWriter(TaxonomyWriter taxoWriter) + private void checkTaxoWriter(ITaxonomyWriter taxoWriter) { if (taxoWriter == null) { - throw new ThreadStateException("a non-null TaxonomyWriter must be provided when indexing FacetField or AssociationFacetField"); + throw new ThreadStateException("a non-null ITaxonomyWriter must be provided when indexing FacetField or AssociationFacetField"); } } diff --git a/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs b/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs index 649135c673..10983d8bd4 100644 --- a/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs +++ b/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs @@ -61,7 +61,7 @@ public DefaultSortedSetDocValuesReaderState(IndexReader reader, string field = F valueCount = (int)dv.ValueCount; // TODO: we can make this more efficient if eg we can be - // "involved" when OrdinalMap is being created? Ie see + // "involved" when IOrdinalMap is being created? Ie see // each term/ord it's assigning as it goes... string lastDim = null; int startOrd = -1; diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs index c93d0e7991..a1c1939f77 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs @@ -46,7 +46,7 @@ namespace Lucene.Net.Facet.Taxonomy.Directory using ReaderManager = Lucene.Net.Index.ReaderManager; using SegmentInfos = Lucene.Net.Index.SegmentInfos; using StringField = Lucene.Net.Documents.StringField; - using TaxonomyWriterCache = Lucene.Net.Facet.Taxonomy.WriterCache.TaxonomyWriterCache; + using ITaxonomyWriterCache = Lucene.Net.Facet.Taxonomy.WriterCache.ITaxonomyWriterCache; using Terms = Lucene.Net.Index.Terms; using TermsEnum = Lucene.Net.Index.TermsEnum; using TextField = Lucene.Net.Documents.TextField; @@ -72,7 +72,7 @@ namespace Lucene.Net.Facet.Taxonomy.Directory /// @lucene.experimental /// /// - public class DirectoryTaxonomyWriter : TaxonomyWriter + public class DirectoryTaxonomyWriter : ITaxonomyWriter { /// /// Property name of user commit data that contains the index epoch. The epoch @@ -87,7 +87,7 @@ public class DirectoryTaxonomyWriter : TaxonomyWriter private readonly Directory dir; private readonly IndexWriter indexWriter; - private readonly TaxonomyWriterCache cache; + private readonly ITaxonomyWriterCache cache; private readonly AtomicInteger cacheMisses = new AtomicInteger(0); // Records the taxonomy index epoch, updated on replaceTaxonomy as well. @@ -175,7 +175,7 @@ public static void Unlock(Directory directory) /// /// if another error occurred. public DirectoryTaxonomyWriter(Directory directory, OpenMode openMode, - TaxonomyWriterCache cache) + ITaxonomyWriterCache cache) { dir = directory; IndexWriterConfig config = CreateIndexWriterConfig(openMode); @@ -332,7 +332,7 @@ public DirectoryTaxonomyWriter(Directory directory, OpenMode openMode = OpenMode /// with the parameters (1024, 0.15f, 3), i.e., the entire taxonomy is /// cached in memory while building it. /// - public static TaxonomyWriterCache DefaultTaxonomyWriterCache() + public static ITaxonomyWriterCache DefaultTaxonomyWriterCache() { return new Cl2oTaxonomyWriterCache(1024, 0.15f, 3); } @@ -897,14 +897,14 @@ public virtual int GetParent(int ordinal) /// with a mapping from the original ordinal to the new /// ordinal. ///
- public virtual void AddTaxonomy(Directory taxoDir, OrdinalMap map) + public virtual void AddTaxonomy(Directory taxoDir, IOrdinalMap map) { EnsureOpen(); DirectoryReader r = DirectoryReader.Open(taxoDir); try { int size = r.NumDocs; - OrdinalMap ordinalMap = map; + IOrdinalMap ordinalMap = map; ordinalMap.Size = size; int @base = 0; TermsEnum te = null; @@ -936,11 +936,11 @@ public virtual void AddTaxonomy(Directory taxoDir, OrdinalMap map) /// wit separate taxonomies. /// /// addToTaxonomies() merges one or more taxonomies into the given taxonomy - /// (this). An OrdinalMap is filled for each of the added taxonomies, + /// (this). An IOrdinalMap is filled for each of the added taxonomies, /// containing the new ordinal (in the merged taxonomy) of each of the /// categories in the old taxonomy. ///

- /// There exist two implementations of OrdinalMap: MemoryOrdinalMap and + /// There exist two implementations of IOrdinalMap: MemoryOrdinalMap and /// DiskOrdinalMap. As their names suggest, the former keeps the map in /// memory and the latter in a temporary disk file. Because these maps will /// later be needed one by one (to remap the counting lists), not all at the @@ -949,7 +949,7 @@ public virtual void AddTaxonomy(Directory taxoDir, OrdinalMap map) /// by one, when needed). /// ///

- public interface OrdinalMap + public interface IOrdinalMap { /// /// Set the size of the map. This MUST be called before addMapping(). @@ -983,7 +983,7 @@ public interface OrdinalMap /// /// maintained in memory /// - public sealed class MemoryOrdinalMap : OrdinalMap + public sealed class MemoryOrdinalMap : IOrdinalMap { internal int[] map; @@ -1027,7 +1027,7 @@ public int[] Map /// /// maintained on file system /// - public sealed class DiskOrdinalMap : OrdinalMap + public sealed class DiskOrdinalMap : IOrdinalMap { internal string tmpfile; internal OutputStreamDataOutput @out; diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyWriter.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyWriter.cs index 0487cbfcd7..6358dc1504 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyWriter.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyWriter.cs @@ -23,7 +23,7 @@ namespace Lucene.Net.Facet.Taxonomy using TwoPhaseCommit = Lucene.Net.Index.TwoPhaseCommit; /// - /// TaxonomyWriter is the interface which the faceted-search library uses + /// ITaxonomyWriter is the interface which the faceted-search library uses /// to dynamically build the taxonomy at indexing time. ///

/// Notes about concurrent access to the taxonomy: @@ -51,7 +51,7 @@ namespace Lucene.Net.Facet.Taxonomy /// /// @lucene.experimental ///

- public interface TaxonomyWriter : IDisposable, TwoPhaseCommit + public interface ITaxonomyWriter : IDisposable, TwoPhaseCommit { /// /// addCategory() adds a category with a given path name to the taxonomy, diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs index 8e6ca98407..9a40f166df 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs @@ -27,7 +27,7 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache /// /// @lucene.experimental /// - public class Cl2oTaxonomyWriterCache : TaxonomyWriterCache + public class Cl2oTaxonomyWriterCache : ITaxonomyWriterCache { private const int LockTimeOut = 1000; private readonly ReaderWriterLock @lock = new ReaderWriterLock(); diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs index d74891bbc5..8727893b86 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs @@ -22,7 +22,7 @@ /// /// @lucene.experimental ///
- public class LruTaxonomyWriterCache : TaxonomyWriterCache + public class LruTaxonomyWriterCache : ITaxonomyWriterCache { /// /// Determines cache type. diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs index b0d32b9701..bbe82ecdf1 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs @@ -20,8 +20,8 @@ using DirectoryTaxonomyWriter = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter; /// - /// TaxonomyWriterCache is a relatively simple interface for a cache of - /// category->ordinal mappings, used in TaxonomyWriter implementations (such as + /// ITaxonomyWriterCache is a relatively simple interface for a cache of + /// category->ordinal mappings, used in ITaxonomyWriter implementations (such as /// ). /// /// It basically has put() methods for adding a mapping, and get() for looking a @@ -46,7 +46,7 @@ /// @lucene.experimental /// /// - public interface TaxonomyWriterCache + public interface ITaxonomyWriterCache { /// /// Let go of whatever resources the cache is holding. After a close(), diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs index df4f491671..9482407cd9 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs @@ -13,7 +13,7 @@ namespace Lucene.Net.Facet.Taxonomy.Directory using DiskOrdinalMap = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter.DiskOrdinalMap; using MemoryOrdinalMap = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter.MemoryOrdinalMap; - using OrdinalMap = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter.OrdinalMap; + using IOrdinalMap = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter.IOrdinalMap; using Directory = Lucene.Net.Store.Directory; using IOUtils = Lucene.Net.Util.IOUtils; using TestUtil = Lucene.Net.Util.TestUtil; @@ -64,7 +64,7 @@ private void Dotest(int ncats, int range) } var tw1 = new DirectoryTaxonomyWriter(dirs[0]); - OrdinalMap map = randomOrdinalMap(); + IOrdinalMap map = randomOrdinalMap(); tw1.AddTaxonomy(dirs[1], map); tw1.Dispose(); @@ -108,7 +108,7 @@ public override void Run() } - private OrdinalMap randomOrdinalMap() + private IOrdinalMap randomOrdinalMap() { if (Random().NextBoolean()) { @@ -120,7 +120,7 @@ private OrdinalMap randomOrdinalMap() } } - private void validate(Directory dest, Directory src, OrdinalMap ordMap) + private void validate(Directory dest, Directory src, IOrdinalMap ordMap) { var destTr = new DirectoryTaxonomyReader(dest); try @@ -168,7 +168,7 @@ public virtual void TestAddEmpty() Directory src = NewDirectory(); (new DirectoryTaxonomyWriter(src)).Dispose(); // create an empty taxonomy - OrdinalMap map = randomOrdinalMap(); + IOrdinalMap map = randomOrdinalMap(); destTW.AddTaxonomy(src, map); destTW.Dispose(); @@ -189,7 +189,7 @@ public virtual void TestAddToEmpty() srcTW.Dispose(); DirectoryTaxonomyWriter destTW = new DirectoryTaxonomyWriter(dest); - OrdinalMap map = randomOrdinalMap(); + IOrdinalMap map = randomOrdinalMap(); destTW.AddTaxonomy(src, map); destTW.Dispose(); @@ -234,7 +234,7 @@ public virtual void TestSimple() tw2.AddCategory(new FacetLabel("Aardvarks", "Bob")); tw2.Dispose(); - OrdinalMap map = randomOrdinalMap(); + IOrdinalMap map = randomOrdinalMap(); tw1.AddTaxonomy(src, map); tw1.Dispose(); @@ -266,7 +266,7 @@ public virtual void TestConcurrency() ThreadClass t = new ThreadAnonymousInnerClassHelper2(this, numCategories, destTw); t.Start(); - OrdinalMap map = new MemoryOrdinalMap(); + IOrdinalMap map = new MemoryOrdinalMap(); destTw.AddTaxonomy(src, map); t.Join(); destTw.Dispose(); diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs index 5ee17a62a0..f2c0fe7ca8 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs @@ -10,7 +10,7 @@ namespace Lucene.Net.Facet.Taxonomy.Directory using Document = Lucene.Net.Documents.Document; - using TaxonomyWriterCache = Lucene.Net.Facet.Taxonomy.WriterCache.TaxonomyWriterCache; + using ITaxonomyWriterCache = Lucene.Net.Facet.Taxonomy.WriterCache.ITaxonomyWriterCache; using Cl2oTaxonomyWriterCache = Lucene.Net.Facet.Taxonomy.WriterCache.Cl2oTaxonomyWriterCache; using LruTaxonomyWriterCache = Lucene.Net.Facet.Taxonomy.WriterCache.LruTaxonomyWriterCache; using IndexWriter = Lucene.Net.Index.IndexWriter; @@ -38,11 +38,11 @@ namespace Lucene.Net.Facet.Taxonomy.Directory public class TestConcurrentFacetedIndexing : FacetTestCase { - // A No-Op TaxonomyWriterCache which always discards all given categories, and + // A No-Op ITaxonomyWriterCache which always discards all given categories, and // always returns true in put(), to indicate some cache entries were cleared. - private static TaxonomyWriterCache NO_OP_CACHE = new TaxonomyWriterCacheAnonymousInnerClassHelper(); + private static ITaxonomyWriterCache NO_OP_CACHE = new TaxonomyWriterCacheAnonymousInnerClassHelper(); - private class TaxonomyWriterCacheAnonymousInnerClassHelper : TaxonomyWriterCache + private class TaxonomyWriterCacheAnonymousInnerClassHelper : ITaxonomyWriterCache { public TaxonomyWriterCacheAnonymousInnerClassHelper() { @@ -82,7 +82,7 @@ internal static FacetField NewCategory() return new FacetField(l1, l2, l3); } - internal static TaxonomyWriterCache NewTaxoWriterCache(int ndocs) + internal static ITaxonomyWriterCache NewTaxoWriterCache(int ndocs) { double d = Random().NextDouble(); if (d < 0.7) diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs index 74ba8fe854..d0801dd209 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs @@ -146,7 +146,7 @@ public virtual void TestOpenIfChangedReadRecreatedTaxonomy() private void doTestReadRecreatedTaxonomy(Random random, bool closeReader) { Directory dir = null; - TaxonomyWriter tw = null; + ITaxonomyWriter tw = null; TaxonomyReader tr = null; // prepare a few categories diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs index 60e90c27b9..8924f56147 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs @@ -13,7 +13,7 @@ namespace Lucene.Net.Facet.Taxonomy.Directory using MockAnalyzer = Lucene.Net.Analysis.MockAnalyzer; using Document = Lucene.Net.Documents.Document; using MemoryOrdinalMap = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter.MemoryOrdinalMap; - using TaxonomyWriterCache = Lucene.Net.Facet.Taxonomy.WriterCache.TaxonomyWriterCache; + using ITaxonomyWriterCache = Lucene.Net.Facet.Taxonomy.WriterCache.ITaxonomyWriterCache; using Cl2oTaxonomyWriterCache = Lucene.Net.Facet.Taxonomy.WriterCache.Cl2oTaxonomyWriterCache; using LruTaxonomyWriterCache = Lucene.Net.Facet.Taxonomy.WriterCache.LruTaxonomyWriterCache; using DirectoryReader = Lucene.Net.Index.DirectoryReader; @@ -48,11 +48,11 @@ namespace Lucene.Net.Facet.Taxonomy.Directory public class TestDirectoryTaxonomyWriter : FacetTestCase { - // A No-Op TaxonomyWriterCache which always discards all given categories, and + // A No-Op ITaxonomyWriterCache which always discards all given categories, and // always returns true in put(), to indicate some cache entries were cleared. - private static TaxonomyWriterCache NO_OP_CACHE = new TaxonomyWriterCacheAnonymousInnerClassHelper(); + private static ITaxonomyWriterCache NO_OP_CACHE = new TaxonomyWriterCacheAnonymousInnerClassHelper(); - private class TaxonomyWriterCacheAnonymousInnerClassHelper : TaxonomyWriterCache + private class TaxonomyWriterCacheAnonymousInnerClassHelper : ITaxonomyWriterCache { public virtual void Close() { @@ -272,7 +272,7 @@ public virtual void TestConcurrency() Directory dir = NewDirectory(); var values = new ConcurrentDictionary(); double d = Random().NextDouble(); - TaxonomyWriterCache cache; + ITaxonomyWriterCache cache; if (d < 0.7) { // this is the fastest, yet most memory consuming diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs index b0a1277d4a..0d02696907 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs @@ -47,12 +47,12 @@ private class IndexerThread : ThreadClass internal IndexWriter w; internal FacetsConfig config; - internal TaxonomyWriter tw; + internal ITaxonomyWriter tw; internal ReferenceManager mgr; internal int ordLimit; internal AtomicBoolean stop; - public IndexerThread(IndexWriter w, FacetsConfig config, TaxonomyWriter tw, ReferenceManager mgr, int ordLimit, AtomicBoolean stop) + public IndexerThread(IndexWriter w, FacetsConfig config, ITaxonomyWriter tw, ReferenceManager mgr, int ordLimit, AtomicBoolean stop) { this.w = w; this.config = config; diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs index caf1f09a2a..9290ec29c7 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs @@ -61,7 +61,7 @@ public class TestTaxonomyCombined : FacetTestCase }; /// - /// When adding the above categories with TaxonomyWriter.AddCategory(), + /// When adding the above categories with ITaxonomyWriter.AddCategory(), /// the following paths are expected to be returned: /// (note that currently the full path is not returned, and therefore /// not tested - rather, just the last component, the ordinal, is returned @@ -99,7 +99,7 @@ public class TestTaxonomyCombined : FacetTestCase /// index will surely have this method fail. /// - public static void FillTaxonomy(TaxonomyWriter tw) + public static void FillTaxonomy(ITaxonomyWriter tw) { for (int i = 0; i < categories.Length; i++) { @@ -149,7 +149,7 @@ private string Showcat(FacetLabel path) } /// - /// Basic tests for TaxonomyWriter. Basically, we test that + /// Basic tests for ITaxonomyWriter. Basically, we test that /// IndexWriter.AddCategory works, i.e. returns the expected ordinals /// (this is tested by calling the fillTaxonomy() method above). /// We do not test here that after writing the index can be read - @@ -161,7 +161,7 @@ public virtual void TestWriter() var indexDir = NewDirectory(); var tw = new DirectoryTaxonomyWriter(indexDir); FillTaxonomy(tw); - // Also check TaxonomyWriter.getSize() - see that the taxonomy's size + // Also check ITaxonomyWriter.getSize() - see that the taxonomy's size // is what we expect it to be. Assert.AreEqual(ExpectedCategories.Length, tw.Size); tw.Dispose(); @@ -445,7 +445,7 @@ public virtual void TestReaderParent() } /// - /// Tests for TaxonomyWriter's getParent() method. We check it by comparing + /// Tests for ITaxonomyWriter's getParent() method. We check it by comparing /// its results to those we could have gotten by looking at the category /// string paths using a TaxonomyReader (where the parentage is obvious). /// Note that after testReaderBasic(), we already know we can trust the @@ -490,7 +490,7 @@ public virtual void TestWriterParent2() indexDir.Dispose(); } - private void CheckWriterParent(TaxonomyReader tr, TaxonomyWriter tw) + private void CheckWriterParent(TaxonomyReader tr, ITaxonomyWriter tw) { // check that the parent of the root ordinal is the invalid ordinal: Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tw.GetParent(0)); @@ -1068,7 +1068,7 @@ public virtual void TestWriterLock() /// taxonomy index. Calling it after something else was already added to the /// taxonomy index will surely have this method fail. /// - public static void FillTaxonomyCheckPaths(TaxonomyWriter tw) + public static void FillTaxonomyCheckPaths(ITaxonomyWriter tw) { for (int i = 0; i < categories.Length; i++) { @@ -1092,7 +1092,7 @@ public static void FillTaxonomyCheckPaths(TaxonomyWriter tw) // After fillTaxonomy returned successfully, checkPaths() checks that // the getParent() calls return as expected, from the table - public static void CheckPaths(TaxonomyWriter tw) + public static void CheckPaths(ITaxonomyWriter tw) { for (int i = 0; i < categories.Length; i++) { @@ -1112,7 +1112,7 @@ public static void CheckPaths(TaxonomyWriter tw) } /// - /// Basic test for TaxonomyWriter.getParent(). This is similar to testWriter + /// Basic test for ITaxonomyWriter.getParent(). This is similar to testWriter /// above, except we also check the parents of the added categories, not just /// the categories themselves. /// @@ -1122,7 +1122,7 @@ public virtual void TestWriterCheckPaths() var indexDir = NewDirectory(); var tw = new DirectoryTaxonomyWriter(indexDir); FillTaxonomyCheckPaths(tw); - // Also check TaxonomyWriter.getSize() - see that the taxonomy's size + // Also check ITaxonomyWriter.getSize() - see that the taxonomy's size // is what we expect it to be. Assert.AreEqual(ExpectedCategories.Length, tw.Size); tw.Dispose(); diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetAssociations.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetAssociations.cs index b4bc17bfac..8cdd14de0e 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetAssociations.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetAssociations.cs @@ -191,7 +191,7 @@ public virtual void TestMixedTypesInSameIndexField() Store.Directory dir = NewDirectory(); Store.Directory taxoDir = NewDirectory(); - TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir); + ITaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir); FacetsConfig config = new FacetsConfig(); RandomIndexWriter writer = new RandomIndexWriter(Random(), dir, Similarity, TimeZone); @@ -216,7 +216,7 @@ public virtual void TestNoHierarchy() Store.Directory dir = NewDirectory(); Store.Directory taxoDir = NewDirectory(); - TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir); + ITaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir); FacetsConfig config = new FacetsConfig(); config.SetHierarchical("a", true); RandomIndexWriter writer = new RandomIndexWriter(Random(), dir, Similarity, TimeZone); @@ -241,7 +241,7 @@ public virtual void TestRequireDimCount() Store.Directory dir = NewDirectory(); Store.Directory taxoDir = NewDirectory(); - TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir); + ITaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir); FacetsConfig config = new FacetsConfig(); config.SetRequireDimCount("a", true); RandomIndexWriter writer = new RandomIndexWriter(Random(), dir, Similarity, TimeZone); diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs index 51d0794673..263a1d27b0 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs @@ -287,7 +287,7 @@ public virtual void TestReallyNoNormsForDrillDown() Store.Directory taxoDir = NewDirectory(); IndexWriterConfig iwc = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())); iwc.SetSimilarity(new PerFieldSimilarityWrapperAnonymousInnerClassHelper(this)); - TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode_e.CREATE); + ITaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode_e.CREATE); RandomIndexWriter writer = new RandomIndexWriter(Random(), dir, iwc); FacetsConfig config = new FacetsConfig(); @@ -543,7 +543,7 @@ public virtual void TestDetectMultiValuedField() { Store.Directory dir = NewDirectory(); Store.Directory taxoDir = NewDirectory(); - TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode_e.CREATE); + ITaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode_e.CREATE); RandomIndexWriter writer = new RandomIndexWriter(Random(), dir, Similarity, TimeZone); FacetsConfig config = new FacetsConfig(); @@ -686,7 +686,7 @@ public virtual void TestChildCount() IOUtils.Close(taxoWriter, iw, taxoReader, taxoDir, r, indexDir); } - private void indexTwoDocs(TaxonomyWriter taxoWriter, IndexWriter indexWriter, FacetsConfig config, bool withContent) + private void indexTwoDocs(ITaxonomyWriter taxoWriter, IndexWriter indexWriter, FacetsConfig config, bool withContent) { for (int i = 0; i < 2; i++) { diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts2.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts2.cs index 6cc831400b..6f4cb8bec0 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts2.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts2.cs @@ -170,7 +170,7 @@ private static void IndexDocsNoFacets(IndexWriter indexWriter) indexWriter.Commit(); // flush a segment } - private static void IndexDocsWithFacetsNoTerms(IndexWriter indexWriter, TaxonomyWriter taxoWriter, IDictionary expectedCounts) + private static void IndexDocsWithFacetsNoTerms(IndexWriter indexWriter, ITaxonomyWriter taxoWriter, IDictionary expectedCounts) { Random random = Random(); int numDocs = AtLeast(random, 2); @@ -184,7 +184,7 @@ private static void IndexDocsWithFacetsNoTerms(IndexWriter indexWriter, Taxonomy indexWriter.Commit(); // flush a segment } - private static void IndexDocsWithFacetsAndTerms(IndexWriter indexWriter, TaxonomyWriter taxoWriter, IDictionary expectedCounts) + private static void IndexDocsWithFacetsAndTerms(IndexWriter indexWriter, ITaxonomyWriter taxoWriter, IDictionary expectedCounts) { Random random = Random(); int numDocs = AtLeast(random, 2); @@ -199,7 +199,7 @@ private static void IndexDocsWithFacetsAndTerms(IndexWriter indexWriter, Taxonom indexWriter.Commit(); // flush a segment } - private static void IndexDocsWithFacetsAndSomeTerms(IndexWriter indexWriter, TaxonomyWriter taxoWriter, IDictionary expectedCounts) + private static void IndexDocsWithFacetsAndSomeTerms(IndexWriter indexWriter, ITaxonomyWriter taxoWriter, IDictionary expectedCounts) { Random random = Random(); int numDocs = AtLeast(random, 2); @@ -260,7 +260,7 @@ public void BeforeClassCountingFacetsAggregatorTest() IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())); //conf.MergePolicy = NoMergePolicy.INSTANCE; // prevent merges, so we can control the index segments IndexWriter indexWriter = new IndexWriter(indexDir, conf); - TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir); + ITaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir); allExpectedCounts = newCounts(); termExpectedCounts = newCounts(); diff --git a/src/Lucene.Net.Tests.Facet/TestDrillDownQuery.cs b/src/Lucene.Net.Tests.Facet/TestDrillDownQuery.cs index 3ceb00574c..01f7fe5483 100644 --- a/src/Lucene.Net.Tests.Facet/TestDrillDownQuery.cs +++ b/src/Lucene.Net.Tests.Facet/TestDrillDownQuery.cs @@ -29,7 +29,7 @@ namespace Lucene.Net.Facet using Document = Lucene.Net.Documents.Document; using Field = Lucene.Net.Documents.Field; using TextField = Lucene.Net.Documents.TextField; - using TaxonomyWriter = Lucene.Net.Facet.Taxonomy.TaxonomyWriter; + using ITaxonomyWriter = Lucene.Net.Facet.Taxonomy.ITaxonomyWriter; using DirectoryTaxonomyReader = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader; using DirectoryTaxonomyWriter = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter; using IndexReader = Lucene.Net.Index.IndexReader; @@ -75,7 +75,7 @@ public void BeforeClassDrillDownQueryTest() RandomIndexWriter writer = new RandomIndexWriter(r, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(r, MockTokenizer.KEYWORD, false))); taxoDir = NewDirectory(); - TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir); + ITaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir); config = new FacetsConfig(); // Randomize the per-dim config: diff --git a/src/Lucene.Net.Tests.Facet/TestMultipleIndexFields.cs b/src/Lucene.Net.Tests.Facet/TestMultipleIndexFields.cs index 086e608541..3d229fecff 100644 --- a/src/Lucene.Net.Tests.Facet/TestMultipleIndexFields.cs +++ b/src/Lucene.Net.Tests.Facet/TestMultipleIndexFields.cs @@ -28,7 +28,7 @@ namespace Lucene.Net.Facet using Field = Lucene.Net.Documents.Field; using TextField = Lucene.Net.Documents.TextField; using TaxonomyReader = Lucene.Net.Facet.Taxonomy.TaxonomyReader; - using TaxonomyWriter = Lucene.Net.Facet.Taxonomy.TaxonomyWriter; + using ITaxonomyWriter = Lucene.Net.Facet.Taxonomy.ITaxonomyWriter; using DirectoryTaxonomyReader = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader; using DirectoryTaxonomyWriter = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter; using AtomicReader = Lucene.Net.Index.AtomicReader; @@ -234,7 +234,7 @@ public virtual void TestSomeSameSomeDifferent() // create and open an index writer RandomIndexWriter iw = new RandomIndexWriter(Random(), indexDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false))); // create and open a taxonomy writer - TaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE); + ITaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE); FacetsConfig config = Config; config.SetIndexFieldName("Band", "$music"); @@ -286,7 +286,7 @@ private static FacetsCollector PerformSearch(TaxonomyReader tr, IndexReader ir, return fc; } - private static void seedIndex(TaxonomyWriter tw, RandomIndexWriter iw, FacetsConfig config) + private static void seedIndex(ITaxonomyWriter tw, RandomIndexWriter iw, FacetsConfig config) { foreach (FacetField ff in CATEGORIES) { From 9604c0f723c4574cfe48f491a7ff6de06613c094 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 14:50:19 +0700 Subject: [PATCH 15/41] .NETify Facet: Method names should be PascalCase --- src/Lucene.Net.Facet/FacetsConfig.cs | 10 ++++---- src/Lucene.Net.Facet/Range/DoubleRange.cs | 4 ++-- .../Range/DoubleRangeFacetCounts.cs | 4 ++-- src/Lucene.Net.Facet/Range/LongRange.cs | 4 ++-- .../Range/LongRangeCounter.cs | 24 +++++++++---------- .../Range/LongRangeFacetCounts.cs | 4 ++-- src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs | 12 +++++----- .../Taxonomy/FloatAssociationFacetField.cs | 12 +++++----- .../Taxonomy/IntAssociationFacetField.cs | 8 +++---- 9 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/Lucene.Net.Facet/FacetsConfig.cs b/src/Lucene.Net.Facet/FacetsConfig.cs index 99aaf6ca80..16a0ea3aac 100644 --- a/src/Lucene.Net.Facet/FacetsConfig.cs +++ b/src/Lucene.Net.Facet/FacetsConfig.cs @@ -378,7 +378,7 @@ public virtual Document Build(ITaxonomyWriter taxoWriter, Document doc) Document result = new Document(); ProcessFacetFields(taxoWriter, byField, result); - processSSDVFacetFields(dvByField, result); + ProcessSSDVFacetFields(dvByField, result); ProcessAssocFacetFields(taxoWriter, assocByField, result); //System.out.println("add stored: " + addedStoredFields); @@ -416,7 +416,7 @@ private void ProcessFacetFields(ITaxonomyWriter taxoWriter, IDictionary> byField, Document doc) + public void ProcessSSDVFacetFields(IDictionary> byField, Document doc) { //System.out.println("process SSDV: " + byField); foreach (KeyValuePair> ent in byField) @@ -496,7 +496,7 @@ private void ProcessAssocFacetFields(ITaxonomyWriter taxoWriter, IDictionary bytes.Length) @@ -592,7 +592,7 @@ protected virtual BytesRef DedupAndEncode(IntsRef ordinals) return new BytesRef(bytes, 0, upto); } - private void checkTaxoWriter(ITaxonomyWriter taxoWriter) + private void CheckTaxoWriter(ITaxonomyWriter taxoWriter) { if (taxoWriter == null) { diff --git a/src/Lucene.Net.Facet/Range/DoubleRange.cs b/src/Lucene.Net.Facet/Range/DoubleRange.cs index 28685d4e4e..93f85cb7cc 100644 --- a/src/Lucene.Net.Facet/Range/DoubleRange.cs +++ b/src/Lucene.Net.Facet/Range/DoubleRange.cs @@ -100,7 +100,7 @@ public DoubleRange(string label, double minIn, bool minInclusive, double maxIn, /// /// True if this range accepts the provided value. - public bool accept(double value) + public bool Accept(double value) { return value >= minIncl && value <= maxIncl; } @@ -216,7 +216,7 @@ public virtual bool Get(int docID) { return false; } - return outerInstance.outerInstance.outerInstance.accept(outerInstance.values.DoubleVal(docID)); + return outerInstance.outerInstance.outerInstance.Accept(outerInstance.values.DoubleVal(docID)); } public virtual int Length() diff --git a/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs b/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs index 1e3a99618f..1033a42d06 100644 --- a/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs +++ b/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs @@ -135,7 +135,7 @@ private void Count(ValueSource valueSource, IEnumerable matchingDo // Skip missing docs: if (fv.Exists(doc)) { - counter.add(NumericUtils.DoubleToSortableLong(fv.DoubleVal(doc))); + counter.Add(NumericUtils.DoubleToSortableLong(fv.DoubleVal(doc))); } else { @@ -144,7 +144,7 @@ private void Count(ValueSource valueSource, IEnumerable matchingDo } } - missingCount += counter.fillCounts(Counts); + missingCount += counter.FillCounts(Counts); TotCount -= missingCount; } } diff --git a/src/Lucene.Net.Facet/Range/LongRange.cs b/src/Lucene.Net.Facet/Range/LongRange.cs index 7a4f0c1fa0..c54456df7a 100644 --- a/src/Lucene.Net.Facet/Range/LongRange.cs +++ b/src/Lucene.Net.Facet/Range/LongRange.cs @@ -101,7 +101,7 @@ public LongRange(string label, long minIn, bool minInclusive, long maxIn, bool m /// /// True if this range accepts the provided value. - public bool accept(long value) + public bool Accept(long value) { return value >= minIncl && value <= maxIncl; } @@ -214,7 +214,7 @@ public virtual bool Get(int docID) { return false; } - return outerInstance.outerInstance.outerInstance.accept(outerInstance.values.LongVal(docID)); + return outerInstance.outerInstance.outerInstance.Accept(outerInstance.values.LongVal(docID)); } diff --git a/src/Lucene.Net.Facet/Range/LongRangeCounter.cs b/src/Lucene.Net.Facet/Range/LongRangeCounter.cs index 43ef3b4652..f5753fa04b 100644 --- a/src/Lucene.Net.Facet/Range/LongRangeCounter.cs +++ b/src/Lucene.Net.Facet/Range/LongRangeCounter.cs @@ -135,7 +135,7 @@ public LongRangeCounter(LongRange[] ranges) // each node in the tree: for (int i = 0; i < ranges.Length; i++) { - root.addOutputs(i, ranges[i]); + root.AddOutputs(i, ranges[i]); } // Set boundaries (ends of each elementary interval): @@ -153,7 +153,7 @@ public LongRangeCounter(LongRange[] ranges) //System.out.println("root:\n" + root); } - public void add(long v) + public void Add(long v) { //System.out.println("add v=" + v); @@ -208,23 +208,23 @@ public void add(long v) /// ranges, returning the missing count (how many hits /// didn't match any ranges). /// - public int fillCounts(int[] counts) + public int FillCounts(int[] counts) { //System.out.println(" rollup"); missingCount = 0; leafUpto = 0; - rollup(root, counts, false); + Rollup(root, counts, false); return missingCount; } - private int rollup(LongRangeNode node, int[] counts, bool sawOutputs) + private int Rollup(LongRangeNode node, int[] counts, bool sawOutputs) { int count; sawOutputs |= node.outputs != null; if (node.left != null) { - count = rollup(node.left, counts, sawOutputs); - count += rollup(node.right, counts, sawOutputs); + count = Rollup(node.left, counts, sawOutputs); + count += Rollup(node.right, counts, sawOutputs); } else { @@ -319,7 +319,7 @@ public override string ToString() return sb.ToString(); } - internal static void indent(StringBuilder sb, int depth) + internal static void Indent(StringBuilder sb, int depth) { for (int i = 0; i < depth; i++) { @@ -329,7 +329,7 @@ internal static void indent(StringBuilder sb, int depth) /// /// Recursively assigns range outputs to each node. - internal void addOutputs(int index, LongRange range) + internal void AddOutputs(int index, LongRange range) { if (start >= range.minIncl && end <= range.maxIncl) { @@ -345,14 +345,14 @@ internal void addOutputs(int index, LongRange range) { Debug.Assert(right != null); // Recurse: - left.addOutputs(index, range); - right.addOutputs(index, range); + left.AddOutputs(index, range); + right.AddOutputs(index, range); } } internal void ToString(StringBuilder sb, int depth) { - indent(sb, depth); + Indent(sb, depth); if (left == null) { Debug.Assert(right == null); diff --git a/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs b/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs index 813757ded5..167eb85418 100644 --- a/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs +++ b/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs @@ -120,7 +120,7 @@ private void Count(ValueSource valueSource, IList matchingDocs) // Skip missing docs: if (fv.Exists(doc)) { - counter.add(fv.LongVal(doc)); + counter.Add(fv.LongVal(doc)); } else { @@ -129,7 +129,7 @@ private void Count(ValueSource valueSource, IList matchingDocs) } } - int x = counter.fillCounts(Counts); + int x = counter.FillCounts(Counts); missingCount += x; diff --git a/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs b/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs index 3709b58954..d00c50ae92 100644 --- a/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs +++ b/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs @@ -149,19 +149,19 @@ public virtual int CompareTo(CategoryPath other) return length - other.length; } - private void hasDelimiter(string offender, char delimiter) + private void HasDelimiter(string offender, char delimiter) { throw new System.ArgumentException("delimiter character '" + delimiter + "' (U+" + delimiter.ToString() + ") appears in path component \"" + offender + "\""); } - private void noDelimiter(char[] buf, int offset, int len, char delimiter) + private void NoDelimiter(char[] buf, int offset, int len, char delimiter) { for (int idx = 0; idx < len; idx++) { if (buf[offset + idx] == delimiter) { - hasDelimiter(new string(buf, offset, len), delimiter); + HasDelimiter(new string(buf, offset, len), delimiter); } } } @@ -190,12 +190,12 @@ public virtual int CopyFullPath(char[] buf, int start, char delimiter) { int len = components[i].Length; components[i].CopyTo(0, buf, idx, len - 0); - noDelimiter(buf, idx, len, delimiter); + NoDelimiter(buf, idx, len, delimiter); idx += len; buf[idx++] = delimiter; } components[upto].CopyTo(0, buf, idx, components[upto].Length - 0); - noDelimiter(buf, idx, components[upto].Length, delimiter); + NoDelimiter(buf, idx, components[upto].Length, delimiter); return idx + components[upto].Length - start; } @@ -301,7 +301,7 @@ public virtual string ToString(char delimiter) { if (components[i].IndexOf(delimiter) != -1) { - hasDelimiter(components[i], delimiter); + HasDelimiter(components[i], delimiter); } sb.Append(components[i]).Append(delimiter); } diff --git a/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs b/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs index a1e6c88d04..8b47430fae 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs @@ -38,28 +38,28 @@ public class FloatAssociationFacetField : AssociationFacetField /// float association /// public FloatAssociationFacetField(float assoc, string dim, params string[] path) - : base(floatToBytesRef(assoc), dim, path) + : base(FloatToBytesRef(assoc), dim, path) { } /// /// Encodes a {@code float} as a 4-byte . - public static BytesRef floatToBytesRef(float v) + public static BytesRef FloatToBytesRef(float v) { - return IntAssociationFacetField.intToBytesRef(Number.FloatToIntBits(v)); + return IntAssociationFacetField.IntToBytesRef(Number.FloatToIntBits(v)); } /// /// Decodes a previously encoded {@code float}. - public static float bytesRefToFloat(BytesRef b) + public static float BytesRefToFloat(BytesRef b) { - return Number.IntBitsToFloat(IntAssociationFacetField.bytesRefToInt(b)); + return Number.IntBitsToFloat(IntAssociationFacetField.BytesRefToInt(b)); } public override string ToString() { return "FloatAssociationFacetField(dim=" + dim + " path=" + Arrays.ToString(path) + - " value=" + bytesRefToFloat(assoc).ToString("0.0#####", CultureInfo.InvariantCulture) + ")"; + " value=" + BytesRefToFloat(assoc).ToString("0.0#####", CultureInfo.InvariantCulture) + ")"; } } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/IntAssociationFacetField.cs b/src/Lucene.Net.Facet/Taxonomy/IntAssociationFacetField.cs index 417fbd6a8c..1c854fd83a 100644 --- a/src/Lucene.Net.Facet/Taxonomy/IntAssociationFacetField.cs +++ b/src/Lucene.Net.Facet/Taxonomy/IntAssociationFacetField.cs @@ -37,7 +37,7 @@ public class IntAssociationFacetField : AssociationFacetField /// int association /// public IntAssociationFacetField(int assoc, string dim, params string[] path) - : base(intToBytesRef(assoc), dim, path) + : base(IntToBytesRef(assoc), dim, path) { } @@ -45,7 +45,7 @@ public IntAssociationFacetField(int assoc, string dim, params string[] path) /// Encodes an {@code int} as a 4-byte , /// big-endian. ///
- public static BytesRef intToBytesRef(int v) + public static BytesRef IntToBytesRef(int v) { byte[] bytes = new byte[4]; @@ -59,7 +59,7 @@ public static BytesRef intToBytesRef(int v) /// /// Decodes a previously encoded {@code int}. - public static int bytesRefToInt(BytesRef b) + public static int BytesRefToInt(BytesRef b) { return ((b.Bytes[b.Offset] & 0xFF) << 24) | ((b.Bytes[b.Offset + 1] & 0xFF) << 16) | ((b.Bytes[b.Offset + 2] & 0xFF) << 8) | (b.Bytes[b.Offset + 3] & 0xFF); @@ -67,7 +67,7 @@ public static int bytesRefToInt(BytesRef b) public override string ToString() { - return "IntAssociationFacetField(dim=" + dim + " path=" + Arrays.ToString(path) + " value=" + bytesRefToInt(assoc) + ")"; + return "IntAssociationFacetField(dim=" + dim + " path=" + Arrays.ToString(path) + " value=" + BytesRefToInt(assoc) + ")"; } } } \ No newline at end of file From e0a73b45dd4a0faf6b128a271971a9d787b85cc3 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 10:33:03 +0700 Subject: [PATCH 16/41] .NETify Facet: Field names should be camelCase. Fields should not be public (changed to properties with PascalCase names). --- src/Lucene.Net.Facet/DrillSideways.cs | 4 +- src/Lucene.Net.Facet/DrillSidewaysScorer.cs | 4 +- src/Lucene.Net.Facet/FacetField.cs | 10 +-- src/Lucene.Net.Facet/FacetResult.cs | 18 ++-- src/Lucene.Net.Facet/FacetsCollector.cs | 16 ++-- src/Lucene.Net.Facet/FacetsConfig.cs | 39 ++++---- src/Lucene.Net.Facet/LabelAndValue.cs | 32 +++---- .../RandomSamplingFacetsCollector.cs | 14 +-- src/Lucene.Net.Facet/Range/DoubleRange.cs | 8 +- .../Range/DoubleRangeFacetCounts.cs | 16 ++-- src/Lucene.Net.Facet/Range/LongRange.cs | 16 ++-- .../Range/LongRangeFacetCounts.cs | 16 ++-- src/Lucene.Net.Facet/Range/Range.cs | 2 +- .../Range/RangeFacetCounts.cs | 30 +++---- .../SortedSetDocValuesFacetCounts.cs | 10 +-- .../SortedSet/SortedSetDocValuesFacetField.cs | 4 +- .../SortedSetDocValuesReaderState.cs | 4 +- .../Taxonomy/AssociationFacetField.cs | 14 +-- .../Taxonomy/CachedOrdinalsReader.cs | 28 +++--- src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs | 88 +++++++++---------- src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs | 4 +- .../Taxonomy/FastTaxonomyFacetCounts.cs | 4 +- .../Taxonomy/FloatAssociationFacetField.cs | 4 +- .../Taxonomy/FloatTaxonomyFacets.cs | 30 +++---- .../Taxonomy/IntAssociationFacetField.cs | 2 +- .../Taxonomy/IntTaxonomyFacets.cs | 22 ++--- src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs | 22 ++--- .../Taxonomy/SearcherTaxonomyManager.cs | 30 +++---- .../Taxonomy/TaxonomyFacetCounts.cs | 4 +- .../TaxonomyFacetSumFloatAssociations.cs | 4 +- .../TaxonomyFacetSumIntAssociations.cs | 4 +- .../Taxonomy/TaxonomyFacetSumValueSource.cs | 8 +- .../Taxonomy/TaxonomyFacets.cs | 36 ++++---- .../Taxonomy/TaxonomyReader.cs | 8 +- .../Taxonomy/WriterCache/CollisionMap.cs | 30 +++---- src/Lucene.Net.Facet/TopOrdAndFloatQueue.cs | 10 +-- src/Lucene.Net.Facet/TopOrdAndIntQueue.cs | 4 +- src/Lucene.Net.Tests.Facet/FacetTestCase.cs | 18 ++-- .../Range/TestRangeFacetCounts.cs | 24 ++--- .../TestConcurrentFacetedIndexing.cs | 2 +- .../Taxonomy/TestSearcherTaxonomyManager.cs | 16 ++-- .../Taxonomy/TestTaxonomyFacetCounts.cs | 8 +- .../Taxonomy/TestTaxonomyFacetCounts2.cs | 34 +++---- .../TestDrillSideways.cs | 8 +- .../TestFacetsConfig.cs | 2 +- .../TestRandomSamplingFacetsCollector.cs | 6 +- 46 files changed, 359 insertions(+), 358 deletions(-) diff --git a/src/Lucene.Net.Facet/DrillSideways.cs b/src/Lucene.Net.Facet/DrillSideways.cs index 2c71be448d..457bed3ab1 100644 --- a/src/Lucene.Net.Facet/DrillSideways.cs +++ b/src/Lucene.Net.Facet/DrillSideways.cs @@ -272,11 +272,11 @@ public class DrillSidewaysResult { /// /// Combined drill down & sideways results. - public readonly Facets Facets; + public Facets Facets { get; private set; } /// /// Hits. - public readonly TopDocs Hits; + public TopDocs Hits { get; private set; } /// /// Sole constructor. diff --git a/src/Lucene.Net.Facet/DrillSidewaysScorer.cs b/src/Lucene.Net.Facet/DrillSidewaysScorer.cs index bd045c3a3d..13d51e6882 100644 --- a/src/Lucene.Net.Facet/DrillSidewaysScorer.cs +++ b/src/Lucene.Net.Facet/DrillSidewaysScorer.cs @@ -723,8 +723,8 @@ private sealed class FakeScorer : Scorer { private readonly DrillSidewaysScorer outerInstance; - internal float score_Renamed; - internal int doc; + //internal float score_Renamed; // not used + //internal int doc; // not used public FakeScorer(DrillSidewaysScorer outerInstance) : base(null) diff --git a/src/Lucene.Net.Facet/FacetField.cs b/src/Lucene.Net.Facet/FacetField.cs index 5c85936966..794ec319a6 100644 --- a/src/Lucene.Net.Facet/FacetField.cs +++ b/src/Lucene.Net.Facet/FacetField.cs @@ -42,11 +42,11 @@ static FacetField() /// /// Dimension for this field. - public readonly string dim; + public string Dim { get; private set; } /// /// Path for this field. - public readonly string[] path; + public string[] Path { get; private set; } /// /// Creates the this from {@code dim} and @@ -60,17 +60,17 @@ public FacetField(string dim, params string[] path) { VerifyLabel(label); } - this.dim = dim; + this.Dim = dim; if (path.Length == 0) { throw new System.ArgumentException("path must have at least one element"); } - this.path = path; + this.Path = path; } public override string ToString() { - return "FacetField(dim=" + dim + " path=[" + Arrays.ToString(path) + "])"; + return "FacetField(dim=" + Dim + " path=[" + Arrays.ToString(Path) + "])"; } /// diff --git a/src/Lucene.Net.Facet/FacetResult.cs b/src/Lucene.Net.Facet/FacetResult.cs index 5699e6c0f2..7dc73b918e 100644 --- a/src/Lucene.Net.Facet/FacetResult.cs +++ b/src/Lucene.Net.Facet/FacetResult.cs @@ -28,31 +28,31 @@ public sealed class FacetResult { /// /// Dimension that was requested. - public readonly string Dim; + public string Dim { get; private set; } /// /// Path whose children were requested. - public readonly string[] Path; + public string[] Path { get; private set; } /// /// Total value for this path (sum of all child counts, or /// sum of all child values), even those not included in /// the topN. /// - public readonly float Value; + public float Value { get; private set; } /// /// How many child labels were encountered. - public readonly int ChildCount; + public int ChildCount { get; private set; } /// /// Child counts. - public readonly LabelAndValue[] LabelValues; + public LabelAndValue[] LabelValues { get; private set; } /// /// The original data type of that was passed through the constructor. /// - public readonly Type typeOfValue; + public Type TypeOfValue { get; private set; } /// /// Constructor for . Makes the method @@ -62,7 +62,7 @@ public FacetResult(string dim, string[] path, float value, LabelAndValue[] label : this(dim, path, labelValues, childCount) { this.Value = value; - this.typeOfValue = typeof(float); + this.TypeOfValue = typeof(float); } /// @@ -73,7 +73,7 @@ public FacetResult(string dim, string[] path, int value, LabelAndValue[] labelVa : this(dim, path, labelValues, childCount) { this.Value = value; - this.typeOfValue = typeof(int); + this.TypeOfValue = typeof(int); } /// @@ -95,7 +95,7 @@ public override string ToString() sb.Append(" path="); sb.Append("[" + Arrays.ToString(Path) + "]"); sb.Append(" value="); - if (typeOfValue == typeof(int)) + if (TypeOfValue == typeof(int)) { sb.AppendFormat(CultureInfo.InvariantCulture, "{0:0}", Value); // No formatting (looks like int) } diff --git a/src/Lucene.Net.Facet/FacetsCollector.cs b/src/Lucene.Net.Facet/FacetsCollector.cs index 07393673b2..d7be2f0823 100644 --- a/src/Lucene.Net.Facet/FacetsCollector.cs +++ b/src/Lucene.Net.Facet/FacetsCollector.cs @@ -72,28 +72,28 @@ public sealed class MatchingDocs /// /// Context for this segment. - public readonly AtomicReaderContext context; + public AtomicReaderContext Context { get; private set; } /// /// Which documents were seen. - public readonly DocIdSet bits; + public DocIdSet Bits { get; private set; } /// /// Non-sparse scores array. - public readonly float[] scores; + public float[] Scores { get; private set; } /// /// Total number of hits - public readonly int totalHits; + public int TotalHits { get; private set; } /// /// Sole constructor. public MatchingDocs(AtomicReaderContext context, DocIdSet bits, int totalHits, float[] scores) { - this.context = context; - this.bits = bits; - this.scores = scores; - this.totalHits = totalHits; + this.Context = context; + this.Bits = bits; + this.Scores = scores; + this.TotalHits = totalHits; } } diff --git a/src/Lucene.Net.Facet/FacetsConfig.cs b/src/Lucene.Net.Facet/FacetsConfig.cs index 16a0ea3aac..48e97a1fdf 100644 --- a/src/Lucene.Net.Facet/FacetsConfig.cs +++ b/src/Lucene.Net.Facet/FacetsConfig.cs @@ -80,28 +80,29 @@ public sealed class DimConfig { /// /// True if this dimension is hierarchical. - public bool Hierarchical; + public bool Hierarchical { get; set; } /// /// True if this dimension is multi-valued. - public bool MultiValued; + public bool MultiValued { get; set; } /// /// True if the count/aggregate for the entire dimension /// is required, which is unusual (default is false). /// - public bool RequireDimCount; + public bool RequireDimCount { get; set; } /// /// Actual field where this dimension's facet labels /// should be indexed /// - public string IndexFieldName = DEFAULT_INDEX_FIELD_NAME; + public string IndexFieldName { get; set; } /// /// Default constructor. public DimConfig() { + IndexFieldName = DEFAULT_INDEX_FIELD_NAME; } } @@ -288,10 +289,10 @@ public virtual Document Build(ITaxonomyWriter taxoWriter, Document doc) if (field.FieldType == FacetField.TYPE) { FacetField facetField = (FacetField)field; - FacetsConfig.DimConfig dimConfig = GetDimConfig(facetField.dim); + FacetsConfig.DimConfig dimConfig = GetDimConfig(facetField.Dim); if (dimConfig.MultiValued == false) { - CheckSeen(seenDims, facetField.dim); + CheckSeen(seenDims, facetField.Dim); } string indexFieldName = dimConfig.IndexFieldName; IList fields; @@ -324,18 +325,18 @@ public virtual Document Build(ITaxonomyWriter taxoWriter, Document doc) if (field.FieldType == AssociationFacetField.TYPE) { AssociationFacetField facetField = (AssociationFacetField)field; - FacetsConfig.DimConfig dimConfig = GetDimConfig(facetField.dim); + FacetsConfig.DimConfig dimConfig = GetDimConfig(facetField.Dim); if (dimConfig.MultiValued == false) { - CheckSeen(seenDims, facetField.dim); + CheckSeen(seenDims, facetField.Dim); } if (dimConfig.Hierarchical) { - throw new System.ArgumentException("AssociationFacetField cannot be hierarchical (dim=\"" + facetField.dim + "\")"); + throw new System.ArgumentException("AssociationFacetField cannot be hierarchical (dim=\"" + facetField.Dim + "\")"); } if (dimConfig.RequireDimCount) { - throw new System.ArgumentException("AssociationFacetField cannot requireDimCount (dim=\"" + facetField.dim + "\")"); + throw new System.ArgumentException("AssociationFacetField cannot requireDimCount (dim=\"" + facetField.Dim + "\")"); } string indexFieldName = dimConfig.IndexFieldName; @@ -408,13 +409,13 @@ private void ProcessFacetFields(ITaxonomyWriter taxoWriter, IDictionary 1 && ft.Hierarchical == false) + FacetsConfig.DimConfig ft = GetDimConfig(facetField.Dim); + if (facetField.Path.Length > 1 && ft.Hierarchical == false) { - throw new System.ArgumentException("dimension \"" + facetField.dim + "\" is not hierarchical yet has " + facetField.path.Length + " components"); + throw new System.ArgumentException("dimension \"" + facetField.Dim + "\" is not hierarchical yet has " + facetField.Path.Length + " components"); } - FacetLabel cp = new FacetLabel(facetField.dim, facetField.path); + FacetLabel cp = new FacetLabel(facetField.Dim, facetField.Path); CheckTaxoWriter(taxoWriter); int ordinal = taxoWriter.AddCategory(cp); @@ -497,7 +498,7 @@ private void ProcessAssocFacetFields(ITaxonomyWriter taxoWriter, IDictionary bytes.Length) { @@ -508,12 +509,12 @@ private void ProcessAssocFacetFields(ITaxonomyWriter taxoWriter, IDictionary> 16); bytes[upto++] = (byte)(ordinal >> 8); bytes[upto++] = (byte)ordinal; - if (upto + field.assoc.Length > bytes.Length) + if (upto + field.Assoc.Length > bytes.Length) { - bytes = ArrayUtil.Grow(bytes, upto + field.assoc.Length); + bytes = ArrayUtil.Grow(bytes, upto + field.Assoc.Length); } - Array.Copy(field.assoc.Bytes, field.assoc.Offset, bytes, upto, field.assoc.Length); - upto += field.assoc.Length; + Array.Copy(field.Assoc.Bytes, field.Assoc.Offset, bytes, upto, field.Assoc.Length); + upto += field.Assoc.Length; // Drill down: for (int i = 1; i <= label.Length; i++) diff --git a/src/Lucene.Net.Facet/LabelAndValue.cs b/src/Lucene.Net.Facet/LabelAndValue.cs index 1503e3e156..bf6271c413 100644 --- a/src/Lucene.Net.Facet/LabelAndValue.cs +++ b/src/Lucene.Net.Facet/LabelAndValue.cs @@ -28,16 +28,16 @@ public sealed class LabelAndValue { /// /// Facet's label. - public readonly string label; + public string Label { get; private set; } /// /// Value associated with this label. - public readonly float value; + public float Value { get; private set; } /// - /// The original data type of that was passed through the constructor. + /// The original data type of that was passed through the constructor. /// - public readonly Type typeOfValue; + public Type TypeOfValue { get; private set; } /// /// Constructor for . Makes the method @@ -45,9 +45,9 @@ public sealed class LabelAndValue /// public LabelAndValue(string label, float value) { - this.label = label; - this.value = value; - this.typeOfValue = typeof(float); + this.Label = label; + this.Value = value; + this.TypeOfValue = typeof(float); } /// @@ -56,17 +56,17 @@ public LabelAndValue(string label, float value) /// public LabelAndValue(string label, int value) { - this.label = label; - this.value = value; - this.typeOfValue = typeof(int); + this.Label = label; + this.Value = value; + this.TypeOfValue = typeof(int); } public override string ToString() { - string valueString = (typeOfValue == typeof(int)) - ? value.ToString("0", CultureInfo.InvariantCulture) - : value.ToString("0.0#####", CultureInfo.InvariantCulture); - return label + " (" + valueString + ")"; + string valueString = (TypeOfValue == typeof(int)) + ? Value.ToString("0", CultureInfo.InvariantCulture) + : Value.ToString("0.0#####", CultureInfo.InvariantCulture); + return Label + " (" + valueString + ")"; } public override bool Equals(object _other) @@ -76,12 +76,12 @@ public override bool Equals(object _other) return false; } LabelAndValue other = (LabelAndValue)_other; - return label.Equals(other.label) && value.Equals(other.value); + return Label.Equals(other.Label) && Value.Equals(other.Value); } public override int GetHashCode() { - return label.GetHashCode() + 1439 * value.GetHashCode(); + return Label.GetHashCode() + 1439 * Value.GetHashCode(); } } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs b/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs index a662b6a958..6c00c40bf4 100644 --- a/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs +++ b/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs @@ -143,7 +143,7 @@ public override IList GetMatchingDocs totalHits = 0; foreach (MatchingDocs md in matchingDocs) { - totalHits += md.totalHits; + totalHits += md.TotalHits; } } @@ -187,7 +187,7 @@ private IList CreateSampledDocs(IList matchingDocsLi /// Create a sampled of the given hits. private MatchingDocs CreateSample(MatchingDocs docs) { - int maxdoc = docs.context.Reader.MaxDoc; + int maxdoc = docs.Context.Reader.MaxDoc; // TODO: we could try the WAH8DocIdSet here as well, as the results will be sparse FixedBitSet sampleDocs = new FixedBitSet(maxdoc); @@ -210,7 +210,7 @@ private MatchingDocs CreateSample(MatchingDocs docs) limit = binSize; randomIndex = random.NextInt(binSize); } - DocIdSetIterator it = docs.bits.GetIterator(); + DocIdSetIterator it = docs.Bits.GetIterator(); for (int doc = it.NextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = it.NextDoc()) { if (counter == randomIndex) @@ -250,7 +250,7 @@ private MatchingDocs CreateSample(MatchingDocs docs) } } - return new MatchingDocs(docs.context, sampleDocs, docs.totalHits, null); + return new MatchingDocs(docs.Context, sampleDocs, docs.TotalHits, null); } catch (IOException) { @@ -282,12 +282,12 @@ public virtual FacetResult AmortizeFacetCounts(FacetResult res, FacetsConfig con for (int i = 0; i < res.LabelValues.Length; i++) { - childPath[res.Path.Length + 1] = res.LabelValues[i].label; + childPath[res.Path.Length + 1] = res.LabelValues[i].Label; string fullPath = FacetsConfig.PathToString(childPath, childPath.Length); int max = reader.DocFreq(new Term(dimConfig.IndexFieldName, fullPath)); - int correctedCount = (int)((double)res.LabelValues[i].value / samplingRate); + int correctedCount = (int)((double)res.LabelValues[i].Value / samplingRate); correctedCount = Math.Min(max, correctedCount); - fixedLabelValues[i] = new LabelAndValue(res.LabelValues[i].label, correctedCount); + fixedLabelValues[i] = new LabelAndValue(res.LabelValues[i].Label, correctedCount); } // cap the total count on the total number of non-deleted documents in the reader diff --git a/src/Lucene.Net.Facet/Range/DoubleRange.cs b/src/Lucene.Net.Facet/Range/DoubleRange.cs index 93f85cb7cc..058ff52161 100644 --- a/src/Lucene.Net.Facet/Range/DoubleRange.cs +++ b/src/Lucene.Net.Facet/Range/DoubleRange.cs @@ -40,19 +40,19 @@ public sealed class DoubleRange : Range /// /// Minimum. - public readonly double Min; + public double Min { get; private set; } /// /// Maximum. - public readonly double Max; + public double Max { get; private set; } /// /// True if the minimum value is inclusive. - public readonly bool MinInclusive; + public bool MinInclusive { get; private set; } /// /// True if the maximum value is inclusive. - public readonly bool MaxInclusive; + public bool MaxInclusive { get; private set; } private const double EPSILON = 1E-14; /// diff --git a/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs b/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs index 1033a42d06..52a3ad5cb7 100644 --- a/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs +++ b/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs @@ -85,7 +85,7 @@ public DoubleRangeFacetCounts(string field, ValueSource valueSource, FacetsColle private void Count(ValueSource valueSource, IEnumerable matchingDocs) { - DoubleRange[] ranges = (DoubleRange[])this.Ranges; + DoubleRange[] ranges = (DoubleRange[])this.ranges; LongRange[] longRanges = new LongRange[ranges.Length]; for (int i = 0; i < ranges.Length; i++) @@ -99,13 +99,13 @@ private void Count(ValueSource valueSource, IEnumerable matchingDo int missingCount = 0; foreach (MatchingDocs hits in matchingDocs) { - FunctionValues fv = valueSource.GetValues(new Dictionary(), hits.context); + FunctionValues fv = valueSource.GetValues(new Dictionary(), hits.Context); - TotCount += hits.totalHits; + totCount += hits.TotalHits; Bits bits; - if (FastMatchFilter != null) + if (fastMatchFilter != null) { - DocIdSet dis = FastMatchFilter.GetDocIdSet(hits.context, null); + DocIdSet dis = fastMatchFilter.GetDocIdSet(hits.Context, null); if (dis == null) { // No documents match @@ -122,7 +122,7 @@ private void Count(ValueSource valueSource, IEnumerable matchingDo bits = null; } - DocIdSetIterator docs = hits.bits.GetIterator(); + DocIdSetIterator docs = hits.Bits.GetIterator(); int doc; while ((doc = docs.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS) @@ -144,8 +144,8 @@ private void Count(ValueSource valueSource, IEnumerable matchingDo } } - missingCount += counter.FillCounts(Counts); - TotCount -= missingCount; + missingCount += counter.FillCounts(counts); + totCount -= missingCount; } } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Range/LongRange.cs b/src/Lucene.Net.Facet/Range/LongRange.cs index c54456df7a..eb7671b2cf 100644 --- a/src/Lucene.Net.Facet/Range/LongRange.cs +++ b/src/Lucene.Net.Facet/Range/LongRange.cs @@ -39,19 +39,19 @@ public sealed class LongRange : Range /// /// Minimum. - public readonly long min; + public long Min { get; private set; } /// /// Maximum. - public readonly long max; + public long Max { get; private set; } /// /// True if the minimum value is inclusive. - public readonly bool minInclusive; + public bool MinInclusive { get; private set; } /// /// True if the maximum value is inclusive. - public readonly bool maxInclusive; + public bool MaxInclusive { get; private set; } // TODO: can we require fewer args? (same for // Double/FloatRange too) @@ -61,10 +61,10 @@ public sealed class LongRange : Range public LongRange(string label, long minIn, bool minInclusive, long maxIn, bool maxInclusive) : base(label) { - this.min = minIn; - this.max = maxIn; - this.minInclusive = minInclusive; - this.maxInclusive = maxInclusive; + this.Min = minIn; + this.Max = maxIn; + this.MinInclusive = minInclusive; + this.MaxInclusive = maxInclusive; if (!minInclusive) { diff --git a/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs b/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs index 167eb85418..d906cf82db 100644 --- a/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs +++ b/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs @@ -78,20 +78,20 @@ public LongRangeFacetCounts(string field, ValueSource valueSource, private void Count(ValueSource valueSource, IList matchingDocs) { - LongRange[] ranges = (LongRange[])this.Ranges; + LongRange[] ranges = (LongRange[])this.ranges; LongRangeCounter counter = new LongRangeCounter(ranges); int missingCount = 0; foreach (MatchingDocs hits in matchingDocs) { - FunctionValues fv = valueSource.GetValues(new Dictionary(), hits.context); + FunctionValues fv = valueSource.GetValues(new Dictionary(), hits.Context); - TotCount += hits.totalHits; + totCount += hits.TotalHits; Bits bits; - if (FastMatchFilter != null) + if (fastMatchFilter != null) { - DocIdSet dis = FastMatchFilter.GetDocIdSet(hits.context, null); + DocIdSet dis = fastMatchFilter.GetDocIdSet(hits.Context, null); if (dis == null) { // No documents match @@ -108,7 +108,7 @@ private void Count(ValueSource valueSource, IList matchingDocs) bits = null; } - DocIdSetIterator docs = hits.bits.GetIterator(); + DocIdSetIterator docs = hits.Bits.GetIterator(); int doc; while ((doc = docs.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { @@ -129,12 +129,12 @@ private void Count(ValueSource valueSource, IList matchingDocs) } } - int x = counter.FillCounts(Counts); + int x = counter.FillCounts(counts); missingCount += x; //System.out.println("totCount " + totCount + " missingCount " + counter.missingCount); - TotCount -= missingCount; + totCount -= missingCount; } } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Range/Range.cs b/src/Lucene.Net.Facet/Range/Range.cs index c207031ebf..32ea72471e 100644 --- a/src/Lucene.Net.Facet/Range/Range.cs +++ b/src/Lucene.Net.Facet/Range/Range.cs @@ -30,7 +30,7 @@ public abstract class Range /// /// Label that identifies this range. - public readonly string Label; + public string Label { get; private set; } /// /// Sole constructor. diff --git a/src/Lucene.Net.Facet/Range/RangeFacetCounts.cs b/src/Lucene.Net.Facet/Range/RangeFacetCounts.cs index 53a4d26836..e051712582 100644 --- a/src/Lucene.Net.Facet/Range/RangeFacetCounts.cs +++ b/src/Lucene.Net.Facet/Range/RangeFacetCounts.cs @@ -30,11 +30,11 @@ public abstract class RangeFacetCounts : Facets { /// /// Ranges passed to constructor. - protected internal readonly Range[] Ranges; + protected internal readonly Range[] ranges; /// /// Counts, initialized in by subclass. - protected internal readonly int[] Counts; + protected internal readonly int[] counts; /// /// Optional: if specified, we first test this Filter to @@ -42,42 +42,42 @@ public abstract class RangeFacetCounts : Facets /// matching ranges. If this is null, all documents are /// checked. /// - protected internal readonly Filter FastMatchFilter; + protected internal readonly Filter fastMatchFilter; /// /// Our field name. - protected internal readonly string Field; + protected internal readonly string field; /// /// Total number of hits. - protected internal int TotCount; + protected internal int totCount; /// /// Create {@code RangeFacetCounts} protected internal RangeFacetCounts(string field, Range[] ranges, Filter fastMatchFilter) { - this.Field = field; - this.Ranges = ranges; - this.FastMatchFilter = fastMatchFilter; - Counts = new int[ranges.Length]; + this.field = field; + this.ranges = ranges; + this.fastMatchFilter = fastMatchFilter; + counts = new int[ranges.Length]; } public override FacetResult GetTopChildren(int topN, string dim, params string[] path) { - if (dim.Equals(Field) == false) + if (dim.Equals(field) == false) { - throw new System.ArgumentException("invalid dim \"" + dim + "\"; should be \"" + Field + "\""); + throw new System.ArgumentException("invalid dim \"" + dim + "\"; should be \"" + field + "\""); } if (path.Length != 0) { throw new System.ArgumentException("path.length should be 0"); } - LabelAndValue[] labelValues = new LabelAndValue[Counts.Length]; - for (int i = 0; i < Counts.Length; i++) + LabelAndValue[] labelValues = new LabelAndValue[counts.Length]; + for (int i = 0; i < counts.Length; i++) { - labelValues[i] = new LabelAndValue(Ranges[i].Label, Counts[i]); + labelValues[i] = new LabelAndValue(ranges[i].Label, counts[i]); } - return new FacetResult(dim, path, TotCount, labelValues, labelValues.Length); + return new FacetResult(dim, path, totCount, labelValues, labelValues.Length); } public override float GetSpecificValue(string dim, params string[] path) diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs index 1039fffc67..057d274739 100644 --- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs +++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs @@ -172,13 +172,13 @@ private void Count(IList matchingDocs) foreach (FacetsCollector.MatchingDocs hits in matchingDocs) { - var reader = hits.context.AtomicReader; + var reader = hits.Context.AtomicReader; //System.out.println(" reader=" + reader); // LUCENE-5090: make sure the provided reader context "matches" // the top-level reader passed to the // SortedSetDocValuesReaderState, else cryptic // AIOOBE can happen: - if (!Equals(ReaderUtil.GetTopLevelContext(hits.context).Reader, origReader)) + if (!Equals(ReaderUtil.GetTopLevelContext(hits.Context).Reader, origReader)) { throw new InvalidOperationException("the SortedSetDocValuesReaderState provided to this class does not match the reader being searched; you must create a new SortedSetDocValuesReaderState every time you open a new IndexReader"); } @@ -189,7 +189,7 @@ private void Count(IList matchingDocs) continue; } - DocIdSetIterator docs = hits.bits.GetIterator(); + DocIdSetIterator docs = hits.Bits.GetIterator(); // TODO: yet another option is to count all segs // first, only in seg-ord space, and then do a @@ -202,11 +202,11 @@ private void Count(IList matchingDocs) // segs) if (ordinalMap != null) { - int segOrd = hits.context.Ord; + int segOrd = hits.Context.Ord; int numSegOrds = (int)segValues.ValueCount; - if (hits.totalHits < numSegOrds / 10) + if (hits.TotalHits < numSegOrds / 10) { //System.out.println(" remap as-we-go"); // Remap every ord to global ord as we iterate: diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetField.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetField.cs index 372958393a..ba1f360b8f 100644 --- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetField.cs +++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetField.cs @@ -37,11 +37,11 @@ static SortedSetDocValuesFacetField() /// /// Dimension. - public readonly string Dim; + public string Dim { get; private set; } /// /// Label. - public readonly string Label; + public string Label { get; private set; } /// /// Sole constructor. diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesReaderState.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesReaderState.cs index 2b3c2b17ea..f8952109c9 100644 --- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesReaderState.cs +++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesReaderState.cs @@ -51,10 +51,10 @@ public sealed class OrdRange { /// /// Start of range, inclusive: - public readonly int Start; + public int Start { get; private set; } /// /// End of range, inclusive: - public readonly int End; + public int End { get; private set; } /// /// Start and end are inclusive. diff --git a/src/Lucene.Net.Facet/Taxonomy/AssociationFacetField.cs b/src/Lucene.Net.Facet/Taxonomy/AssociationFacetField.cs index 6092f9aecf..f2e70a7fbb 100644 --- a/src/Lucene.Net.Facet/Taxonomy/AssociationFacetField.cs +++ b/src/Lucene.Net.Facet/Taxonomy/AssociationFacetField.cs @@ -48,15 +48,15 @@ static AssociationFacetField() /// /// Dimension for this field. - public readonly string dim; + public string Dim { get; private set; } /// /// Facet path for this field. - public readonly string[] path; + public string[] Path { get; private set; } /// /// Associated value. - public readonly BytesRef assoc; + public BytesRef Assoc { get; private set; } /// /// Creates this from {@code dim} and {@code path} and an @@ -70,18 +70,18 @@ public AssociationFacetField(BytesRef assoc, string dim, params string[] path) { FacetField.VerifyLabel(label); } - this.dim = dim; - this.assoc = assoc; + this.Dim = dim; + this.Assoc = assoc; if (path.Length == 0) { throw new System.ArgumentException("path must have at least one element"); } - this.path = path; + this.Path = path; } public override string ToString() { - return "AssociationFacetField(dim=" + dim + " path=" + Arrays.ToString(path) + " bytes=" + assoc + ")"; + return "AssociationFacetField(dim=" + Dim + " path=" + Arrays.ToString(Path) + " bytes=" + Assoc + ")"; } } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/CachedOrdinalsReader.cs b/src/Lucene.Net.Facet/Taxonomy/CachedOrdinalsReader.cs index 70bbd26069..62ee95f11f 100644 --- a/src/Lucene.Net.Facet/Taxonomy/CachedOrdinalsReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/CachedOrdinalsReader.cs @@ -115,9 +115,9 @@ public OrdinalsSegmentReaderAnonymousInnerClassHelper(CachedOrdinalsReader outer public override void Get(int docID, IntsRef ordinals) { - ordinals.Ints = cachedOrds.ordinals; - ordinals.Offset = cachedOrds.offsets[docID]; - ordinals.Length = cachedOrds.offsets[docID + 1] - ordinals.Offset; + ordinals.Ints = cachedOrds.Ordinals; + ordinals.Offset = cachedOrds.Offsets[docID]; + ordinals.Length = cachedOrds.Offsets[docID + 1] - ordinals.Offset; } } @@ -127,11 +127,11 @@ public sealed class CachedOrds : Accountable { /// /// Index into for each document. - public readonly int[] offsets; + public int[] Offsets { get; private set; } /// /// Holds ords for all docs. - public readonly int[] ordinals; + public int[] Ordinals { get; private set; } /// /// Creates a new from the . @@ -139,7 +139,7 @@ public sealed class CachedOrds : Accountable /// public CachedOrds(OrdinalsSegmentReader source, int maxDoc) { - offsets = new int[maxDoc + 1]; + Offsets = new int[maxDoc + 1]; int[] ords = new int[maxDoc]; // let's assume one ordinal per-document as an initial size // this aggregator is limited to Integer.MAX_VALUE total ordinals. @@ -147,7 +147,7 @@ public CachedOrds(OrdinalsSegmentReader source, int maxDoc) IntsRef values = new IntsRef(32); for (int docID = 0; docID < maxDoc; docID++) { - offsets[docID] = (int)totOrds; + Offsets[docID] = (int)totOrds; source.Get(docID, values); long nextLength = totOrds + values.Length; if (nextLength > ords.Length) @@ -161,26 +161,26 @@ public CachedOrds(OrdinalsSegmentReader source, int maxDoc) Array.Copy(values.Ints, 0, ords, (int)totOrds, values.Length); totOrds = nextLength; } - offsets[maxDoc] = (int)totOrds; + Offsets[maxDoc] = (int)totOrds; // if ords array is bigger by more than 10% of what we really need, shrink it if ((double)totOrds / ords.Length < 0.9) { - this.ordinals = new int[(int)totOrds]; - Array.Copy(ords, 0, this.ordinals, 0, (int)totOrds); + this.Ordinals = new int[(int)totOrds]; + Array.Copy(ords, 0, this.Ordinals, 0, (int)totOrds); } else { - this.ordinals = ords; + this.Ordinals = ords; } } public long RamBytesUsed() { - long mem = RamUsageEstimator.ShallowSizeOf(this) + RamUsageEstimator.SizeOf(offsets); - if (offsets != ordinals) + long mem = RamUsageEstimator.ShallowSizeOf(this) + RamUsageEstimator.SizeOf(Offsets); + if (Offsets != Ordinals) { - mem += RamUsageEstimator.SizeOf(ordinals); + mem += RamUsageEstimator.SizeOf(Ordinals); } return mem; } diff --git a/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs b/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs index d00c50ae92..f168e87929 100644 --- a/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs +++ b/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs @@ -40,17 +40,17 @@ public class CategoryPath : IComparable /// , therefore you should traverse the array up to /// for this path's components. /// - public readonly string[] components; + public string[] Components { get; private set; } /// /// The number of components of this . - public readonly int length; + public int Length { get; private set; } // Used by singleton EMPTY private CategoryPath() { - components = null; - length = 0; + Components = null; + Length = 0; } // Used by subpath @@ -59,9 +59,9 @@ private CategoryPath(CategoryPath copyFrom, int prefixLen) // while the code which calls this method is safe, at some point a test // tripped on AIOOBE in toString, but we failed to reproduce. adding the // assert as a safety check. - Debug.Assert(prefixLen > 0 && prefixLen <= copyFrom.components.Length, "prefixLen cannot be negative nor larger than the given components' length: prefixLen=" + prefixLen + " components.length=" + copyFrom.components.Length); - this.components = copyFrom.components; - length = prefixLen; + Debug.Assert(prefixLen > 0 && prefixLen <= copyFrom.Components.Length, "prefixLen cannot be negative nor larger than the given components' length: prefixLen=" + prefixLen + " components.length=" + copyFrom.Components.Length); + this.Components = copyFrom.Components; + Length = prefixLen; } /// @@ -76,8 +76,8 @@ public CategoryPath(params string[] components) throw new System.ArgumentException("empty or null components not allowed: " + Arrays.ToString(components)); } } - this.components = components; - length = components.Length; + this.Components = components; + Length = components.Length; } /// @@ -87,8 +87,8 @@ public CategoryPath(string pathString, char delimiter) string[] comps = pathString.Split(new[] { delimiter }, StringSplitOptions.RemoveEmptyEntries); if (comps.Length == 1 && comps[0].Length == 0) { - components = null; - length = 0; + Components = null; + Length = 0; } else { @@ -99,8 +99,8 @@ public CategoryPath(string pathString, char delimiter) throw new System.ArgumentException("empty or null components not allowed: " + Arrays.ToString(comps)); } } - components = comps; - length = components.Length; + Components = comps; + Length = Components.Length; } } @@ -111,17 +111,17 @@ public CategoryPath(string pathString, char delimiter) /// public virtual int FullPathLength() { - if (length == 0) + if (Length == 0) { return 0; } int charsNeeded = 0; - for (int i = 0; i < length; i++) + for (int i = 0; i < Length; i++) { - charsNeeded += components[i].Length; + charsNeeded += Components[i].Length; } - charsNeeded += length - 1; // num delimter chars + charsNeeded += Length - 1; // num delimter chars return charsNeeded; } @@ -131,10 +131,10 @@ public virtual int FullPathLength() /// public virtual int CompareTo(CategoryPath other) { - int len = length < other.length ? length : other.length; + int len = Length < other.Length ? Length : other.Length; for (int i = 0, j = 0; i < len; i++, j++) { - int cmp = components[i].CompareTo(other.components[j]); + int cmp = Components[i].CompareTo(other.Components[j]); if (cmp < 0) // this is 'before' { return -1; @@ -146,7 +146,7 @@ public virtual int CompareTo(CategoryPath other) } // one is a prefix of the other - return length - other.length; + return Length - other.Length; } private void HasDelimiter(string offender, char delimiter) @@ -179,25 +179,25 @@ private void NoDelimiter(char[] buf, int offset, int len, char delimiter) /// public virtual int CopyFullPath(char[] buf, int start, char delimiter) { - if (length == 0) + if (Length == 0) { return 0; } int idx = start; - int upto = length - 1; + int upto = Length - 1; for (int i = 0; i < upto; i++) { - int len = components[i].Length; - components[i].CopyTo(0, buf, idx, len - 0); + int len = Components[i].Length; + Components[i].CopyTo(0, buf, idx, len - 0); NoDelimiter(buf, idx, len, delimiter); idx += len; buf[idx++] = delimiter; } - components[upto].CopyTo(0, buf, idx, components[upto].Length - 0); - NoDelimiter(buf, idx, components[upto].Length, delimiter); + Components[upto].CopyTo(0, buf, idx, Components[upto].Length - 0); + NoDelimiter(buf, idx, Components[upto].Length, delimiter); - return idx + components[upto].Length - start; + return idx + Components[upto].Length - start; } public override bool Equals(object obj) @@ -208,16 +208,16 @@ public override bool Equals(object obj) } CategoryPath other = (CategoryPath)obj; - if (length != other.length) + if (Length != other.Length) { return false; // not same length, cannot be equal } // CategoryPaths are more likely to differ at the last components, so start // from last-first - for (int i = length - 1; i >= 0; i--) + for (int i = Length - 1; i >= 0; i--) { - if (!components[i].Equals(other.components[i])) + if (!Components[i].Equals(other.Components[i])) { return false; } @@ -227,15 +227,15 @@ public override bool Equals(object obj) public override int GetHashCode() { - if (length == 0) + if (Length == 0) { return 0; } - int hash = length; - for (int i = 0; i < length; i++) + int hash = Length; + for (int i = 0; i < Length; i++) { - hash = hash * 31 + components[i].GetHashCode(); + hash = hash * 31 + Components[i].GetHashCode(); } return hash; } @@ -244,15 +244,15 @@ public override int GetHashCode() /// Calculate a 64-bit hash function for this path. public virtual long LongHashCode() { - if (length == 0) + if (Length == 0) { return 0; } - long hash = length; - for (int i = 0; i < length; i++) + long hash = Length; + for (int i = 0; i < Length; i++) { - hash = hash * 65599 + components[i].GetHashCode(); + hash = hash * 65599 + Components[i].GetHashCode(); } return hash; } @@ -261,7 +261,7 @@ public virtual long LongHashCode() /// Returns a sub-path of this path up to {@code length} components. public virtual CategoryPath Subpath(int length) { - if (length >= this.length || length < 0) + if (length >= this.Length || length < 0) { return this; } @@ -291,19 +291,19 @@ public override string ToString() /// public virtual string ToString(char delimiter) { - if (length == 0) + if (Length == 0) { return ""; } StringBuilder sb = new StringBuilder(); - for (int i = 0; i < length; i++) + for (int i = 0; i < Length; i++) { - if (components[i].IndexOf(delimiter) != -1) + if (Components[i].IndexOf(delimiter) != -1) { - HasDelimiter(components[i], delimiter); + HasDelimiter(Components[i], delimiter); } - sb.Append(components[i]).Append(delimiter); + sb.Append(Components[i]).Append(delimiter); } sb.Length = sb.Length - 1; // remove last delimiter return sb.ToString(); diff --git a/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs b/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs index 94eb2d6ab3..26dc493342 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs @@ -50,11 +50,11 @@ public class FacetLabel : IComparable /// , therefore you should traverse the array up to /// for this path's components. /// - public readonly string[] Components; + public string[] Components { get; private set; } /// /// The number of components of this . - public readonly int Length; + public int Length { get; private set; } // Used by subpath private FacetLabel(FacetLabel copyFrom, int prefixLen) diff --git a/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs b/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs index f54b70b41a..e303394a65 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs @@ -58,13 +58,13 @@ private void Count(IList matchingDocs) { foreach (FacetsCollector.MatchingDocs hits in matchingDocs) { - BinaryDocValues dv = hits.context.AtomicReader.GetBinaryDocValues(IndexFieldName); + BinaryDocValues dv = hits.Context.AtomicReader.GetBinaryDocValues(indexFieldName); if (dv == null) // this reader does not have DocValues for the requested category list { continue; } - DocIdSetIterator docs = hits.bits.GetIterator(); + DocIdSetIterator docs = hits.Bits.GetIterator(); int doc; BytesRef bytesRef = new BytesRef(); diff --git a/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs b/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs index 8b47430fae..1b070a6e18 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs @@ -58,8 +58,8 @@ public static float BytesRefToFloat(BytesRef b) public override string ToString() { - return "FloatAssociationFacetField(dim=" + dim + " path=" + Arrays.ToString(path) + - " value=" + BytesRefToFloat(assoc).ToString("0.0#####", CultureInfo.InvariantCulture) + ")"; + return "FloatAssociationFacetField(dim=" + Dim + " path=" + Arrays.ToString(Path) + + " value=" + BytesRefToFloat(Assoc).ToString("0.0#####", CultureInfo.InvariantCulture) + ")"; } } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/FloatTaxonomyFacets.cs b/src/Lucene.Net.Facet/Taxonomy/FloatTaxonomyFacets.cs index e0b36886d6..f2e79a5900 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FloatTaxonomyFacets.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FloatTaxonomyFacets.cs @@ -46,15 +46,15 @@ protected internal FloatTaxonomyFacets(string indexFieldName, TaxonomyReader tax protected virtual void Rollup() { // Rollup any necessary dims: - foreach (KeyValuePair ent in Config.DimConfigs) + foreach (KeyValuePair ent in config.DimConfigs) { string dim = ent.Key; FacetsConfig.DimConfig ft = ent.Value; if (ft.Hierarchical && ft.MultiValued == false) { - int dimRootOrd = TaxoReader.GetOrdinal(new FacetLabel(dim)); + int dimRootOrd = taxoReader.GetOrdinal(new FacetLabel(dim)); Debug.Assert(dimRootOrd > 0); - values[dimRootOrd] += Rollup(Children[dimRootOrd]); + values[dimRootOrd] += Rollup(children[dimRootOrd]); } } } @@ -64,10 +64,10 @@ private float Rollup(int ord) float sum = 0; while (ord != TaxonomyReader.INVALID_ORDINAL) { - float childValue = values[ord] + Rollup(Children[ord]); + float childValue = values[ord] + Rollup(children[ord]); values[ord] = childValue; sum += childValue; - ord = Siblings[ord]; + ord = siblings[ord]; } return sum; } @@ -90,7 +90,7 @@ public override float GetSpecificValue(string dim, params string[] path) throw new System.ArgumentException("cannot return dimension-level value alone; use getTopChildren instead"); } } - int ord = TaxoReader.GetOrdinal(new FacetLabel(dim, path)); + int ord = taxoReader.GetOrdinal(new FacetLabel(dim, path)); if (ord < 0) { return -1; @@ -106,16 +106,16 @@ public override FacetResult GetTopChildren(int topN, string dim, params string[] } FacetsConfig.DimConfig dimConfig = VerifyDim(dim); FacetLabel cp = new FacetLabel(dim, path); - int dimOrd = TaxoReader.GetOrdinal(cp); + int dimOrd = taxoReader.GetOrdinal(cp); if (dimOrd == -1) { return null; } - TopOrdAndFloatQueue q = new TopOrdAndFloatQueue(Math.Min(TaxoReader.Size, topN)); + TopOrdAndFloatQueue q = new TopOrdAndFloatQueue(Math.Min(taxoReader.Size, topN)); float bottomValue = 0; - int ord = Children[dimOrd]; + int ord = children[dimOrd]; float sumValues = 0; int childCount = 0; @@ -132,17 +132,17 @@ public override FacetResult GetTopChildren(int topN, string dim, params string[] { reuse = new TopOrdAndFloatQueue.OrdAndValue(); } - reuse.ord = ord; - reuse.value = values[ord]; + reuse.Ord = ord; + reuse.Value = values[ord]; reuse = q.InsertWithOverflow(reuse); if (q.Size() == topN) { - bottomValue = q.Top().value; + bottomValue = q.Top().Value; } } } - ord = Siblings[ord]; + ord = siblings[ord]; } if (sumValues == 0) @@ -171,8 +171,8 @@ public override FacetResult GetTopChildren(int topN, string dim, params string[] for (int i = labelValues.Length - 1; i >= 0; i--) { TopOrdAndFloatQueue.OrdAndValue ordAndValue = q.Pop(); - FacetLabel child = TaxoReader.GetPath(ordAndValue.ord); - labelValues[i] = new LabelAndValue(child.Components[cp.Length], ordAndValue.value); + FacetLabel child = taxoReader.GetPath(ordAndValue.Ord); + labelValues[i] = new LabelAndValue(child.Components[cp.Length], ordAndValue.Value); } return new FacetResult(dim, path, sumValues, labelValues, childCount); diff --git a/src/Lucene.Net.Facet/Taxonomy/IntAssociationFacetField.cs b/src/Lucene.Net.Facet/Taxonomy/IntAssociationFacetField.cs index 1c854fd83a..e7b56d7049 100644 --- a/src/Lucene.Net.Facet/Taxonomy/IntAssociationFacetField.cs +++ b/src/Lucene.Net.Facet/Taxonomy/IntAssociationFacetField.cs @@ -67,7 +67,7 @@ public static int BytesRefToInt(BytesRef b) public override string ToString() { - return "IntAssociationFacetField(dim=" + dim + " path=" + Arrays.ToString(path) + " value=" + BytesRefToInt(assoc) + ")"; + return "IntAssociationFacetField(dim=" + Dim + " path=" + Arrays.ToString(Path) + " value=" + BytesRefToInt(Assoc) + ")"; } } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/IntTaxonomyFacets.cs b/src/Lucene.Net.Facet/Taxonomy/IntTaxonomyFacets.cs index 11f76f05a6..c9a789b054 100644 --- a/src/Lucene.Net.Facet/Taxonomy/IntTaxonomyFacets.cs +++ b/src/Lucene.Net.Facet/Taxonomy/IntTaxonomyFacets.cs @@ -46,18 +46,18 @@ protected internal IntTaxonomyFacets(string indexFieldName, TaxonomyReader taxoR protected virtual void Rollup() { // Rollup any necessary dims: - foreach (KeyValuePair ent in Config.DimConfigs) + foreach (KeyValuePair ent in config.DimConfigs) { string dim = ent.Key; FacetsConfig.DimConfig ft = ent.Value; if (ft.Hierarchical && ft.MultiValued == false) { - int dimRootOrd = TaxoReader.GetOrdinal(new FacetLabel(dim)); + int dimRootOrd = taxoReader.GetOrdinal(new FacetLabel(dim)); // It can be -1 if this field was declared in the // config but never indexed: if (dimRootOrd > 0) { - values[dimRootOrd] += Rollup(Children[dimRootOrd]); + values[dimRootOrd] += Rollup(children[dimRootOrd]); } } } @@ -68,10 +68,10 @@ private int Rollup(int ord) int sum = 0; while (ord != TaxonomyReader.INVALID_ORDINAL) { - int childValue = values[ord] + Rollup(Children[ord]); + int childValue = values[ord] + Rollup(children[ord]); values[ord] = childValue; sum += childValue; - ord = Siblings[ord]; + ord = siblings[ord]; } return sum; } @@ -94,7 +94,7 @@ public override float GetSpecificValue(string dim, params string[] path) throw new System.ArgumentException("cannot return dimension-level value alone; use getTopChildren instead"); } } - int ord = TaxoReader.GetOrdinal(new FacetLabel(dim, path)); + int ord = taxoReader.GetOrdinal(new FacetLabel(dim, path)); if (ord < 0) { return -1; @@ -110,17 +110,17 @@ public override FacetResult GetTopChildren(int topN, string dim, params string[] } var dimConfig = VerifyDim(dim); FacetLabel cp = new FacetLabel(dim, path); - int dimOrd = TaxoReader.GetOrdinal(cp); + int dimOrd = taxoReader.GetOrdinal(cp); if (dimOrd == -1) { return null; } - TopOrdAndIntQueue q = new TopOrdAndIntQueue(Math.Min(TaxoReader.Size, topN)); + TopOrdAndIntQueue q = new TopOrdAndIntQueue(Math.Min(taxoReader.Size, topN)); int bottomValue = 0; - int ord = Children[dimOrd]; + int ord = children[dimOrd]; int totValue = 0; int childCount = 0; @@ -147,7 +147,7 @@ public override FacetResult GetTopChildren(int topN, string dim, params string[] } } - ord = Siblings[ord]; + ord = siblings[ord]; } if (totValue == 0) @@ -176,7 +176,7 @@ public override FacetResult GetTopChildren(int topN, string dim, params string[] for (int i = labelValues.Length - 1; i >= 0; i--) { TopOrdAndIntQueue.OrdAndValue ordAndValue = q.Pop(); - FacetLabel child = TaxoReader.GetPath(ordAndValue.Ord); + FacetLabel child = taxoReader.GetPath(ordAndValue.Ord); labelValues[i] = new LabelAndValue(child.Components[cp.Length], ordAndValue.Value); } diff --git a/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs b/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs index 5d51036a27..1f7883f908 100644 --- a/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs +++ b/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs @@ -95,20 +95,20 @@ public bool Put(TKey key, TValue value) if (cache.TryGetValue(key, out cdo)) { // Item already exists, update our last access time - cdo.Timestamp = GetTimestamp(); + cdo.timestamp = GetTimestamp(); } else { cache[key] = new CacheDataObject { - Value = value, - Timestamp = GetTimestamp() + value = value, + timestamp = GetTimestamp() }; // We have added a new item, so we may need to remove the eldest if (cache.Count > MaxSize) { // Remove the eldest item (lowest timestamp) from the cache - cache.Remove(cache.OrderBy(x => x.Value.Timestamp).First().Key); + cache.Remove(cache.OrderBy(x => x.Value.timestamp).First().Key); } } } @@ -123,9 +123,9 @@ public TValue Get(TKey key) if (cache.TryGetValue(key, out cdo)) { // Write our last access time - cdo.Timestamp = GetTimestamp(); + cdo.timestamp = GetTimestamp(); - return cdo.Value; + return cdo.value; } } return null; @@ -139,8 +139,8 @@ public bool TryGetValue(TKey key, out TValue value) if (cache.TryGetValue(key, out cdo)) { // Write our last access time - cdo.Timestamp = GetTimestamp(); - value = cdo.Value; + cdo.timestamp = GetTimestamp(); + value = cdo.value; return true; } @@ -184,12 +184,12 @@ private long GetTimestamp() private class CacheDataObject { // Ticks representing the last access time - public long Timestamp; - public TValue Value; + public long timestamp; + public TValue value; public override string ToString() { - return "Last Access: " + Timestamp.ToString() + " - " + Value.ToString(); + return "Last Access: " + timestamp.ToString() + " - " + value.ToString(); } } diff --git a/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs b/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs index 6686188b12..2c8edb388c 100644 --- a/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs +++ b/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs @@ -44,24 +44,24 @@ public class SearcherTaxonomyManager : ReferenceManager /// Holds a matched pair of and - /// + /// ///
public class SearcherAndTaxonomy { /// /// Point-in-time . - public readonly IndexSearcher searcher; + public IndexSearcher Searcher { get; private set; } /// /// Matching point-in-time . - public readonly DirectoryTaxonomyReader taxonomyReader; + public DirectoryTaxonomyReader TaxonomyReader { get; private set; } /// /// Create a SearcherAndTaxonomy public SearcherAndTaxonomy(IndexSearcher searcher, DirectoryTaxonomyReader taxonomyReader) { - this.searcher = searcher; - this.taxonomyReader = taxonomyReader; + this.Searcher = searcher; + this.TaxonomyReader = taxonomyReader; } } @@ -113,7 +113,7 @@ public SearcherTaxonomyManager(Store.Directory indexDir, Store.Directory taxoDir protected override void DecRef(SearcherAndTaxonomy @ref) { - @ref.searcher.IndexReader.DecRef(); + @ref.Searcher.IndexReader.DecRef(); // This decRef can fail, and then in theory we should // tryIncRef the searcher to put back the ref count @@ -122,20 +122,20 @@ protected override void DecRef(SearcherAndTaxonomy @ref) // during close, in which case 2) very likely the // searcher was also just closed by the above decRef and // a tryIncRef would fail: - @ref.taxonomyReader.DecRef(); + @ref.TaxonomyReader.DecRef(); } protected override bool TryIncRef(SearcherAndTaxonomy @ref) { - if (@ref.searcher.IndexReader.TryIncRef()) + if (@ref.Searcher.IndexReader.TryIncRef()) { - if (@ref.taxonomyReader.TryIncRef()) + if (@ref.TaxonomyReader.TryIncRef()) { return true; } else { - @ref.searcher.IndexReader.DecRef(); + @ref.Searcher.IndexReader.DecRef(); } } return false; @@ -146,7 +146,7 @@ protected override SearcherAndTaxonomy RefreshIfNeeded(SearcherAndTaxonomy @ref) // Must re-open searcher first, otherwise we may get a // new reader that references ords not yet known to the // taxonomy reader: - IndexReader r = @ref.searcher.IndexReader; + IndexReader r = @ref.Searcher.IndexReader; IndexReader newReader = DirectoryReader.OpenIfChanged((DirectoryReader)r); if (newReader == null) { @@ -154,11 +154,11 @@ protected override SearcherAndTaxonomy RefreshIfNeeded(SearcherAndTaxonomy @ref) } else { - var tr = TaxonomyReader.OpenIfChanged(@ref.taxonomyReader); + var tr = TaxonomyReader.OpenIfChanged(@ref.TaxonomyReader); if (tr == null) { - @ref.taxonomyReader.IncRef(); - tr = @ref.taxonomyReader; + @ref.TaxonomyReader.IncRef(); + tr = @ref.TaxonomyReader; } else if (taxoWriter != null && taxoWriter.TaxonomyEpoch != taxoEpoch) { @@ -172,7 +172,7 @@ protected override SearcherAndTaxonomy RefreshIfNeeded(SearcherAndTaxonomy @ref) protected override int GetRefCount(SearcherAndTaxonomy reference) { - return reference.searcher.IndexReader.RefCount; + return reference.Searcher.IndexReader.RefCount; } } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs index af008c7985..059822c724 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs @@ -53,8 +53,8 @@ private void Count(IList matchingDocs) IntsRef scratch = new IntsRef(); foreach (FacetsCollector.MatchingDocs hits in matchingDocs) { - OrdinalsReader.OrdinalsSegmentReader ords = ordinalsReader.GetReader(hits.context); - DocIdSetIterator docs = hits.bits.GetIterator(); + OrdinalsReader.OrdinalsSegmentReader ords = ordinalsReader.GetReader(hits.Context); + DocIdSetIterator docs = hits.Bits.GetIterator(); int doc; while ((doc = docs.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS) diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs index 821c942045..b943004d3e 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs @@ -58,13 +58,13 @@ private void SumValues(IList matchingDocs) //System.out.println("count matchingDocs=" + matchingDocs + " facetsField=" + facetsFieldName); foreach (FacetsCollector.MatchingDocs hits in matchingDocs) { - BinaryDocValues dv = hits.context.AtomicReader.GetBinaryDocValues(IndexFieldName); + BinaryDocValues dv = hits.Context.AtomicReader.GetBinaryDocValues(indexFieldName); if (dv == null) // this reader does not have DocValues for the requested category list { continue; } - DocIdSetIterator docs = hits.bits.GetIterator(); + DocIdSetIterator docs = hits.Bits.GetIterator(); int doc; while ((doc = docs.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS) diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs index 8d835fbc89..d053dfeb1f 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs @@ -57,13 +57,13 @@ private void SumValues(IList matchingDocs) //System.out.println("count matchingDocs=" + matchingDocs + " facetsField=" + facetsFieldName); foreach (FacetsCollector.MatchingDocs hits in matchingDocs) { - BinaryDocValues dv = hits.context.AtomicReader.GetBinaryDocValues(IndexFieldName); + BinaryDocValues dv = hits.Context.AtomicReader.GetBinaryDocValues(indexFieldName); if (dv == null) // this reader does not have DocValues for the requested category list { continue; } - DocIdSetIterator docs = hits.bits.GetIterator(); + DocIdSetIterator docs = hits.Bits.GetIterator(); int doc; while ((doc = docs.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS) diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs index 4981f336b8..2ae0f49d3e 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs @@ -129,13 +129,13 @@ private void SumValues(IList matchingDocs, bool keepScores, ValueS IntsRef scratch = new IntsRef(); foreach (MatchingDocs hits in matchingDocs) { - OrdinalsReader.OrdinalsSegmentReader ords = ordinalsReader.GetReader(hits.context); + OrdinalsReader.OrdinalsSegmentReader ords = ordinalsReader.GetReader(hits.Context); int scoresIdx = 0; - float[] scores = hits.scores; + float[] scores = hits.Scores; - FunctionValues functionValues = valueSource.GetValues(context, hits.context); - DocIdSetIterator docs = hits.bits.GetIterator(); + FunctionValues functionValues = valueSource.GetValues(context, hits.Context); + DocIdSetIterator docs = hits.Bits.GetIterator(); int doc; while ((doc = docs.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS) diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs index 03baa55efc..c0ae7584ac 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs @@ -54,39 +54,39 @@ public virtual int Compare(FacetResult a, FacetResult b) /// /// Index field name provided to the constructor. - protected readonly string IndexFieldName; + protected readonly string indexFieldName; /// /// {@code TaxonomyReader} provided to the constructor. - protected readonly TaxonomyReader TaxoReader; + protected readonly TaxonomyReader taxoReader; /// /// {@code FacetsConfig} provided to the constructor. - protected readonly FacetsConfig Config; + protected readonly FacetsConfig config; /// /// Maps parent ordinal to its child, or -1 if the parent /// is childless. /// - protected readonly int[] Children; + protected readonly int[] children; /// /// Maps an ordinal to its sibling, or -1 if there is no /// sibling. /// - protected readonly int[] Siblings; + protected readonly int[] siblings; /// /// Sole constructor. /// protected internal TaxonomyFacets(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config) { - this.IndexFieldName = indexFieldName; - this.TaxoReader = taxoReader; - this.Config = config; + this.indexFieldName = indexFieldName; + this.taxoReader = taxoReader; + this.config = config; ParallelTaxonomyArrays pta = taxoReader.ParallelTaxonomyArrays; - Children = pta.Children(); - Siblings = pta.Siblings(); + children = pta.Children(); + siblings = pta.Siblings(); } /// @@ -96,23 +96,23 @@ protected internal TaxonomyFacets(string indexFieldName, TaxonomyReader taxoRead /// protected internal virtual DimConfig VerifyDim(string dim) { - DimConfig dimConfig = Config.GetDimConfig(dim); - if (!dimConfig.IndexFieldName.Equals(IndexFieldName)) + DimConfig dimConfig = config.GetDimConfig(dim); + if (!dimConfig.IndexFieldName.Equals(indexFieldName)) { - throw new System.ArgumentException("dimension \"" + dim + "\" was not indexed into field \"" + IndexFieldName); + throw new System.ArgumentException("dimension \"" + dim + "\" was not indexed into field \"" + indexFieldName); } return dimConfig; } public override IList GetAllDims(int topN) { - int ord = Children[TaxonomyReader.ROOT_ORDINAL]; + int ord = children[TaxonomyReader.ROOT_ORDINAL]; IList results = new List(); while (ord != TaxonomyReader.INVALID_ORDINAL) { - string dim = TaxoReader.GetPath(ord).Components[0]; - DimConfig dimConfig = Config.GetDimConfig(dim); - if (dimConfig.IndexFieldName.Equals(IndexFieldName)) + string dim = taxoReader.GetPath(ord).Components[0]; + DimConfig dimConfig = config.GetDimConfig(dim); + if (dimConfig.IndexFieldName.Equals(indexFieldName)) { FacetResult result = GetTopChildren(topN, dim); if (result != null) @@ -120,7 +120,7 @@ public override IList GetAllDims(int topN) results.Add(result); } } - ord = Siblings[ord]; + ord = siblings[ord]; } // Sort by highest value, tie break by dim: diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs index f303abbb53..f94ebe4d20 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs @@ -133,7 +133,7 @@ public static T OpenIfChanged(T oldTaxoReader) where T : TaxonomyReader return newTaxoReader; } - private volatile bool Closed = false; + private volatile bool closed = false; // set refCount to 1 at start private readonly AtomicInteger refCount = new AtomicInteger(1); @@ -168,10 +168,10 @@ public virtual void Dispose(bool disposing) { lock (this) { - if (!Closed) + if (!closed) { DecRef(); - Closed = true; + closed = true; } } } @@ -192,7 +192,7 @@ public void DecRef() try { DoClose(); - Closed = true; + closed = true; success = true; } finally diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs index 9e8c1ad208..277a166601 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs @@ -29,9 +29,9 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache /// public class CollisionMap { - private int capacity_Renamed; + private int capacity; private float loadFactor; - private int size_Renamed; + private int size; private int threshold; internal class Entry @@ -68,17 +68,17 @@ private CollisionMap(int initialCapacity, float loadFactor, CharBlockArray label { this.labelRepository = labelRepository; this.loadFactor = loadFactor; - this.capacity_Renamed = CompactLabelToOrdinal.DetermineCapacity(2, initialCapacity); + this.capacity = CompactLabelToOrdinal.DetermineCapacity(2, initialCapacity); - this.entries = new Entry[this.capacity_Renamed]; - this.threshold = (int)(this.capacity_Renamed * this.loadFactor); + this.entries = new Entry[this.capacity]; + this.threshold = (int)(this.capacity * this.loadFactor); } /// /// How many mappings. public virtual int Size() { - return this.size_Renamed; + return this.size; } /// @@ -86,12 +86,12 @@ public virtual int Size() /// public virtual int Capacity() { - return this.capacity_Renamed; + return this.capacity; } private void Grow() { - int newCapacity = this.capacity_Renamed * 2; + int newCapacity = this.capacity * 2; Entry[] newEntries = new Entry[newCapacity]; Entry[] src = this.entries; @@ -113,9 +113,9 @@ private void Grow() } } - this.capacity_Renamed = newCapacity; + this.capacity = newCapacity; this.entries = newEntries; - this.threshold = (int)(this.capacity_Renamed * this.loadFactor); + this.threshold = (int)(this.capacity * this.loadFactor); } /// @@ -125,7 +125,7 @@ private void Grow() /// public virtual int Get(FacetLabel label, int hash) { - int bucketIndex = IndexFor(hash, this.capacity_Renamed); + int bucketIndex = IndexFor(hash, this.capacity); Entry e = this.entries[bucketIndex]; while (e != null && !(hash == e.hash && CategoryPathUtils.EqualsToSerialized(label, labelRepository, e.offset))) @@ -145,7 +145,7 @@ public virtual int Get(FacetLabel label, int hash) /// public virtual int AddLabel(FacetLabel label, int hash, int cid) { - int bucketIndex = IndexFor(hash, this.capacity_Renamed); + int bucketIndex = IndexFor(hash, this.capacity); for (Entry e = this.entries[bucketIndex]; e != null; e = e.next) { if (e.hash == hash && CategoryPathUtils.EqualsToSerialized(label, labelRepository, e.offset)) @@ -168,7 +168,7 @@ public virtual int AddLabel(FacetLabel label, int hash, int cid) /// public virtual void AddLabelOffset(int hash, int offset, int cid) { - int bucketIndex = IndexFor(hash, this.capacity_Renamed); + int bucketIndex = IndexFor(hash, this.capacity); AddEntry(offset, cid, hash, bucketIndex); } @@ -176,7 +176,7 @@ private void AddEntry(int offset, int cid, int hash, int bucketIndex) { Entry e = this.entries[bucketIndex]; this.entries[bucketIndex] = new Entry(offset, cid, hash, e); - if (this.size_Renamed++ >= this.threshold) + if (this.size++ >= this.threshold) { Grow(); } @@ -184,7 +184,7 @@ private void AddEntry(int offset, int cid, int hash, int bucketIndex) internal virtual IEnumerator entryIterator() { - return new EntryIterator(this, entries, size_Renamed); + return new EntryIterator(this, entries, size); } /// diff --git a/src/Lucene.Net.Facet/TopOrdAndFloatQueue.cs b/src/Lucene.Net.Facet/TopOrdAndFloatQueue.cs index 4b4dad7210..9c81f3103b 100644 --- a/src/Lucene.Net.Facet/TopOrdAndFloatQueue.cs +++ b/src/Lucene.Net.Facet/TopOrdAndFloatQueue.cs @@ -31,11 +31,11 @@ public sealed class OrdAndValue { /// /// Ordinal of the entry. - public int ord; + public int Ord { get; set; } /// /// Value associated with the ordinal. - public float value; + public float Value { get; set; } /// /// Default constructor. @@ -52,17 +52,17 @@ public TopOrdAndFloatQueue(int topN) : base(topN, false) public override bool LessThan(OrdAndValue a, OrdAndValue b) { - if (a.value < b.value) + if (a.Value < b.Value) { return true; } - else if (a.value > b.value) + else if (a.Value > b.Value) { return false; } else { - return a.ord > b.ord; + return a.Ord > b.Ord; } } } diff --git a/src/Lucene.Net.Facet/TopOrdAndIntQueue.cs b/src/Lucene.Net.Facet/TopOrdAndIntQueue.cs index 80246e55a1..7016e806e8 100644 --- a/src/Lucene.Net.Facet/TopOrdAndIntQueue.cs +++ b/src/Lucene.Net.Facet/TopOrdAndIntQueue.cs @@ -31,11 +31,11 @@ public sealed class OrdAndValue { /// /// Ordinal of the entry. - public int Ord; + public int Ord { get; set; } /// /// Value associated with the ordinal. - public int Value; + public int Value { get; set; } /// /// Default constructor. diff --git a/src/Lucene.Net.Tests.Facet/FacetTestCase.cs b/src/Lucene.Net.Tests.Facet/FacetTestCase.cs index ccc5cdfdb1..7c4b3c1c40 100644 --- a/src/Lucene.Net.Tests.Facet/FacetTestCase.cs +++ b/src/Lucene.Net.Tests.Facet/FacetTestCase.cs @@ -146,7 +146,7 @@ protected internal virtual void SortTies(LabelAndValue[] labelValues) int i = 0; while (i <= labelValues.Length) { - if (i < labelValues.Length && (double)labelValues[i].value == lastValue) + if (i < labelValues.Length && (double)labelValues[i].Value == lastValue) { numInRow++; } @@ -159,7 +159,7 @@ protected internal virtual void SortTies(LabelAndValue[] labelValues) numInRow = 1; if (i < labelValues.Length) { - lastValue = (double)labelValues[i].value; + lastValue = (double)labelValues[i].Value; } } i++; @@ -177,8 +177,8 @@ public ComparatorAnonymousInnerClassHelper(FacetTestCase outerInstance) public virtual int Compare(LabelAndValue a, LabelAndValue b) { - Debug.Assert((double)a.value == (double)b.value); - return (new BytesRef(a.label)).CompareTo(new BytesRef(b.label)); + Debug.Assert((double)a.Value == (double)b.Value); + return (new BytesRef(a.Label)).CompareTo(new BytesRef(b.Label)); } } @@ -198,17 +198,17 @@ public ComparatorAnonymousInnerClassHelper2(FacetTestCase outerInstance) public virtual int Compare(LabelAndValue a, LabelAndValue b) { - if ((double)a.value > (double)b.value) + if ((double)a.Value > (double)b.Value) { return -1; } - else if ((double)a.value < (double)b.value) + else if ((double)a.Value < (double)b.Value) { return 1; } else { - return (new BytesRef(a.label)).CompareTo(new BytesRef(b.label)); + return (new BytesRef(a.Label)).CompareTo(new BytesRef(b.Label)); } } } @@ -278,8 +278,8 @@ protected internal virtual void AssertFloatValuesEquals(FacetResult a, FacetResu Assert.AreEqual(a.LabelValues.Length, b.LabelValues.Length); for (int i = 0; i < a.LabelValues.Length; i++) { - Assert.AreEqual(a.LabelValues[i].label, b.LabelValues[i].label); - Assert.AreEqual((float)a.LabelValues[i].value, (float)b.LabelValues[i].value, (float)a.LabelValues[i].value / 1e5); + Assert.AreEqual(a.LabelValues[i].Label, b.LabelValues[i].Label); + Assert.AreEqual((float)a.LabelValues[i].Value, (float)b.LabelValues[i].Value, (float)a.LabelValues[i].Value / 1e5); } } } diff --git a/src/Lucene.Net.Tests.Facet/Range/TestRangeFacetCounts.cs b/src/Lucene.Net.Tests.Facet/Range/TestRangeFacetCounts.cs index e3a2623748..d39cefd794 100644 --- a/src/Lucene.Net.Tests.Facet/Range/TestRangeFacetCounts.cs +++ b/src/Lucene.Net.Tests.Facet/Range/TestRangeFacetCounts.cs @@ -433,11 +433,11 @@ public virtual void TestRandomLongs() LongRange prevRange = ranges[Random().Next(rangeID)]; if (Random().NextBoolean()) { - min = prevRange.min; + min = prevRange.Min; } else { - min = prevRange.max; + min = prevRange.Max; } } else @@ -451,11 +451,11 @@ public virtual void TestRandomLongs() LongRange prevRange = ranges[Random().Next(rangeID)]; if (Random().NextBoolean()) { - max = prevRange.min; + max = prevRange.Min; } else { - max = prevRange.max; + max = prevRange.Max; } } else @@ -546,8 +546,8 @@ public virtual void TestRandomLongs() Console.WriteLine(" range " + rangeID + " expectedCount=" + expectedCounts[rangeID]); } LabelAndValue subNode = result.LabelValues[rangeID]; - Assert.AreEqual("r" + rangeID, subNode.label); - Assert.AreEqual(expectedCounts[rangeID], (int)subNode.value); + Assert.AreEqual("r" + rangeID, subNode.Label); + Assert.AreEqual(expectedCounts[rangeID], (int)subNode.Value); LongRange range = ranges[rangeID]; @@ -557,11 +557,11 @@ public virtual void TestRandomLongs() { if (Random().NextBoolean()) { - ddq.Add("field", NumericRangeFilter.NewLongRange("field", range.min, range.max, range.minInclusive, range.maxInclusive)); + ddq.Add("field", NumericRangeFilter.NewLongRange("field", range.Min, range.Max, range.MinInclusive, range.MaxInclusive)); } else { - ddq.Add("field", NumericRangeQuery.NewLongRange("field", range.min, range.max, range.minInclusive, range.maxInclusive)); + ddq.Add("field", NumericRangeQuery.NewLongRange("field", range.Min, range.Max, range.MinInclusive, range.MaxInclusive)); } } else @@ -751,8 +751,8 @@ public virtual void TestRandomFloats() Console.WriteLine("TEST: verify range " + rangeID + " expectedCount=" + expectedCounts[rangeID]); } LabelAndValue subNode = result.LabelValues[rangeID]; - Assert.AreEqual("r" + rangeID, subNode.label); - Assert.AreEqual(expectedCounts[rangeID], (int)subNode.value); + Assert.AreEqual("r" + rangeID, subNode.Label); + Assert.AreEqual(expectedCounts[rangeID], (int)subNode.Value); DoubleRange range = ranges[rangeID]; @@ -937,8 +937,8 @@ public virtual void TestRandomDoubles() Console.WriteLine(" range " + rangeID + " expectedCount=" + expectedCounts[rangeID]); } LabelAndValue subNode = result.LabelValues[rangeID]; - Assert.AreEqual("r" + rangeID, subNode.label); - Assert.AreEqual(expectedCounts[rangeID], (int)subNode.value); + Assert.AreEqual("r" + rangeID, subNode.Label); + Assert.AreEqual(expectedCounts[rangeID], (int)subNode.Value); DoubleRange range = ranges[rangeID]; diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs index f2c0fe7ca8..8c3664956d 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs @@ -203,7 +203,7 @@ public override void Run() FacetField ff = NewCategory(); doc.Add(ff); - FacetLabel label = new FacetLabel(ff.dim, ff.path); + FacetLabel label = new FacetLabel(ff.Dim, ff.Path); // add all prefixes to values int level = label.Length; while (level > 0) diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs index 0d02696907..79f8b8074a 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs @@ -175,10 +175,10 @@ public virtual void TestNrt() { //System.out.println("search maxOrd=" + pair.taxonomyReader.getSize()); FacetsCollector sfc = new FacetsCollector(); - pair.searcher.Search(new MatchAllDocsQuery(), sfc); - Facets facets = GetTaxonomyFacetCounts(pair.taxonomyReader, config, sfc); + pair.Searcher.Search(new MatchAllDocsQuery(), sfc); + Facets facets = GetTaxonomyFacetCounts(pair.TaxonomyReader, config, sfc); FacetResult result = facets.GetTopChildren(10, "field"); - if (pair.searcher.IndexReader.NumDocs > 0) + if (pair.Searcher.IndexReader.NumDocs > 0) { //System.out.println(pair.taxonomyReader.getSize()); Assert.True(result.ChildCount > 0); @@ -283,10 +283,10 @@ public virtual void TestDirectory() { //System.out.println("search maxOrd=" + pair.taxonomyReader.getSize()); FacetsCollector sfc = new FacetsCollector(); - pair.searcher.Search(new MatchAllDocsQuery(), sfc); - Facets facets = GetTaxonomyFacetCounts(pair.taxonomyReader, config, sfc); + pair.Searcher.Search(new MatchAllDocsQuery(), sfc); + Facets facets = GetTaxonomyFacetCounts(pair.TaxonomyReader, config, sfc); FacetResult result = facets.GetTopChildren(10, "field"); - if (pair.searcher.IndexReader.NumDocs > 0) + if (pair.Searcher.IndexReader.NumDocs > 0) { //System.out.println(pair.taxonomyReader.getSize()); Assert.True(result.ChildCount > 0); @@ -365,7 +365,7 @@ public virtual void TestReplaceTaxonomyDirectory() SearcherAndTaxonomy pair = mgr.Acquire(); try { - Assert.AreEqual(1, pair.taxonomyReader.Size); + Assert.AreEqual(1, pair.TaxonomyReader.Size); } finally { @@ -382,7 +382,7 @@ public virtual void TestReplaceTaxonomyDirectory() pair = mgr.Acquire(); try { - Assert.AreEqual(3, pair.taxonomyReader.Size); + Assert.AreEqual(3, pair.TaxonomyReader.Size); } finally { diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs index 263a1d27b0..6bee101edf 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs @@ -362,7 +362,7 @@ public virtual void TestMultiValuedHierarchy() FacetResult result = facets.GetTopChildren(10, "a"); Assert.AreEqual(1, result.LabelValues.Length); - Assert.AreEqual(1, (int)result.LabelValues[0].value); + Assert.AreEqual(1, (int)result.LabelValues[0].Value); IOUtils.Close(writer, taxoWriter, searcher.IndexReader, taxoReader, dir, taxoDir); } @@ -502,8 +502,8 @@ public virtual void TestManyFacetsInOneDocument() var allLabels = new HashSet(); foreach (LabelAndValue labelValue in result.LabelValues) { - allLabels.Add(labelValue.label); - Assert.AreEqual(1, (int)labelValue.value); + allLabels.Add(labelValue.Label); + Assert.AreEqual(1, (int)labelValue.Value); } Assert.AreEqual(numLabels, allLabels.Count); @@ -744,7 +744,7 @@ public virtual void TestSegmentsWithoutCategoriesOrResults() Assert.AreEqual(2, result.LabelValues.Length, "wrong number of children"); foreach (LabelAndValue labelValue in result.LabelValues) { - Assert.AreEqual(2, (int)labelValue.value, "wrong weight for child " + labelValue.label); + Assert.AreEqual(2, (int)labelValue.Value, "wrong weight for child " + labelValue.Label); } IOUtils.Close(indexReader, taxoReader, indexDir, taxoDir); diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts2.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts2.cs index 6f4cb8bec0..09d1119604 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts2.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts2.cs @@ -126,7 +126,7 @@ private static void AddFacets(Document doc, FacetsConfig config, bool updateTerm foreach (FacetField ff in docCategories) { doc.Add(ff); - string cp = ff.dim + "/" + ff.path[0]; + string cp = ff.Dim + "/" + ff.Path[0]; allExpectedCounts[cp] = allExpectedCounts[cp] + 1; if (updateTermExpectedCounts) { @@ -228,19 +228,19 @@ private static void IndexDocsWithFacetsAndSomeTerms(IndexWriter indexWriter, ITa counts[CP_D] = 0; foreach (FacetField ff in CATEGORIES_A) { - counts[ff.dim + "/" + ff.path[0]] = 0; + counts[ff.Dim + "/" + ff.Path[0]] = 0; } foreach (FacetField ff in CATEGORIES_B) { - counts[ff.dim + "/" + ff.path[0]] = 0; + counts[ff.Dim + "/" + ff.Path[0]] = 0; } foreach (FacetField ff in CATEGORIES_C) { - counts[ff.dim + "/" + ff.path[0]] = 0; + counts[ff.Dim + "/" + ff.Path[0]] = 0; } foreach (FacetField ff in CATEGORIES_D) { - counts[ff.dim + "/" + ff.path[0]] = 0; + counts[ff.Dim + "/" + ff.Path[0]] = 0; } return counts; } @@ -296,13 +296,13 @@ public virtual void TestDifferentNumResults() Assert.AreEqual(-1, (int)result.Value); foreach (LabelAndValue labelValue in result.LabelValues) { - Assert.AreEqual(termExpectedCounts[CP_A + "/" + labelValue.label], labelValue.value); + Assert.AreEqual(termExpectedCounts[CP_A + "/" + labelValue.Label], labelValue.Value); } result = facets.GetTopChildren(NUM_CHILDREN_CP_B, CP_B); Assert.AreEqual(termExpectedCounts[CP_B], result.Value); foreach (LabelAndValue labelValue in result.LabelValues) { - Assert.AreEqual(termExpectedCounts[CP_B + "/" + labelValue.label], labelValue.value); + Assert.AreEqual(termExpectedCounts[CP_B + "/" + labelValue.Label], labelValue.Value); } IOUtils.Close(indexReader, taxoReader); @@ -325,9 +325,9 @@ public virtual void TestAllCounts() int prevValue = int.MaxValue; foreach (LabelAndValue labelValue in result.LabelValues) { - Assert.AreEqual(allExpectedCounts[CP_A + "/" + labelValue.label], labelValue.value); - Assert.True((int)labelValue.value <= prevValue, "wrong sort order of sub results: labelValue.value=" + labelValue.value + " prevValue=" + prevValue); - prevValue = (int)labelValue.value; + Assert.AreEqual(allExpectedCounts[CP_A + "/" + labelValue.Label], labelValue.Value); + Assert.True((int)labelValue.Value <= prevValue, "wrong sort order of sub results: labelValue.value=" + labelValue.Value + " prevValue=" + prevValue); + prevValue = (int)labelValue.Value; } result = facets.GetTopChildren(NUM_CHILDREN_CP_B, CP_B); @@ -335,9 +335,9 @@ public virtual void TestAllCounts() prevValue = int.MaxValue; foreach (LabelAndValue labelValue in result.LabelValues) { - Assert.AreEqual(allExpectedCounts[CP_B + "/" + labelValue.label], labelValue.value); - Assert.True((int)labelValue.value <= prevValue, "wrong sort order of sub results: labelValue.value=" + labelValue.value + " prevValue=" + prevValue); - prevValue = (int)labelValue.value; + Assert.AreEqual(allExpectedCounts[CP_B + "/" + labelValue.Label], labelValue.Value); + Assert.True((int)labelValue.Value <= prevValue, "wrong sort order of sub results: labelValue.value=" + labelValue.Value + " prevValue=" + prevValue); + prevValue = (int)labelValue.Value; } IOUtils.Close(indexReader, taxoReader); @@ -359,13 +359,13 @@ public virtual void TestBigNumResults() Assert.AreEqual(-1, (int)result.Value); foreach (LabelAndValue labelValue in result.LabelValues) { - Assert.AreEqual(allExpectedCounts[CP_A + "/" + labelValue.label], labelValue.value); + Assert.AreEqual(allExpectedCounts[CP_A + "/" + labelValue.Label], labelValue.Value); } result = facets.GetTopChildren(int.MaxValue, CP_B); Assert.AreEqual(allExpectedCounts[CP_B], result.Value); foreach (LabelAndValue labelValue in result.LabelValues) { - Assert.AreEqual(allExpectedCounts[CP_B + "/" + labelValue.label], labelValue.value); + Assert.AreEqual(allExpectedCounts[CP_B + "/" + labelValue.Label], labelValue.Value); } IOUtils.Close(indexReader, taxoReader); @@ -387,13 +387,13 @@ public virtual void TestNoParents() Assert.AreEqual(allExpectedCounts[CP_C], result.Value); foreach (LabelAndValue labelValue in result.LabelValues) { - Assert.AreEqual(allExpectedCounts[CP_C + "/" + labelValue.label], labelValue.value); + Assert.AreEqual(allExpectedCounts[CP_C + "/" + labelValue.Label], labelValue.Value); } result = facets.GetTopChildren(NUM_CHILDREN_CP_D, CP_D); Assert.AreEqual(allExpectedCounts[CP_C], result.Value); foreach (LabelAndValue labelValue in result.LabelValues) { - Assert.AreEqual(allExpectedCounts[CP_D + "/" + labelValue.label], labelValue.value); + Assert.AreEqual(allExpectedCounts[CP_D + "/" + labelValue.Label], labelValue.Value); } IOUtils.Close(indexReader, taxoReader); diff --git a/src/Lucene.Net.Tests.Facet/TestDrillSideways.cs b/src/Lucene.Net.Tests.Facet/TestDrillSideways.cs index 719e2124a9..e32693d2fc 100644 --- a/src/Lucene.Net.Tests.Facet/TestDrillSideways.cs +++ b/src/Lucene.Net.Tests.Facet/TestDrillSideways.cs @@ -1213,10 +1213,10 @@ internal virtual void VerifyEquals(string[][] dimValues, IndexSearcher s, TestFa { foreach (LabelAndValue labelValue in fr.LabelValues) { - actualValues[labelValue.label] = (int)labelValue.value; + actualValues[labelValue.Label] = (int)labelValue.Value; if (VERBOSE) { - Console.WriteLine(" " + idx + ": " + new BytesRef(labelValue.label) + ": " + labelValue.value); + Console.WriteLine(" " + idx + ": " + new BytesRef(labelValue.Label) + ": " + labelValue.Value); idx++; } } @@ -1254,12 +1254,12 @@ internal virtual void VerifyEquals(string[][] dimValues, IndexSearcher s, TestFa for (int i = 0; i < topNIDs.Length; i++) { int expectedOrd = topNIDs[i]; - Assert.AreEqual(expected.Counts[dim][expectedOrd], (int)fr.LabelValues[i].value); + Assert.AreEqual(expected.Counts[dim][expectedOrd], (int)fr.LabelValues[i].Value); if (isSortedSetDV) { // Tie-break facet labels are only in unicode // order with SortedSetDVFacets: - assertEquals("value @ idx=" + i, dimValues[dim][expectedOrd], fr.LabelValues[i].label); + assertEquals("value @ idx=" + i, dimValues[dim][expectedOrd], fr.LabelValues[i].Label); } } } diff --git a/src/Lucene.Net.Tests.Facet/TestFacetsConfig.cs b/src/Lucene.Net.Tests.Facet/TestFacetsConfig.cs index 9c14f7975c..73a4123ddc 100644 --- a/src/Lucene.Net.Tests.Facet/TestFacetsConfig.cs +++ b/src/Lucene.Net.Tests.Facet/TestFacetsConfig.cs @@ -90,7 +90,7 @@ public virtual void TestAddSameDocTwice() Facets facets = GetTaxonomyFacetCounts(taxoReader, facetsConfig, fc); FacetResult res = facets.GetTopChildren(10, "a"); Assert.AreEqual(1, res.LabelValues.Length); - Assert.AreEqual(2, res.LabelValues[0].value); + Assert.AreEqual(2, res.LabelValues[0].Value); IOUtils.Close(indexReader, taxoReader); IOUtils.Close(indexDir, taxoDir); diff --git a/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs b/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs index 7b5915b260..29694365d2 100644 --- a/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs +++ b/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs @@ -80,7 +80,7 @@ public virtual void TestRandomSampling() // There should be no results at all foreach (MatchingDocs doc in collectRandomZeroResults.GetMatchingDocs) { - Assert.AreEqual(0, doc.totalHits); + Assert.AreEqual(0, doc.TotalHits); } // Now start searching and retrieve results. @@ -125,14 +125,14 @@ public virtual void TestRandomSampling() int sum = 0; foreach (LabelAndValue lav in random10Result.LabelValues) { - sum += (int)lav.value; + sum += (int)lav.Value; } float mu = (float)sum / (float)maxNumChildren; float variance = 0; foreach (LabelAndValue lav in random10Result.LabelValues) { - variance += (float)Math.Pow((mu - (int)lav.value), 2); + variance += (float)Math.Pow((mu - (int)lav.Value), 2); } variance = variance / maxNumChildren; float sigma = (float)Math.Sqrt(variance); From e72d3cbf1fb8a1d2ee76b6d6c311960893daa456 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 10:43:36 +0700 Subject: [PATCH 17/41] .NETify Facet: Renamed method from entryIterator() to GetEnumerator() --- src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs | 2 +- .../Taxonomy/WriterCache/CompactLabelToOrdinal.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs index 277a166601..fd47cd9cfc 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs @@ -182,7 +182,7 @@ private void AddEntry(int offset, int cid, int hash, int bucketIndex) } } - internal virtual IEnumerator entryIterator() + internal virtual IEnumerator GetEnumerator() { return new EntryIterator(this, entries, size); } diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs index 28f93c4fc7..0ea11226b2 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs @@ -208,7 +208,7 @@ private void Grow() this.collisionMap = new CollisionMap(oldCollisionMap.Capacity(), this.labelRepository); this.threshold = (int)(this.capacity * this.loadFactor); - var it = oldCollisionMap.entryIterator(); + var it = oldCollisionMap.GetEnumerator(); while (it.MoveNext()) { From e4b7e0ba9924265db97a0699da7487f6acd6f759 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 12:06:55 +0700 Subject: [PATCH 18/41] Fixed bug in Facet.Taxonomy.Directory.DirectoryTaxonomyWriter.MemoryOrdinalMap - setting size has no effect on the size of the array. --- .../Taxonomy/Directory/DirectoryTaxonomyWriter.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs index a1c1939f77..b6dc7a1f48 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs @@ -995,7 +995,10 @@ public MemoryOrdinalMap() map = new int[] { }; } - public int Size { set; private get; } + public int Size + { + set { map = new int[value]; } + } public void AddMapping(int origOrdinal, int newOrdinal) { From 8d23d138ac51e8a73d87ab13b2cb657d06263f87 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 13:22:53 +0700 Subject: [PATCH 19/41] Fixed Facet.Taxonomy.Directory.TaxonomyIndexArrays _renamed variable names. --- .../Taxonomy/Directory/TaxonomyIndexArrays.cs | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/TaxonomyIndexArrays.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/TaxonomyIndexArrays.cs index 2319550334..ec0b33a773 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/TaxonomyIndexArrays.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/TaxonomyIndexArrays.cs @@ -35,26 +35,26 @@ namespace Lucene.Net.Facet.Taxonomy.Directory /// internal class TaxonomyIndexArrays : ParallelTaxonomyArrays { - private readonly int[] parents_Renamed; + private readonly int[] parents; // the following two arrays are lazily intialized. note that we only keep a // single boolean member as volatile, instead of declaring the arrays // volatile. the code guarantees that only after the boolean is set to true, // the arrays are returned. private volatile bool initializedChildren = false; - private int[] children_Renamed, siblings_Renamed; + private int[] children, siblings; /// /// Used by after the array grew. private TaxonomyIndexArrays(int[] parents) { - this.parents_Renamed = parents; + this.parents = parents; } public TaxonomyIndexArrays(IndexReader reader) { - parents_Renamed = new int[reader.MaxDoc]; - if (parents_Renamed.Length > 0) + parents = new int[reader.MaxDoc]; + if (parents.Length > 0) { InitParents(reader, 0); // Starting Lucene 2.9, following the change LUCENE-1542, we can @@ -64,7 +64,7 @@ public TaxonomyIndexArrays(IndexReader reader) // with existing indexes, so what we'll do instead is just // hard-code the parent of ordinal 0 to be -1, and assume (as is // indeed the case) that no other parent can be -1. - parents_Renamed[0] = TaxonomyReader.INVALID_ORDINAL; + parents[0] = TaxonomyReader.INVALID_ORDINAL; } } @@ -77,8 +77,8 @@ public TaxonomyIndexArrays(IndexReader reader, TaxonomyIndexArrays copyFrom) // NRT reader was obtained, even though nothing was changed. this is not very likely // to happen. int[] copyParents = copyFrom.Parents(); - this.parents_Renamed = new int[reader.MaxDoc]; - Array.Copy(copyParents, 0, parents_Renamed, 0, copyParents.Length); + this.parents = new int[reader.MaxDoc]; + Array.Copy(copyParents, 0, parents, 0, copyParents.Length); InitParents(reader, copyParents.Length); if (copyFrom.initializedChildren) @@ -93,14 +93,14 @@ private void InitChildrenSiblings(TaxonomyIndexArrays copyFrom) { if (!initializedChildren) // must do this check ! { - children_Renamed = new int[parents_Renamed.Length]; - siblings_Renamed = new int[parents_Renamed.Length]; + children = new int[parents.Length]; + siblings = new int[parents.Length]; if (copyFrom != null) { // called from the ctor, after we know copyFrom has initialized children/siblings - Array.Copy(copyFrom.Children(), 0, children_Renamed, 0, copyFrom.Children().Length); - Array.Copy(copyFrom.Siblings(), 0, siblings_Renamed, 0, copyFrom.Siblings().Length); - ComputeChildrenSiblings(copyFrom.parents_Renamed.Length); + Array.Copy(copyFrom.Children(), 0, children, 0, copyFrom.Children().Length); + Array.Copy(copyFrom.Siblings(), 0, siblings, 0, copyFrom.Siblings().Length); + ComputeChildrenSiblings(copyFrom.parents.Length); } else { @@ -116,24 +116,24 @@ private void ComputeChildrenSiblings(int first) // reset the youngest child of all ordinals. while this should be done only // for the leaves, we don't know up front which are the leaves, so we reset // all of them. - for (int i = first; i < parents_Renamed.Length; i++) + for (int i = first; i < parents.Length; i++) { - children_Renamed[i] = TaxonomyReader.INVALID_ORDINAL; + children[i] = TaxonomyReader.INVALID_ORDINAL; } // the root category has no parent, and therefore no siblings if (first == 0) { first = 1; - siblings_Renamed[0] = TaxonomyReader.INVALID_ORDINAL; + siblings[0] = TaxonomyReader.INVALID_ORDINAL; } - for (int i = first; i < parents_Renamed.Length; i++) + for (int i = first; i < parents.Length; i++) { // note that parents[i] is always < i, so the right-hand-side of // the following line is already set when we get here - siblings_Renamed[i] = children_Renamed[parents_Renamed[i]]; - children_Renamed[parents_Renamed[i]] = i; + siblings[i] = children[parents[i]]; + children[parents[i]] = i; } } @@ -166,7 +166,7 @@ private void InitParents(IndexReader reader, int first) throw new CorruptIndexException("Missing parent data for category " + i); } - parents_Renamed[i] = positions.NextPosition(); + parents[i] = positions.NextPosition(); if (positions.NextDoc() == DocIdSetIterator.NO_MORE_DOCS) { @@ -193,13 +193,13 @@ private void InitParents(IndexReader reader, int first) /// internal virtual TaxonomyIndexArrays Add(int ordinal, int parentOrdinal) { - if (ordinal >= parents_Renamed.Length) + if (ordinal >= parents.Length) { - int[] newarray = ArrayUtil.Grow(parents_Renamed, ordinal + 1); + int[] newarray = ArrayUtil.Grow(parents, ordinal + 1); newarray[ordinal] = parentOrdinal; return new TaxonomyIndexArrays(newarray); } - parents_Renamed[ordinal] = parentOrdinal; + parents[ordinal] = parentOrdinal; return this; } @@ -209,7 +209,7 @@ internal virtual TaxonomyIndexArrays Add(int ordinal, int parentOrdinal) /// public override int[] Parents() { - return parents_Renamed; + return parents; } /// @@ -226,7 +226,7 @@ public override int[] Children() } // the array is guaranteed to be populated - return children_Renamed; + return children; } /// @@ -242,7 +242,7 @@ public override int[] Siblings() } // the array is guaranteed to be populated - return siblings_Renamed; + return siblings; } } } \ No newline at end of file From e76ee907c4302bc1765847892ca790153dd845fe Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 14:17:24 +0700 Subject: [PATCH 20/41] Fixed string CompareTo to match Java --- .../SortedSet/SortedSetDocValuesFacetCounts.cs | 5 +++-- src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs | 2 +- src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs | 2 +- src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs index 057d274739..95ee9d1ad2 100644 --- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs +++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs @@ -1,4 +1,5 @@ -using System; +using Lucene.Net.Support; +using System; using System.Collections.Generic; using System.Linq; @@ -329,7 +330,7 @@ public virtual int Compare(FacetResult a, FacetResult b) } else { - return a.Dim.CompareTo(b.Dim); + return a.Dim.CompareToOrdinal(b.Dim); } } } diff --git a/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs b/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs index f168e87929..ae177b65ef 100644 --- a/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs +++ b/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs @@ -134,7 +134,7 @@ public virtual int CompareTo(CategoryPath other) int len = Length < other.Length ? Length : other.Length; for (int i = 0, j = 0; i < len; i++, j++) { - int cmp = Components[i].CompareTo(other.Components[j]); + int cmp = Components[i].CompareToOrdinal(other.Components[j]); if (cmp < 0) // this is 'before' { return -1; diff --git a/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs b/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs index 26dc493342..edc68c0a99 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs @@ -114,7 +114,7 @@ public virtual int CompareTo(FacetLabel other) int len = Length < other.Length ? Length : other.Length; for (int i = 0, j = 0; i < len; i++, j++) { - int cmp = Components[i].CompareTo(other.Components[j]); + int cmp = Components[i].CompareToOrdinal(other.Components[j]); if (cmp < 0) { return -1; // this is 'before' diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs index c0ae7584ac..1a5399419f 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs @@ -1,4 +1,5 @@ -using System; +using Lucene.Net.Support; +using System; using System.Collections.Generic; using System.Linq; @@ -47,7 +48,7 @@ public virtual int Compare(FacetResult a, FacetResult b) } else { - return a.Dim.CompareTo(b.Dim); + return a.Dim.CompareToOrdinal(b.Dim); } } } From 9912999c154159dfcf0f87106132fb85a763271f Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 14:40:30 +0700 Subject: [PATCH 21/41] Facet: Changed accessibility of class members to match Java Lucene. --- src/Lucene.Net.Facet/Range/DoubleRange.cs | 8 +++---- src/Lucene.Net.Facet/Range/LongRange.cs | 12 +++++------ .../DefaultSortedSetDocValuesReaderState.cs | 2 +- .../Directory/DirectoryTaxonomyWriter.cs | 10 ++++----- .../Taxonomy/TaxonomyReader.cs | 4 ++-- .../Taxonomy/WriterCache/CharBlockArray.cs | 21 +++++++++---------- 6 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/Lucene.Net.Facet/Range/DoubleRange.cs b/src/Lucene.Net.Facet/Range/DoubleRange.cs index 058ff52161..affdf26cce 100644 --- a/src/Lucene.Net.Facet/Range/DoubleRange.cs +++ b/src/Lucene.Net.Facet/Range/DoubleRange.cs @@ -178,10 +178,10 @@ private class DocIdSetAnonymousInnerClassHelper : DocIdSet { private readonly FilterAnonymousInnerClassHelper outerInstance; - private Bits acceptDocs; - private FunctionValues values; - private int maxDoc; - private Bits fastMatchBits; + private readonly Bits acceptDocs; + private readonly FunctionValues values; + private readonly int maxDoc; + private readonly Bits fastMatchBits; public DocIdSetAnonymousInnerClassHelper(FilterAnonymousInnerClassHelper outerInstance, Bits acceptDocs, FunctionValues values, int maxDoc, Bits fastMatchBits) { diff --git a/src/Lucene.Net.Facet/Range/LongRange.cs b/src/Lucene.Net.Facet/Range/LongRange.cs index eb7671b2cf..7b245f928a 100644 --- a/src/Lucene.Net.Facet/Range/LongRange.cs +++ b/src/Lucene.Net.Facet/Range/LongRange.cs @@ -120,8 +120,8 @@ private class FilterAnonymousInnerClassHelper : Filter { private readonly LongRange outerInstance; - private Filter fastMatchFilter; - private ValueSource valueSource; + private readonly Filter fastMatchFilter; + private readonly ValueSource valueSource; public FilterAnonymousInnerClassHelper(LongRange outerInstance, Filter fastMatchFilter, ValueSource valueSource) { @@ -175,10 +175,10 @@ private class DocIdSetAnonymousInnerClassHelper : DocIdSet { private readonly FilterAnonymousInnerClassHelper outerInstance; - private Bits acceptDocs; - private FunctionValues values; - private int maxDoc; - private Bits fastMatchBits; + private readonly Bits acceptDocs; + private readonly FunctionValues values; + private readonly int maxDoc; + private readonly Bits fastMatchBits; public DocIdSetAnonymousInnerClassHelper(FilterAnonymousInnerClassHelper outerInstance, Bits acceptDocs, FunctionValues values, int maxDoc, Bits fastMatchBits) { diff --git a/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs b/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs index 10983d8bd4..a5806c304e 100644 --- a/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs +++ b/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs @@ -33,7 +33,7 @@ public class DefaultSortedSetDocValuesReaderState : SortedSetDocValuesReaderStat /// /// passed to the constructor. - public readonly IndexReader origReader; + private readonly IndexReader origReader; private readonly IDictionary prefixToOrdRange = new Dictionary(); diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs index b6dc7a1f48..e4f2d3b111 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs @@ -582,11 +582,11 @@ private int AddCategoryDocument(FacetLabel categoryPath, int parent) private class SinglePositionTokenStream : TokenStream { - internal ICharTermAttribute termAtt; - internal IPositionIncrementAttribute posIncrAtt; - internal bool returned; - internal int val; - internal readonly string word; + private ICharTermAttribute termAtt; + private IPositionIncrementAttribute posIncrAtt; + private bool returned; + private int val; + private readonly string word; public SinglePositionTokenStream(string word) { diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs index f94ebe4d20..4dc391e5cc 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs @@ -70,8 +70,8 @@ public abstract class TaxonomyReader /// An iterator over a category's children. public class ChildrenIterator { - internal readonly int[] siblings; - internal int child; + private readonly int[] siblings; + private int child; internal ChildrenIterator(int child, int[] siblings) { diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs index 691ed4124e..60a0726417 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs @@ -92,12 +92,12 @@ internal virtual int IndexInBlock(int index) return index % blockSize; } - public CharBlockArray Append(ICharSequence chars) + public virtual CharBlockArray Append(ICharSequence chars) { return Append(chars, 0, chars.Length); } - public CharBlockArray Append(char c) + public virtual CharBlockArray Append(char c) { if (this.current.length == this.blockSize) { @@ -109,7 +109,7 @@ public CharBlockArray Append(char c) return this; } - public CharBlockArray Append(ICharSequence chars, int start, int length) + public virtual CharBlockArray Append(ICharSequence chars, int start, int length) { int end = start + length; for (int i = start; i < end; i++) @@ -170,8 +170,13 @@ public virtual CharBlockArray Append(string s) this.length_Renamed += s.Length; return this; } + public virtual char CharAt(int index) + { + Block b = blocks[BlockIndex(index)]; + return b.chars[IndexInBlock(index)]; + } - public int Length + public virtual int Length { get { @@ -179,13 +184,7 @@ public int Length } } - public char CharAt(int index) - { - Block b = blocks[BlockIndex(index)]; - return b.chars[IndexInBlock(index)]; - } - - public string SubSequence(int start, int end) + public virtual string SubSequence(int start, int end) { int remaining = end - start; StringBuilder sb = new StringBuilder(remaining); From f50f913d565ff8d1e90285c8a8af239dbae313f2 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 15:10:27 +0700 Subject: [PATCH 22/41] Facets: Return List rather than IList to prevent having to do too many O(n) operations on the results. --- src/Lucene.Net.Facet/Facets.cs | 2 +- src/Lucene.Net.Facet/MultiFacets.cs | 4 ++-- src/Lucene.Net.Facet/Range/RangeFacetCounts.cs | 4 ++-- .../SortedSet/SortedSetDocValuesFacetCounts.cs | 6 +++--- src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Lucene.Net.Facet/Facets.cs b/src/Lucene.Net.Facet/Facets.cs index 405d1b3adf..ce17c15644 100644 --- a/src/Lucene.Net.Facet/Facets.cs +++ b/src/Lucene.Net.Facet/Facets.cs @@ -53,6 +53,6 @@ public Facets() /// different dimensions were indexed, for example /// depending on the type of document. /// - public abstract IList GetAllDims(int topN); + public abstract List GetAllDims(int topN); } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/MultiFacets.cs b/src/Lucene.Net.Facet/MultiFacets.cs index 051de44946..79bb07795b 100644 --- a/src/Lucene.Net.Facet/MultiFacets.cs +++ b/src/Lucene.Net.Facet/MultiFacets.cs @@ -67,10 +67,10 @@ public override float GetSpecificValue(string dim, params string[] path) return facets.GetSpecificValue(dim, path); } - public override IList GetAllDims(int topN) + public override List GetAllDims(int topN) { - IList results = new List(); + List results = new List(); // First add the specific dim's facets: foreach (KeyValuePair ent in dimToFacets) diff --git a/src/Lucene.Net.Facet/Range/RangeFacetCounts.cs b/src/Lucene.Net.Facet/Range/RangeFacetCounts.cs index e051712582..943f4e1577 100644 --- a/src/Lucene.Net.Facet/Range/RangeFacetCounts.cs +++ b/src/Lucene.Net.Facet/Range/RangeFacetCounts.cs @@ -86,9 +86,9 @@ public override float GetSpecificValue(string dim, params string[] path) throw new System.NotSupportedException(); } - public override IList GetAllDims(int topN) + public override List GetAllDims(int topN) { - return new[] { GetTopChildren(topN, null) }; + return new List { GetTopChildren(topN, null) }; } } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs index 95ee9d1ad2..b32d430a83 100644 --- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs +++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs @@ -291,7 +291,7 @@ public override float GetSpecificValue(string dim, params string[] path) return counts[ord]; } - public override IList GetAllDims(int topN) + public override List GetAllDims(int topN) { IList results = new List(); foreach (KeyValuePair ent in state.PrefixToOrdRange) @@ -303,9 +303,9 @@ public override IList GetAllDims(int topN) } } - var resultArray = results.ToArray(); + var resultArray = results.ToList(); // Sort by highest count: - Array.Sort(resultArray, new ComparatorAnonymousInnerClassHelper(this)); + resultArray.Sort(new ComparatorAnonymousInnerClassHelper(this)); return resultArray; } diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs index 1a5399419f..51a073fb7d 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs @@ -105,7 +105,7 @@ protected internal virtual DimConfig VerifyDim(string dim) return dimConfig; } - public override IList GetAllDims(int topN) + public override List GetAllDims(int topN) { int ord = children[TaxonomyReader.ROOT_ORDINAL]; IList results = new List(); @@ -125,8 +125,8 @@ public override IList GetAllDims(int topN) } // Sort by highest value, tie break by dim: - var resultArray = results.ToArray(); - Array.Sort(resultArray, BY_VALUE_THEN_DIM); + var resultArray = results.ToList(); + resultArray.Sort(BY_VALUE_THEN_DIM); return resultArray; } } From 0bc313025481fbd698f0dbb773a8fa27ade18d0f Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 15:18:47 +0700 Subject: [PATCH 23/41] Facet.Taxononmy.Directory.DirectoryTaxonomyWriter.IOrdinalMap: Renamed Size back to the original SetSize() because it changes the internal state of the object. --- .../Directory/DirectoryTaxonomyWriter.cs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs index e4f2d3b111..d25cd1b67d 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs @@ -905,7 +905,7 @@ public virtual void AddTaxonomy(Directory taxoDir, IOrdinalMap map) { int size = r.NumDocs; IOrdinalMap ordinalMap = map; - ordinalMap.Size = size; + ordinalMap.SetSize(size); int @base = 0; TermsEnum te = null; DocsEnum docs = null; @@ -957,7 +957,7 @@ public interface IOrdinalMap /// called exactly 'size' times, with different origOrdinals between 0 /// and size-1. /// - int Size { set; } + void SetSize(int taxonomySize); /// /// Record a mapping. @@ -995,9 +995,9 @@ public MemoryOrdinalMap() map = new int[] { }; } - public int Size + public void SetSize(int taxonomySize) { - set { map = new int[value]; } + map = new int[taxonomySize]; } public void AddMapping(int origOrdinal, int newOrdinal) @@ -1011,8 +1011,6 @@ public void AddMapping(int origOrdinal, int newOrdinal) Array.Resize(ref map, origOrdinal + 1); map[origOrdinal] = newOrdinal; } - - } public void AddDone() // nothing to do @@ -1051,12 +1049,9 @@ public void AddMapping(int origOrdinal, int newOrdinal) @out.WriteInt(newOrdinal); } - public int Size + public void SetSize(int taxonomySize) { - set - { - @out.WriteInt(value); - } + @out.WriteInt(taxonomySize); } public void AddDone() From 67b29ee32249c88628db4a8a4ddd1e69cc6a9694 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 15:31:19 +0700 Subject: [PATCH 24/41] Changed Facet.Taxonomy.ParallelTaxonomyArrays methods Parents, Children, and Siblings to be properties. --- .../Directory/DirectoryTaxonomyWriter.cs | 2 +- .../Taxonomy/Directory/TaxonomyIndexArrays.cs | 43 +++++++++------- .../Taxonomy/ParallelTaxonomyArrays.cs | 6 +-- .../Taxonomy/TaxonomyFacets.cs | 4 +- .../Taxonomy/TaxonomyReader.cs | 4 +- .../TestConcurrentFacetedIndexing.cs | 2 +- .../Directory/TestDirectoryTaxonomyReader.cs | 10 ++-- .../Directory/TestDirectoryTaxonomyWriter.cs | 2 +- .../Taxonomy/TestTaxonomyCombined.cs | 50 +++++++++---------- 9 files changed, 66 insertions(+), 57 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs index d25cd1b67d..b07940ea48 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs @@ -886,7 +886,7 @@ public virtual int GetParent(int ordinal) throw new System.IndexOutOfRangeException("requested ordinal is bigger than the largest ordinal in the taxonomy"); } - int[] parents = TaxoArrays.Parents(); + int[] parents = TaxoArrays.Parents; Debug.Assert(ordinal < parents.Length, "requested ordinal (" + ordinal + "); parents.length (" + parents.Length + ") !"); return parents[ordinal]; } diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/TaxonomyIndexArrays.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/TaxonomyIndexArrays.cs index ec0b33a773..9cbaaed8d0 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/TaxonomyIndexArrays.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/TaxonomyIndexArrays.cs @@ -76,7 +76,7 @@ public TaxonomyIndexArrays(IndexReader reader, TaxonomyIndexArrays copyFrom) // it may be caused if e.g. the taxonomy segments were merged, and so an updated // NRT reader was obtained, even though nothing was changed. this is not very likely // to happen. - int[] copyParents = copyFrom.Parents(); + int[] copyParents = copyFrom.Parents; this.parents = new int[reader.MaxDoc]; Array.Copy(copyParents, 0, parents, 0, copyParents.Length); InitParents(reader, copyParents.Length); @@ -98,8 +98,8 @@ private void InitChildrenSiblings(TaxonomyIndexArrays copyFrom) if (copyFrom != null) { // called from the ctor, after we know copyFrom has initialized children/siblings - Array.Copy(copyFrom.Children(), 0, children, 0, copyFrom.Children().Length); - Array.Copy(copyFrom.Siblings(), 0, siblings, 0, copyFrom.Siblings().Length); + Array.Copy(copyFrom.Children, 0, children, 0, copyFrom.Children.Length); + Array.Copy(copyFrom.Siblings, 0, siblings, 0, copyFrom.Siblings.Length); ComputeChildrenSiblings(copyFrom.parents.Length); } else @@ -207,9 +207,12 @@ internal virtual TaxonomyIndexArrays Add(int ordinal, int parentOrdinal) /// Returns the parents array, where {@code parents[i]} denotes the parent of /// category ordinal {@code i}. /// - public override int[] Parents() + public override int[] Parents { - return parents; + get + { + return parents; + } } /// @@ -218,15 +221,18 @@ public override int[] Parents() /// category that was added last to the taxonomy as an immediate child of /// {@code i}. /// - public override int[] Children() + public override int[] Children { - if (!initializedChildren) + get { - InitChildrenSiblings(null); - } + if (!initializedChildren) + { + InitChildrenSiblings(null); + } - // the array is guaranteed to be populated - return children; + // the array is guaranteed to be populated + return children; + } } /// @@ -234,15 +240,18 @@ public override int[] Children() /// of category ordinal {@code i}. The sibling is defined as the previous /// youngest child of {@code parents[i]}. /// - public override int[] Siblings() + public override int[] Siblings { - if (!initializedChildren) + get { - InitChildrenSiblings(null); - } + if (!initializedChildren) + { + InitChildrenSiblings(null); + } - // the array is guaranteed to be populated - return siblings; + // the array is guaranteed to be populated + return siblings; + } } } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/ParallelTaxonomyArrays.cs b/src/Lucene.Net.Facet/Taxonomy/ParallelTaxonomyArrays.cs index 60e351e8c6..1b51568441 100644 --- a/src/Lucene.Net.Facet/Taxonomy/ParallelTaxonomyArrays.cs +++ b/src/Lucene.Net.Facet/Taxonomy/ParallelTaxonomyArrays.cs @@ -52,18 +52,18 @@ public ParallelTaxonomyArrays() /// Returns the parents array, where {@code parents[i]} denotes the parent of /// category ordinal {@code i}. /// - public abstract int[] Parents(); + public abstract int[] Parents { get; } /// /// Returns the children array, where {@code children[i]} denotes a child of /// category ordinal {@code i}. /// - public abstract int[] Children(); + public abstract int[] Children { get; } /// /// Returns the siblings array, where {@code siblings[i]} denotes the sibling /// of category ordinal {@code i}. /// - public abstract int[] Siblings(); + public abstract int[] Siblings { get; } } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs index 51a073fb7d..ef8dedecf4 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs @@ -86,8 +86,8 @@ protected internal TaxonomyFacets(string indexFieldName, TaxonomyReader taxoRead this.taxoReader = taxoReader; this.config = config; ParallelTaxonomyArrays pta = taxoReader.ParallelTaxonomyArrays; - children = pta.Children(); - siblings = pta.Siblings(); + children = pta.Children; + siblings = pta.Siblings; } /// diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs index 4dc391e5cc..e99b011965 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs @@ -221,8 +221,8 @@ public void DecRef() public virtual ChildrenIterator GetChildren(int ordinal) { ParallelTaxonomyArrays arrays = ParallelTaxonomyArrays; - int child = ordinal >= 0 ? arrays.Children()[ordinal] : INVALID_ORDINAL; - return new ChildrenIterator(child, arrays.Siblings()); + int child = ordinal >= 0 ? arrays.Children[ordinal] : INVALID_ORDINAL; + return new ChildrenIterator(child, arrays.Siblings); } /// diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs index 8c3664956d..52a4d618b3 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs @@ -148,7 +148,7 @@ public virtual void TestConcurrency() } Fail("mismatch number of categories"); } - int[] parents = tr.ParallelTaxonomyArrays.Parents(); + int[] parents = tr.ParallelTaxonomyArrays.Parents; foreach (string cat in values.Keys) { FacetLabel cp = new FacetLabel(FacetsConfig.StringToPath(cat)); diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs index d0801dd209..0e2935ac98 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs @@ -253,7 +253,7 @@ public virtual void TestOpenIfChangedManySegments() // assert categories Assert.AreEqual(numCategories, reader.Size); int roundOrdinal = reader.GetOrdinal(new FacetLabel(Convert.ToString(i))); - int[] parents = reader.ParallelTaxonomyArrays.Parents(); + int[] parents = reader.ParallelTaxonomyArrays.Parents; Assert.AreEqual(0, parents[roundOrdinal]); // round's parent is root for (int j = 0; j < numCats; j++) { @@ -306,7 +306,7 @@ public virtual void TestOpenIfChangedMergedSegment() var reader = new DirectoryTaxonomyReader(writer); Assert.AreEqual(1, reader.Size); - Assert.AreEqual(1, reader.ParallelTaxonomyArrays.Parents().Length); + Assert.AreEqual(1, reader.ParallelTaxonomyArrays.Parents.Length); // add category and call forceMerge -- this should flush IW and merge segments down to 1 // in ParentArray.initFromReader, this used to fail assuming there are no parents. @@ -319,7 +319,7 @@ public virtual void TestOpenIfChangedMergedSegment() reader.Dispose(); reader = newtr; Assert.AreEqual(2, reader.Size); - Assert.AreEqual(2, reader.ParallelTaxonomyArrays.Parents().Length); + Assert.AreEqual(2, reader.ParallelTaxonomyArrays.Parents.Length); reader.Dispose(); writer.Dispose(); @@ -367,7 +367,7 @@ public virtual void TestOpenIfChangedNoChangesButSegmentMerges() var reader = new DirectoryTaxonomyReader(writer); Assert.AreEqual(2, reader.Size); - Assert.AreEqual(2, reader.ParallelTaxonomyArrays.Parents().Length); + Assert.AreEqual(2, reader.ParallelTaxonomyArrays.Parents.Length); // merge all the segments so that NRT reader thinks there's a change iw.ForceMerge(1); @@ -378,7 +378,7 @@ public virtual void TestOpenIfChangedNoChangesButSegmentMerges() reader.Dispose(); reader = newtr; Assert.AreEqual(2, reader.Size); - Assert.AreEqual(2, reader.ParallelTaxonomyArrays.Parents().Length); + Assert.AreEqual(2, reader.ParallelTaxonomyArrays.Parents.Length); reader.Dispose(); writer.Dispose(); diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs index 8924f56147..778a889bc4 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs @@ -325,7 +325,7 @@ public virtual void TestConcurrency() Fail("mismatch number of categories"); } - int[] parents = dtr.ParallelTaxonomyArrays.Parents(); + int[] parents = dtr.ParallelTaxonomyArrays.Parents; foreach (string cat in values.Keys) { FacetLabel cp = new FacetLabel(FacetsConfig.StringToPath(cat)); diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs index 9290ec29c7..70080ec8ea 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs @@ -312,7 +312,7 @@ public virtual void TestRootOnly() var tr = new DirectoryTaxonomyReader(indexDir); Assert.AreEqual(1, tr.Size); Assert.AreEqual(0, tr.GetPath(0).Length); - Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tr.ParallelTaxonomyArrays.Parents()[0]); + Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tr.ParallelTaxonomyArrays.Parents[0]); Assert.AreEqual(0, tr.GetOrdinal(new FacetLabel())); tr.Dispose(true); indexDir.Dispose(); @@ -333,7 +333,7 @@ public virtual void TestRootOnly2() var tr = new DirectoryTaxonomyReader(indexDir); Assert.AreEqual(1, tr.Size); Assert.AreEqual(0, tr.GetPath(0).Length); - Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tr.ParallelTaxonomyArrays.Parents()[0]); + Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tr.ParallelTaxonomyArrays.Parents[0]); Assert.AreEqual(0, tr.GetOrdinal(new FacetLabel())); tw.Dispose(); tr.Dispose(true); @@ -420,7 +420,7 @@ public virtual void TestReaderParent() var tr = new DirectoryTaxonomyReader(indexDir); // check that the parent of the root ordinal is the invalid ordinal: - int[] parents = tr.ParallelTaxonomyArrays.Parents(); + int[] parents = tr.ParallelTaxonomyArrays.Parents; Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, parents[0]); // check parent of non-root ordinals: @@ -557,9 +557,9 @@ public virtual void TestChildrenArrays() tw.Dispose(); var tr = new DirectoryTaxonomyReader(indexDir); ParallelTaxonomyArrays ca = tr.ParallelTaxonomyArrays; - int[] youngestChildArray = ca.Children(); + int[] youngestChildArray = ca.Children; Assert.AreEqual(tr.Size, youngestChildArray.Length); - int[] olderSiblingArray = ca.Siblings(); + int[] olderSiblingArray = ca.Siblings; Assert.AreEqual(tr.Size, olderSiblingArray.Length); for (int i = 0; i < ExpectedCategories.Length; i++) { @@ -630,13 +630,13 @@ public virtual void TestChildrenArraysInvariants() tw.Dispose(); var tr = new DirectoryTaxonomyReader(indexDir); ParallelTaxonomyArrays ca = tr.ParallelTaxonomyArrays; - int[] children = ca.Children(); + int[] children = ca.Children; Assert.AreEqual(tr.Size, children.Length); - int[] olderSiblingArray = ca.Siblings(); + int[] olderSiblingArray = ca.Siblings; Assert.AreEqual(tr.Size, olderSiblingArray.Length); // test that the "youngest child" of every category is indeed a child: - int[] parents = tr.ParallelTaxonomyArrays.Parents(); + int[] parents = tr.ParallelTaxonomyArrays.Parents; for (int i = 0; i < tr.Size; i++) { int youngestChild = children[i]; @@ -726,10 +726,10 @@ public virtual void TestChildrenArraysGrowth() var tr = new DirectoryTaxonomyReader(indexDir); ParallelTaxonomyArrays ca = tr.ParallelTaxonomyArrays; Assert.AreEqual(3, tr.Size); - Assert.AreEqual(3, ca.Siblings().Length); - Assert.AreEqual(3, ca.Children().Length); - Assert.True(Arrays.Equals(new int[] { 1, 2, -1 }, ca.Children())); - Assert.True(Arrays.Equals(new int[] { -1, -1, -1 }, ca.Siblings())); + Assert.AreEqual(3, ca.Siblings.Length); + Assert.AreEqual(3, ca.Children.Length); + Assert.True(Arrays.Equals(new int[] { 1, 2, -1 }, ca.Children)); + Assert.True(Arrays.Equals(new int[] { -1, -1, -1 }, ca.Siblings)); tw.AddCategory(new FacetLabel("hi", "ho")); tw.AddCategory(new FacetLabel("hello")); tw.Commit(); @@ -737,8 +737,8 @@ public virtual void TestChildrenArraysGrowth() ParallelTaxonomyArrays newca = tr.ParallelTaxonomyArrays; Assert.AreSame(newca, ca); // we got exactly the same object Assert.AreEqual(3, tr.Size); - Assert.AreEqual(3, ca.Siblings().Length); - Assert.AreEqual(3, ca.Children().Length); + Assert.AreEqual(3, ca.Siblings.Length); + Assert.AreEqual(3, ca.Children.Length); // After the refresh, things change: var newtr = TaxonomyReader.OpenIfChanged(tr); Assert.NotNull(newtr); @@ -746,10 +746,10 @@ public virtual void TestChildrenArraysGrowth() tr = newtr; ca = tr.ParallelTaxonomyArrays; Assert.AreEqual(5, tr.Size); - Assert.AreEqual(5, ca.Siblings().Length); - Assert.AreEqual(5, ca.Children().Length); - Assert.True(Arrays.Equals(new int[] { 4, 3, -1, -1, -1 }, ca.Children())); - Assert.True(Arrays.Equals(new int[] { -1, -1, -1, 2, 1 }, ca.Siblings())); + Assert.AreEqual(5, ca.Siblings.Length); + Assert.AreEqual(5, ca.Children.Length); + Assert.True(Arrays.Equals(new int[] { 4, 3, -1, -1, -1 }, ca.Children)); + Assert.True(Arrays.Equals(new int[] { -1, -1, -1, 2, 1 }, ca.Siblings)); tw.Dispose(); tr.Dispose(); indexDir.Dispose(); @@ -771,7 +771,7 @@ public virtual void TestTaxonomyReaderRefreshRaces() ParallelTaxonomyArrays ca1 = trBase.ParallelTaxonomyArrays; int abOrd = trBase.GetOrdinal(abPath); - int abYoungChildBase1 = ca1.Children()[abOrd]; + int abYoungChildBase1 = ca1.Children[abOrd]; int numCategories = AtLeast(800); for (int i = 0; i < numCategories; i++) @@ -786,7 +786,7 @@ public virtual void TestTaxonomyReaderRefreshRaces() trBase = newTaxoReader; ParallelTaxonomyArrays ca2 = trBase.ParallelTaxonomyArrays; - int abYoungChildBase2 = ca2.Children()[abOrd]; + int abYoungChildBase2 = ca2.Children[abOrd]; int numRetries = AtLeast(50); for (int retry = 0; retry < numRetries; retry++) @@ -875,7 +875,7 @@ public override void Run() { while (!stop.Get()) { - int lastOrd = tr.ParallelTaxonomyArrays.Parents().Length - 1; + int lastOrd = tr.ParallelTaxonomyArrays.Parents.Length - 1; Assert.NotNull(tr.GetPath(lastOrd), "path of last-ord " + lastOrd + " is not found!"); AssertChildrenArrays(tr.ParallelTaxonomyArrays, retry, retrieval[0]++); Thread.Sleep(10);// don't starve refresh()'s CPU, which sleeps every 50 bytes for 1 ms @@ -890,8 +890,8 @@ public override void Run() private void AssertChildrenArrays(ParallelTaxonomyArrays ca, int retry, int retrieval) { - int abYoungChild = ca.Children()[abOrd]; - Assert.True(abYoungChildBase1 == abYoungChild || abYoungChildBase2 == ca.Children()[abOrd], "Retry " + retry + ": retrieval: " + retrieval + ": wrong youngest child for category " + abPath + " (ord=" + abOrd + ") - must be either " + abYoungChildBase1 + " or " + abYoungChildBase2 + " but was: " + abYoungChild); + int abYoungChild = ca.Children[abOrd]; + Assert.True(abYoungChildBase1 == abYoungChild || abYoungChildBase2 == ca.Children[abOrd], "Retry " + retry + ": retrieval: " + retrieval + ": wrong youngest child for category " + abPath + " (ord=" + abOrd + ") - must be either " + abYoungChildBase1 + " or " + abYoungChildBase2 + " but was: " + abYoungChild); } } @@ -949,7 +949,7 @@ public virtual void TestSeparateReaderAndWriter() int author = 1; try { - Assert.AreEqual(TaxonomyReader.ROOT_ORDINAL, tr.ParallelTaxonomyArrays.Parents()[author]); + Assert.AreEqual(TaxonomyReader.ROOT_ORDINAL, tr.ParallelTaxonomyArrays.Parents[author]); // ok } catch (System.IndexOutOfRangeException) @@ -969,7 +969,7 @@ public virtual void TestSeparateReaderAndWriter() Assert.NotNull(newTaxoReader); tr.Dispose(); tr = newTaxoReader; - int[] parents = tr.ParallelTaxonomyArrays.Parents(); + int[] parents = tr.ParallelTaxonomyArrays.Parents; Assert.AreEqual(author, parents[dawkins]); Assert.AreEqual(TaxonomyReader.ROOT_ORDINAL, parents[author]); Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, parents[TaxonomyReader.ROOT_ORDINAL]); From 56bf5021831600d3bb373d65c9c637495b07fd4d Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 15:34:14 +0700 Subject: [PATCH 25/41] Renamed Facet.Taxononmy.WriterCache.ITaxonomyWriterCache.Full back to its original name IsFull to indicate it is a boolean state. --- .../Taxonomy/Directory/DirectoryTaxonomyWriter.cs | 2 +- .../Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs | 2 +- .../Taxonomy/WriterCache/LruTaxonomyWriterCache.cs | 2 +- .../Taxonomy/WriterCache/TaxonomyWriterCache.cs | 2 +- .../Taxonomy/Directory/TestConcurrentFacetedIndexing.cs | 2 +- .../Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs index b07940ea48..9a7e4f9fba 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs @@ -796,7 +796,7 @@ private void PerhapsFillCache() termsEnum = terms.Iterator(termsEnum); while (termsEnum.Next() != null) { - if (!cache.Full) + if (!cache.IsFull) { BytesRef t = termsEnum.Term(); // Since we guarantee uniqueness of categories, each term has exactly diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs index 9a40f166df..ba9da3306b 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs @@ -67,7 +67,7 @@ public virtual void Close() } } - public virtual bool Full + public virtual bool IsFull { get { diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs index 8727893b86..ad76ccdc35 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs @@ -79,7 +79,7 @@ public LruTaxonomyWriterCache(int cacheSize, LRUType lruType) } } - public virtual bool Full + public virtual bool IsFull { get { diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs index bbe82ecdf1..1dc4d64bcd 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs @@ -90,7 +90,7 @@ public interface ITaxonomyWriterCache /// Returns true if the cache is full, such that the next will /// evict entries from it, false otherwise. /// - bool Full { get; } + bool IsFull { get; } /// /// Clears the content of the cache. Unlike , the caller can diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs index 52a4d618b3..49df6707d3 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs @@ -60,7 +60,7 @@ public virtual bool Put(FacetLabel categoryPath, int ordinal) { return true; } - public virtual bool Full + public virtual bool IsFull { get { diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs index 778a889bc4..5e4ec756f3 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs @@ -65,7 +65,7 @@ public virtual bool Put(FacetLabel categoryPath, int ordinal) { return true; } - public virtual bool Full + public virtual bool IsFull { get { From cb8d47f280b1b459c9b56401d447da0f70564338 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 15:40:35 +0700 Subject: [PATCH 26/41] Renamed Facet.Taxonomy.WriterCache.CompactLabelToOrdinal.MemoryUsage, Cl2oTaxonomyWriterCache.MemoryUsage and CollisionMap.MemoryUsage back to their original name (GetMemoryUsage()) because these are intensive operations. --- .../WriterCache/Cl2oTaxonomyWriterCache.cs | 7 +-- .../Taxonomy/WriterCache/CollisionMap.cs | 19 ++++---- .../WriterCache/CompactLabelToOrdinal.cs | 45 +++++++++---------- 3 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs index ba9da3306b..6cbff1f761 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs @@ -107,12 +107,9 @@ public virtual bool Put(FacetLabel categoryPath, int ordinal) /// /// Returns the number of bytes in memory used by this object. - public virtual int MemoryUsage + public virtual int GetMemoryUsage() { - get - { - return cache == null ? 0 : cache.MemoryUsage; - } + return cache == null ? 0 : cache.GetMemoryUsage(); } } } \ No newline at end of file diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs index fd47cd9cfc..1b2767b383 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs @@ -198,27 +198,24 @@ internal static int IndexFor(int h, int length) /// /// Returns an estimate of the memory usage of this CollisionMap. /// The approximate number of bytes used by this structure. - internal virtual int MemoryUsage + internal virtual int GetMemoryUsage() { - get + int memoryUsage = 0; + if (this.entries != null) { - int memoryUsage = 0; - if (this.entries != null) + foreach (Entry e in this.entries) { - foreach (Entry e in this.entries) + if (e != null) { - if (e != null) + memoryUsage += (4 * 4); + for (Entry ee = e.next; ee != null; ee = ee.next) { memoryUsage += (4 * 4); - for (Entry ee = e.next; ee != null; ee = ee.next) - { - memoryUsage += (4 * 4); - } } } } - return memoryUsage; } + return memoryUsage; } private class EntryIterator : IEnumerator diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs index 0ea11226b2..94a9e38f22 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs @@ -356,35 +356,32 @@ internal static int StringHashCode(CharBlockArray labelRepository, int offset) /// this package. Memory is consumed mainly by three structures: the hash arrays, /// label repository and collision map. /// - internal virtual int MemoryUsage + internal virtual int GetMemoryUsage() { - get + int memoryUsage = 0; + if (this.hashArrays != null) { - int memoryUsage = 0; - if (this.hashArrays != null) + // HashArray capacity is instance-specific. + foreach (HashArray ha in this.hashArrays) { - // HashArray capacity is instance-specific. - foreach (HashArray ha in this.hashArrays) - { - // Each has 2 capacity-length arrays of ints. - memoryUsage += (ha.capacity * 2 * 4) + 4; - } - } - if (this.labelRepository != null) - { - // All blocks are the same size. - int blockSize = this.labelRepository.blockSize; - // Each block has room for blockSize UTF-16 chars. - int actualBlockSize = (blockSize * 2) + 4; - memoryUsage += this.labelRepository.blocks.Count * actualBlockSize; - memoryUsage += 8; // Two int values for array as a whole. - } - if (this.collisionMap != null) - { - memoryUsage += this.collisionMap.MemoryUsage; + // Each has 2 capacity-length arrays of ints. + memoryUsage += (ha.capacity * 2 * 4) + 4; } - return memoryUsage; } + if (this.labelRepository != null) + { + // All blocks are the same size. + int blockSize = this.labelRepository.blockSize; + // Each block has room for blockSize UTF-16 chars. + int actualBlockSize = (blockSize * 2) + 4; + memoryUsage += this.labelRepository.blocks.Count * actualBlockSize; + memoryUsage += 8; // Two int values for array as a whole. + } + if (this.collisionMap != null) + { + memoryUsage += this.collisionMap.GetMemoryUsage(); + } + return memoryUsage; } /// From e0d070b5de0a9329fcd4cc41afbdda2a7d6216a6 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 15:46:15 +0700 Subject: [PATCH 27/41] Changed Size() and Capacity() methods of Facet.Taxonomy.WriterCache.CollisionMap to Count and Capacity properties. --- .../Taxonomy/WriterCache/CollisionMap.cs | 14 ++++++++++---- .../Taxonomy/WriterCache/CompactLabelToOrdinal.cs | 8 ++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs index 1b2767b383..b199513d8c 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs @@ -76,17 +76,23 @@ private CollisionMap(int initialCapacity, float loadFactor, CharBlockArray label /// /// How many mappings. - public virtual int Size() + public virtual int Count { - return this.size; + get + { + return this.size; + } } /// /// How many slots are allocated. /// - public virtual int Capacity() + public virtual int Capacity { - return this.capacity; + get + { + return this.capacity; + } } private void Grow() diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs index 94a9e38f22..2ba69a5cca 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs @@ -69,7 +69,7 @@ public class CompactLabelToOrdinal : LabelToOrdinal /// How many labels. public virtual int SizeOfMap() { - return this.collisionMap.Size(); + return this.collisionMap.Count; } private CompactLabelToOrdinal() @@ -117,7 +117,7 @@ private void Init() public override void AddLabel(FacetLabel label, int ordinal) { - if (collisionMap.Size() > threshold) + if (collisionMap.Count > threshold) { Grow(); } @@ -205,7 +205,7 @@ private void Grow() } CollisionMap oldCollisionMap = this.collisionMap; - this.collisionMap = new CollisionMap(oldCollisionMap.Capacity(), this.labelRepository); + this.collisionMap = new CollisionMap(oldCollisionMap.Capacity, this.labelRepository); this.threshold = (int)(this.capacity * this.loadFactor); var it = oldCollisionMap.GetEnumerator(); @@ -245,7 +245,7 @@ private void AddLabelOffset(int hash, int cid, int knownOffset) this.collisionMap.AddLabelOffset(hash, knownOffset, cid); - if (this.collisionMap.Size() > this.threshold) + if (this.collisionMap.Count > this.threshold) { Grow(); } From c083a05ec594c660e8e98698cc97210f510d1930 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 15:47:36 +0700 Subject: [PATCH 28/41] Changed Facet.Taxonomy.WriterCache.CompactLabelsToOrdinal.SizeOfMap to a property --- .../Taxonomy/WriterCache/CompactLabelToOrdinal.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs index 2ba69a5cca..35d3ee5bb8 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs @@ -67,9 +67,12 @@ public class CompactLabelToOrdinal : LabelToOrdinal /// /// How many labels. - public virtual int SizeOfMap() + public virtual int SizeOfMap { - return this.collisionMap.Count; + get + { + return this.collisionMap.Count; + } } private CompactLabelToOrdinal() From 03d05b34e29a988a7baa941c3eca01bfd988724e Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 15:50:46 +0700 Subject: [PATCH 29/41] Changed Facet.Taxonomy.WriterCache.LabelToOrdinal.NextOrdinal back to a method (GetNextOrdinal()) because it is not deterministic. --- .../Taxonomy/WriterCache/LabelToOrdinal.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LabelToOrdinal.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LabelToOrdinal.cs index 600ecbbe82..c9b36d6493 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LabelToOrdinal.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LabelToOrdinal.cs @@ -55,12 +55,9 @@ public virtual int MaxOrdinal /// Returns the next unassigned ordinal. The default behavior of this method /// is to simply increment a counter. /// - public virtual int NextOrdinal + public virtual int GetNextOrdinal() { - get - { - return this.counter++; - } + return this.counter++; } /// From fd13e8e5e8e6032cc4ec9b8e4bcb8ff320b7d01c Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 16:07:13 +0700 Subject: [PATCH 30/41] 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. --- src/Lucene.Net.Facet/FacetsCollector.cs | 21 +++-- .../RandomSamplingFacetsCollector.cs | 81 +++++++++---------- .../Range/DoubleRangeFacetCounts.cs | 2 +- .../Range/LongRangeFacetCounts.cs | 2 +- .../SortedSetDocValuesFacetCounts.cs | 2 +- .../Taxonomy/FastTaxonomyFacetCounts.cs | 2 +- .../Taxonomy/TaxonomyFacetCounts.cs | 2 +- .../TaxonomyFacetSumFloatAssociations.cs | 2 +- .../TaxonomyFacetSumIntAssociations.cs | 2 +- .../Taxonomy/TaxonomyFacetSumValueSource.cs | 2 +- .../WriterCache/TestCompactLabelToOrdinal.cs | 4 +- .../TestRandomSamplingFacetsCollector.cs | 4 +- 12 files changed, 59 insertions(+), 67 deletions(-) diff --git a/src/Lucene.Net.Facet/FacetsCollector.cs b/src/Lucene.Net.Facet/FacetsCollector.cs index d7be2f0823..0b225d0117 100644 --- a/src/Lucene.Net.Facet/FacetsCollector.cs +++ b/src/Lucene.Net.Facet/FacetsCollector.cs @@ -38,7 +38,7 @@ public class FacetsCollector : Collector private int totalHits; private float[] scores; private readonly bool keepScores; - private readonly IList matchingDocs = new List(); + private readonly List matchingDocs = new List(); private Docs docs; /// @@ -166,20 +166,17 @@ public bool KeepScores /// Returns the documents matched by the query, one per /// visited segment. /// - public virtual IList GetMatchingDocs + public virtual List 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() diff --git a/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs b/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs index 6c00c40bf4..491cf5e70d 100644 --- a/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs +++ b/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs @@ -1,25 +1,26 @@ using 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 @@ public virtual int NextInt(int n) private readonly XORShift64Random random; private double samplingRate; - private IList sampledDocs; + private List sampledDocs; private int totalHits = NOT_CALCULATED; private int leftoverBin = NOT_CALCULATED; private int leftoverIndex = NOT_CALCULATED; @@ -132,50 +133,44 @@ public RandomSamplingFacetsCollector(int sampleSize, long seed) /// MatchingDocs, scores is set to {@code null} /// /// - public override IList GetMatchingDocs + public override List GetMatchingDocs() { - get - { - IList matchingDocs = base.GetMatchingDocs; + List 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; } /// /// Returns the original matching documents. - public virtual IList OriginalMatchingDocs + public virtual List GetOriginalMatchingDocs() { - get - { - return base.GetMatchingDocs; - } + return base.GetMatchingDocs(); } /// /// Create a sampled copy of the matching documents list. - private IList CreateSampledDocs(IList matchingDocsList) + private List CreateSampledDocs(IEnumerable matchingDocsList) { - IList sampledDocsList = new List(matchingDocsList.Count); + List sampledDocsList = new List(matchingDocsList.Count()); foreach (MatchingDocs docs in matchingDocsList) { sampledDocsList.Add(CreateSample(docs)); diff --git a/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs b/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs index 52a3ad5cb7..7905086a37 100644 --- a/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs +++ b/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs @@ -79,7 +79,7 @@ public DoubleRangeFacetCounts(string field, ValueSource valueSource, FacetsColle 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) diff --git a/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs b/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs index d906cf82db..60451c4d38 100644 --- a/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs +++ b/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs @@ -72,7 +72,7 @@ public LongRangeFacetCounts(string field, ValueSource valueSource, 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) diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs index b32d430a83..c1a1da9f0c 100644 --- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs +++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs @@ -69,7 +69,7 @@ public SortedSetDocValuesFacetCounts(SortedSetDocValuesReaderState state, Facets 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) diff --git a/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs b/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs index e303394a65..3511af8461 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs @@ -51,7 +51,7 @@ public FastTaxonomyFacetCounts(TaxonomyReader taxoReader, FacetsConfig config, F public FastTaxonomyFacetCounts(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc) : base(indexFieldName, taxoReader, config) { - Count(fc.GetMatchingDocs); + Count(fc.GetMatchingDocs()); } private void Count(IList matchingDocs) diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs index 059822c724..b86c924c0b 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs @@ -45,7 +45,7 @@ public TaxonomyFacetCounts(OrdinalsReader ordinalsReader, TaxonomyReader taxoRea : base(ordinalsReader.IndexFieldName, taxoReader, config) { this.ordinalsReader = ordinalsReader; - Count(fc.GetMatchingDocs); + Count(fc.GetMatchingDocs()); } private void Count(IList matchingDocs) diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs index b943004d3e..e30cef21a7 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs @@ -50,7 +50,7 @@ public TaxonomyFacetSumFloatAssociations(TaxonomyReader taxoReader, FacetsConfig public TaxonomyFacetSumFloatAssociations(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc) : base(indexFieldName, taxoReader, config) { - SumValues(fc.GetMatchingDocs); + SumValues(fc.GetMatchingDocs()); } private void SumValues(IList matchingDocs) diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs index d053dfeb1f..7ff982b722 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs @@ -49,7 +49,7 @@ public TaxonomyFacetSumIntAssociations(TaxonomyReader taxoReader, FacetsConfig c public TaxonomyFacetSumIntAssociations(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc) : base(indexFieldName, taxoReader, config) { - SumValues(fc.GetMatchingDocs); + SumValues(fc.GetMatchingDocs()); } private void SumValues(IList matchingDocs) diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs index 2ae0f49d3e..99dbed1c12 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs @@ -66,7 +66,7 @@ public TaxonomyFacetSumValueSource(OrdinalsReader ordinalsReader, TaxonomyReader : 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 diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs index eafdd62726..82c0bdd15a 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 @@ public virtual void TestL2O() if (ord1 == LabelToOrdinal.INVALID_ORDINAL) { - ord1 = compact.NextOrdinal; + ord1 = compact.GetNextOrdinal(); map.AddLabel(label, ord1); compact.AddLabel(label, ord1); } @@ -224,7 +224,7 @@ public virtual void TestL2OBasic() if (ord1 == LabelToOrdinal.INVALID_ORDINAL) { - ord1 = compact.NextOrdinal; + ord1 = compact.GetNextOrdinal(); map.AddLabel(label, ord1); compact.AddLabel(label, ord1); } diff --git a/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs b/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs index 29694365d2..b98b28321e 100644 --- a/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs +++ b/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs @@ -75,10 +75,10 @@ public virtual void TestRandomSampling() 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); } From 66e393255818d5475014af3cc9e869e6079dbfc9 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 16:11:50 +0700 Subject: [PATCH 31/41] Renamed Facet.Taxonomy.TaxonomyReader.Size to Count (.NETified) --- .../Directory/DirectoryTaxonomyReader.cs | 2 +- .../Taxonomy/FloatTaxonomyFacets.cs | 4 +- .../Taxonomy/IntTaxonomyFacets.cs | 4 +- .../Taxonomy/PrintTaxonomyStats.cs | 2 +- .../Taxonomy/TaxonomyReader.cs | 3 +- .../Taxonomy/Directory/TestAddTaxonomy.cs | 8 +-- .../TestConcurrentFacetedIndexing.cs | 2 +- .../Directory/TestDirectoryTaxonomyReader.cs | 18 ++--- .../Directory/TestDirectoryTaxonomyWriter.cs | 2 +- .../Taxonomy/TestSearcherTaxonomyManager.cs | 4 +- .../Taxonomy/TestTaxonomyCombined.cs | 68 +++++++++---------- 11 files changed, 58 insertions(+), 59 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs index e540a00861..98bd09ee60 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs @@ -369,7 +369,7 @@ public override FacetLabel GetPath(int ordinal) return res; } - public override int Size + public override int Count { get { diff --git a/src/Lucene.Net.Facet/Taxonomy/FloatTaxonomyFacets.cs b/src/Lucene.Net.Facet/Taxonomy/FloatTaxonomyFacets.cs index f2e79a5900..27c8effd01 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FloatTaxonomyFacets.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FloatTaxonomyFacets.cs @@ -38,7 +38,7 @@ public abstract class FloatTaxonomyFacets : TaxonomyFacets protected internal FloatTaxonomyFacets(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config) : base(indexFieldName, taxoReader, config) { - values = new float[taxoReader.Size]; + values = new float[taxoReader.Count]; } /// @@ -112,7 +112,7 @@ public override FacetResult GetTopChildren(int topN, string dim, params string[] return null; } - TopOrdAndFloatQueue q = new TopOrdAndFloatQueue(Math.Min(taxoReader.Size, topN)); + TopOrdAndFloatQueue q = new TopOrdAndFloatQueue(Math.Min(taxoReader.Count, topN)); float bottomValue = 0; int ord = children[dimOrd]; diff --git a/src/Lucene.Net.Facet/Taxonomy/IntTaxonomyFacets.cs b/src/Lucene.Net.Facet/Taxonomy/IntTaxonomyFacets.cs index c9a789b054..2c4e533a61 100644 --- a/src/Lucene.Net.Facet/Taxonomy/IntTaxonomyFacets.cs +++ b/src/Lucene.Net.Facet/Taxonomy/IntTaxonomyFacets.cs @@ -38,7 +38,7 @@ public abstract class IntTaxonomyFacets : TaxonomyFacets protected internal IntTaxonomyFacets(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config) : base(indexFieldName, taxoReader, config) { - values = new int[taxoReader.Size]; + values = new int[taxoReader.Count]; } /// @@ -116,7 +116,7 @@ public override FacetResult GetTopChildren(int topN, string dim, params string[] return null; } - TopOrdAndIntQueue q = new TopOrdAndIntQueue(Math.Min(taxoReader.Size, topN)); + TopOrdAndIntQueue q = new TopOrdAndIntQueue(Math.Min(taxoReader.Count, topN)); int bottomValue = 0; diff --git a/src/Lucene.Net.Facet/Taxonomy/PrintTaxonomyStats.cs b/src/Lucene.Net.Facet/Taxonomy/PrintTaxonomyStats.cs index e4b723b4ec..601e5d83a5 100644 --- a/src/Lucene.Net.Facet/Taxonomy/PrintTaxonomyStats.cs +++ b/src/Lucene.Net.Facet/Taxonomy/PrintTaxonomyStats.cs @@ -70,7 +70,7 @@ public static void Main(string[] args) /// Recursively prints stats for all ordinals. public static void PrintStats(TaxonomyReader r, TextWriter @out, bool printTree) { - @out.WriteLine(r.Size + " total categories."); + @out.WriteLine(r.Count + " total categories."); ChildrenIterator it = r.GetChildren(TaxonomyReader.ROOT_ORDINAL); int child; diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs index e99b011965..db56dc222d 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs @@ -265,7 +265,6 @@ public int RefCount } } - // LUCENENET TODO: Rename to Count (.NETify) /// /// Returns the number of categories in the taxonomy. Note that the number of /// categories returned is often slightly higher than the number of categories @@ -273,7 +272,7 @@ public int RefCount /// taxonomy, its ancestors are also added automatically (including the root, /// which always get ordinal 0). /// - public abstract int Size { get; } + public abstract int Count { get; } /// /// Expert: increments the refCount of this TaxonomyReader instance. RefCounts diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs index 9482407cd9..0ed2bb4cf4 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs @@ -125,14 +125,14 @@ private void validate(Directory dest, Directory src, IOrdinalMap ordMap) var destTr = new DirectoryTaxonomyReader(dest); try { - int destSize = destTr.Size; + int destSize = destTr.Count; var srcTR = new DirectoryTaxonomyReader(src); try { var map = ordMap.Map; // validate taxo sizes - int srcSize = srcTR.Size; + int srcSize = srcTR.Count; Assert.True(destSize >= srcSize, "destination taxonomy expected to be larger than source; dest=" + destSize + " src=" + srcSize); // validate that all source categories exist in destination, and their @@ -275,9 +275,9 @@ public virtual void TestConcurrency() var dtr = new DirectoryTaxonomyReader(dest); // +2 to account for the root category + "a" - Assert.AreEqual(numCategories + 2, dtr.Size); + Assert.AreEqual(numCategories + 2, dtr.Count); var categories = new HashSet(); - for (int i = 1; i < dtr.Size; i++) + for (int i = 1; i < dtr.Count; i++) { FacetLabel cat = dtr.GetPath(i); Assert.True(categories.Add(cat), "category " + cat + " already existed"); diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs index 49df6707d3..abd82f8a8a 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs @@ -136,7 +136,7 @@ public virtual void TestConcurrency() var tr = new DirectoryTaxonomyReader(tw); // +1 for root category - if (values.Count + 1 != tr.Size) + if (values.Count + 1 != tr.Count) { foreach (string value in values.Keys) { diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs index 0e2935ac98..41ee66fdcf 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs @@ -53,7 +53,7 @@ public virtual void TestCloseAfterIncRef() ltr.Dispose(); // should not fail as we IncRef() before close - var tmpSie = ltr.Size; + var tmpSie = ltr.Count; ltr.DecRef(); dir.Dispose(); @@ -118,7 +118,7 @@ public virtual void TestAlreadyClosed() ltr.Dispose(); try { - var tmpSize = ltr.Size; + var tmpSize = ltr.Count; Fail("An AlreadyClosedException should have been thrown here"); } catch (AlreadyClosedException) @@ -166,7 +166,7 @@ private void doTestReadRecreatedTaxonomy(Random random, bool closeReader) tw.Dispose(); tr = new DirectoryTaxonomyReader(dir); - int baseNumCategories = tr.Size; + int baseNumCategories = tr.Count; for (int i = 0; i < n; i++) { @@ -189,7 +189,7 @@ private void doTestReadRecreatedTaxonomy(Random random, bool closeReader) tr.Dispose(true); tr = newtr; } - Assert.AreEqual(baseNumCategories + 1 + k, tr.Size, "Wrong #categories in taxonomy (i=" + i + ", k=" + k + ")"); + Assert.AreEqual(baseNumCategories + 1 + k, tr.Count, "Wrong #categories in taxonomy (i=" + i + ", k=" + k + ")"); } } finally @@ -251,7 +251,7 @@ public virtual void TestOpenIfChangedManySegments() reader = newtr; // assert categories - Assert.AreEqual(numCategories, reader.Size); + Assert.AreEqual(numCategories, reader.Count); int roundOrdinal = reader.GetOrdinal(new FacetLabel(Convert.ToString(i))); int[] parents = reader.ParallelTaxonomyArrays.Parents; Assert.AreEqual(0, parents[roundOrdinal]); // round's parent is root @@ -305,7 +305,7 @@ public virtual void TestOpenIfChangedMergedSegment() var writer = new DirectoryTaxonomyWriterAnonymousInnerClassHelper2(dir); var reader = new DirectoryTaxonomyReader(writer); - Assert.AreEqual(1, reader.Size); + Assert.AreEqual(1, reader.Count); Assert.AreEqual(1, reader.ParallelTaxonomyArrays.Parents.Length); // add category and call forceMerge -- this should flush IW and merge segments down to 1 @@ -318,7 +318,7 @@ public virtual void TestOpenIfChangedMergedSegment() Assert.NotNull(newtr); reader.Dispose(); reader = newtr; - Assert.AreEqual(2, reader.Size); + Assert.AreEqual(2, reader.Count); Assert.AreEqual(2, reader.ParallelTaxonomyArrays.Parents.Length); reader.Dispose(); @@ -366,7 +366,7 @@ public virtual void TestOpenIfChangedNoChangesButSegmentMerges() writer.AddCategory(new FacetLabel("a")); var reader = new DirectoryTaxonomyReader(writer); - Assert.AreEqual(2, reader.Size); + Assert.AreEqual(2, reader.Count); Assert.AreEqual(2, reader.ParallelTaxonomyArrays.Parents.Length); // merge all the segments so that NRT reader thinks there's a change @@ -377,7 +377,7 @@ public virtual void TestOpenIfChangedNoChangesButSegmentMerges() Assert.NotNull(newtr); reader.Dispose(); reader = newtr; - Assert.AreEqual(2, reader.Size); + Assert.AreEqual(2, reader.Count); Assert.AreEqual(2, reader.ParallelTaxonomyArrays.Parents.Length); reader.Dispose(); diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs index 5e4ec756f3..bd32d53311 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs @@ -312,7 +312,7 @@ public virtual void TestConcurrency() DirectoryTaxonomyReader dtr = new DirectoryTaxonomyReader(dir); // +1 for root category - if (values.Count + 1 != dtr.Size) + if (values.Count + 1 != dtr.Count) { foreach (string value in values.Keys) { diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs index 79f8b8074a..257ec1b46d 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs @@ -365,7 +365,7 @@ public virtual void TestReplaceTaxonomyDirectory() SearcherAndTaxonomy pair = mgr.Acquire(); try { - Assert.AreEqual(1, pair.TaxonomyReader.Size); + Assert.AreEqual(1, pair.TaxonomyReader.Count); } finally { @@ -382,7 +382,7 @@ public virtual void TestReplaceTaxonomyDirectory() pair = mgr.Acquire(); try { - Assert.AreEqual(3, pair.TaxonomyReader.Size); + Assert.AreEqual(3, pair.TaxonomyReader.Count); } finally { diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs index 70080ec8ea..45eeb3b283 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs @@ -310,7 +310,7 @@ public virtual void TestRootOnly() Assert.AreEqual(1, tw.Size); tw.Dispose(); var tr = new DirectoryTaxonomyReader(indexDir); - Assert.AreEqual(1, tr.Size); + Assert.AreEqual(1, tr.Count); Assert.AreEqual(0, tr.GetPath(0).Length); Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tr.ParallelTaxonomyArrays.Parents[0]); Assert.AreEqual(0, tr.GetOrdinal(new FacetLabel())); @@ -331,7 +331,7 @@ public virtual void TestRootOnly2() var tw = new DirectoryTaxonomyWriter(indexDir); tw.Commit(); var tr = new DirectoryTaxonomyReader(indexDir); - Assert.AreEqual(1, tr.Size); + Assert.AreEqual(1, tr.Count); Assert.AreEqual(0, tr.GetPath(0).Length); Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tr.ParallelTaxonomyArrays.Parents[0]); Assert.AreEqual(0, tr.GetOrdinal(new FacetLabel())); @@ -356,16 +356,16 @@ public virtual void TestReaderBasic() var tr = new DirectoryTaxonomyReader(indexDir); // test TaxonomyReader.getSize(): - Assert.AreEqual(ExpectedCategories.Length, tr.Size); + Assert.AreEqual(ExpectedCategories.Length, tr.Count); // test round trips of ordinal => category => ordinal - for (int i = 0; i < tr.Size; i++) + for (int i = 0; i < tr.Count; i++) { Assert.AreEqual(i, tr.GetOrdinal(tr.GetPath(i))); } // test TaxonomyReader.getCategory(): - for (int i = 1; i < tr.Size; i++) + for (int i = 1; i < tr.Count; i++) { FacetLabel expectedCategory = new FacetLabel(ExpectedCategories[i]); FacetLabel category = tr.GetPath(i); @@ -376,7 +376,7 @@ public virtual void TestReaderBasic() } // (also test invalid ordinals:) Assert.Null(tr.GetPath(-1)); - Assert.Null(tr.GetPath(tr.Size)); + Assert.Null(tr.GetPath(tr.Count)); Assert.Null(tr.GetPath(TaxonomyReader.INVALID_ORDINAL)); // test TaxonomyReader.GetOrdinal(): @@ -424,7 +424,7 @@ public virtual void TestReaderParent() Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, parents[0]); // check parent of non-root ordinals: - for (int ordinal = 1; ordinal < tr.Size; ordinal++) + for (int ordinal = 1; ordinal < tr.Count; ordinal++) { FacetLabel me = tr.GetPath(ordinal); int parentOrdinal = parents[ordinal]; @@ -496,7 +496,7 @@ private void CheckWriterParent(TaxonomyReader tr, ITaxonomyWriter tw) Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tw.GetParent(0)); // check parent of non-root ordinals: - for (int ordinal = 1; ordinal < tr.Size; ordinal++) + for (int ordinal = 1; ordinal < tr.Count; ordinal++) { FacetLabel me = tr.GetPath(ordinal); int parentOrdinal = tw.GetParent(ordinal); @@ -534,7 +534,7 @@ private void CheckWriterParent(TaxonomyReader tr, ITaxonomyWriter tw) } try { - int parent = tw.GetParent(tr.Size); + int parent = tw.GetParent(tr.Count); Fail("getParent for getSize() should throw exception, but returned " + parent); } catch (System.IndexOutOfRangeException) @@ -558,9 +558,9 @@ public virtual void TestChildrenArrays() var tr = new DirectoryTaxonomyReader(indexDir); ParallelTaxonomyArrays ca = tr.ParallelTaxonomyArrays; int[] youngestChildArray = ca.Children; - Assert.AreEqual(tr.Size, youngestChildArray.Length); + Assert.AreEqual(tr.Count, youngestChildArray.Length); int[] olderSiblingArray = ca.Siblings; - Assert.AreEqual(tr.Size, olderSiblingArray.Length); + Assert.AreEqual(tr.Count, olderSiblingArray.Length); for (int i = 0; i < ExpectedCategories.Length; i++) { // find expected children by looking at all expectedCategories @@ -631,13 +631,13 @@ public virtual void TestChildrenArraysInvariants() var tr = new DirectoryTaxonomyReader(indexDir); ParallelTaxonomyArrays ca = tr.ParallelTaxonomyArrays; int[] children = ca.Children; - Assert.AreEqual(tr.Size, children.Length); + Assert.AreEqual(tr.Count, children.Length); int[] olderSiblingArray = ca.Siblings; - Assert.AreEqual(tr.Size, olderSiblingArray.Length); + Assert.AreEqual(tr.Count, olderSiblingArray.Length); // test that the "youngest child" of every category is indeed a child: int[] parents = tr.ParallelTaxonomyArrays.Parents; - for (int i = 0; i < tr.Size; i++) + for (int i = 0; i < tr.Count; i++) { int youngestChild = children[i]; if (youngestChild != TaxonomyReader.INVALID_ORDINAL) @@ -648,14 +648,14 @@ public virtual void TestChildrenArraysInvariants() // test that the "older sibling" of every category is indeed older (lower) // (it can also be INVALID_ORDINAL, which is lower than any ordinal) - for (int i = 0; i < tr.Size; i++) + for (int i = 0; i < tr.Count; i++) { Assert.True(olderSiblingArray[i] < i, "olderSiblingArray[" + i + "] should be <" + i); } // test that the "older sibling" of every category is indeed a sibling // (they share the same parent) - for (int i = 0; i < tr.Size; i++) + for (int i = 0; i < tr.Count; i++) { int sibling = olderSiblingArray[i]; if (sibling == TaxonomyReader.INVALID_ORDINAL) @@ -670,11 +670,11 @@ public virtual void TestChildrenArraysInvariants() // test that the "youngest child" is indeed the youngest (so we don't // miss the first children in the chain) - for (int i = 0; i < tr.Size; i++) + for (int i = 0; i < tr.Count; i++) { // Find the really youngest child: int j; - for (j = tr.Size - 1; j > i; j--) + for (j = tr.Count - 1; j > i; j--) { if (parents[j] == i) { @@ -691,7 +691,7 @@ public virtual void TestChildrenArraysInvariants() // test that the "older sibling" is indeed the least oldest one - and // not a too old one or -1 (so we didn't miss some children in the // middle or the end of the chain). - for (int i = 0; i < tr.Size; i++) + for (int i = 0; i < tr.Count; i++) { // Find the youngest older sibling: int j; @@ -725,7 +725,7 @@ public virtual void TestChildrenArraysGrowth() tw.Commit(); var tr = new DirectoryTaxonomyReader(indexDir); ParallelTaxonomyArrays ca = tr.ParallelTaxonomyArrays; - Assert.AreEqual(3, tr.Size); + Assert.AreEqual(3, tr.Count); Assert.AreEqual(3, ca.Siblings.Length); Assert.AreEqual(3, ca.Children.Length); Assert.True(Arrays.Equals(new int[] { 1, 2, -1 }, ca.Children)); @@ -736,7 +736,7 @@ public virtual void TestChildrenArraysGrowth() // Before refresh, nothing changed.. ParallelTaxonomyArrays newca = tr.ParallelTaxonomyArrays; Assert.AreSame(newca, ca); // we got exactly the same object - Assert.AreEqual(3, tr.Size); + Assert.AreEqual(3, tr.Count); Assert.AreEqual(3, ca.Siblings.Length); Assert.AreEqual(3, ca.Children.Length); // After the refresh, things change: @@ -745,7 +745,7 @@ public virtual void TestChildrenArraysGrowth() tr.Dispose(); tr = newtr; ca = tr.ParallelTaxonomyArrays; - Assert.AreEqual(5, tr.Size); + Assert.AreEqual(5, tr.Count); Assert.AreEqual(5, ca.Siblings.Length); Assert.AreEqual(5, ca.Children.Length); Assert.True(Arrays.Equals(new int[] { 4, 3, -1, -1, -1 }, ca.Children)); @@ -934,13 +934,13 @@ public virtual void TestSeparateReaderAndWriter() tw.Commit(); var tr = new DirectoryTaxonomyReader(indexDir); - Assert.AreEqual(1, tr.Size); // the empty taxonomy has size 1 (the root) + Assert.AreEqual(1, tr.Count); // the empty taxonomy has size 1 (the root) tw.AddCategory(new FacetLabel("Author")); - Assert.AreEqual(1, tr.Size); // still root only... + Assert.AreEqual(1, tr.Count); // still root only... Assert.Null(TaxonomyReader.OpenIfChanged(tr)); // this is not enough, because tw.Commit() hasn't been done yet - Assert.AreEqual(1, tr.Size); // still root only... + Assert.AreEqual(1, tr.Count); // still root only... tw.Commit(); - Assert.AreEqual(1, tr.Size); // still root only... + Assert.AreEqual(1, tr.Count); // still root only... var newTaxoReader = TaxonomyReader.OpenIfChanged(tr); Assert.NotNull(newTaxoReader); tr.Dispose(); @@ -956,7 +956,7 @@ public virtual void TestSeparateReaderAndWriter() { Fail("After category addition, commit() and refresh(), getParent for " + author + " should NOT throw exception"); } - Assert.AreEqual(2, tr.Size); // finally, see there are two categories + Assert.AreEqual(2, tr.Count); // finally, see there are two categories // now, add another category, and verify that after commit and refresh // the parent of this category is correct (this requires the reader @@ -973,7 +973,7 @@ public virtual void TestSeparateReaderAndWriter() Assert.AreEqual(author, parents[dawkins]); Assert.AreEqual(TaxonomyReader.ROOT_ORDINAL, parents[author]); Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, parents[TaxonomyReader.ROOT_ORDINAL]); - Assert.AreEqual(3, tr.Size); + Assert.AreEqual(3, tr.Count); tw.Dispose(); tr.Dispose(); indexDir.Dispose(); @@ -990,25 +990,25 @@ public virtual void TestSeparateReaderAndWriter2() // Test getOrdinal(): FacetLabel author = new FacetLabel("Author"); - Assert.AreEqual(1, tr.Size); // the empty taxonomy has size 1 (the root) + Assert.AreEqual(1, tr.Count); // the empty taxonomy has size 1 (the root) Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tr.GetOrdinal(author)); tw.AddCategory(author); // before commit and refresh, no change: Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tr.GetOrdinal(author)); - Assert.AreEqual(1, tr.Size); // still root only... + Assert.AreEqual(1, tr.Count); // still root only... Assert.Null(TaxonomyReader.OpenIfChanged(tr)); // this is not enough, because tw.Commit() hasn't been done yet Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tr.GetOrdinal(author)); - Assert.AreEqual(1, tr.Size); // still root only... + Assert.AreEqual(1, tr.Count); // still root only... tw.Commit(); // still not enough before refresh: Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tr.GetOrdinal(author)); - Assert.AreEqual(1, tr.Size); // still root only... + Assert.AreEqual(1, tr.Count); // still root only... var newTaxoReader = TaxonomyReader.OpenIfChanged(tr); Assert.NotNull(newTaxoReader); tr.Dispose(); tr = newTaxoReader; Assert.AreEqual(1, tr.GetOrdinal(author)); - Assert.AreEqual(2, tr.Size); + Assert.AreEqual(2, tr.Count); tw.Dispose(); tr.Dispose(); indexDir.Dispose(); @@ -1166,7 +1166,7 @@ public virtual void TestNrt() writer.AddCategory(cp); var newReader = TaxonomyReader.OpenIfChanged(reader); Assert.NotNull(newReader, "expected a new instance"); - Assert.AreEqual(2, newReader.Size); + Assert.AreEqual(2, newReader.Count); Assert.AreNotSame(TaxonomyReader.INVALID_ORDINAL, newReader.GetOrdinal(cp)); reader.Dispose(); reader = newReader; From 4319c5d1281469a0f7f34cc3bfa91f3fdbc21197 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 16:18:05 +0700 Subject: [PATCH 32/41] Changed Facet.Taxonomy.LRUHashMap Size and MaxSize methods to Count and Capacity properties (.NETified) --- .../Directory/DirectoryTaxonomyReader.cs | 4 +-- src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs | 30 ++++++++++--------- .../Taxonomy/TestLRUHashMap.cs | 14 ++++----- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs index 98bd09ee60..0a60bff2a3 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs @@ -393,8 +393,8 @@ public virtual int CacheSize EnsureOpen(); // LUCENENET NOTE: No locking required here, // since our LRU implementation is thread-safe - categoryCache.MaxSize = value; - ordinalCache.MaxSize = value; + categoryCache.Capacity = value; + ordinalCache.Capacity = value; } } diff --git a/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs b/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs index 1f7883f908..059f834cb7 100644 --- a/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs +++ b/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs @@ -62,28 +62,28 @@ public class LRUHashMap where TValue : class //this is implementat // Record last access so we can tie break if 2 calls make it in within // the same millisecond. private long lastAccess; - private int maxSize; + private int capacity; - public LRUHashMap(int maxSize) + public LRUHashMap(int capacity) { - if (maxSize < 1) + if (capacity < 1) { - throw new ArgumentOutOfRangeException("maxSize must be at least 1"); + throw new ArgumentOutOfRangeException("capacity must be at least 1"); } - this.maxSize = maxSize; - this.cache = new Dictionary(maxSize); + this.capacity = capacity; + this.cache = new Dictionary(capacity); } - public virtual int MaxSize + public virtual int Capacity { - get { return maxSize; } + get { return capacity; } set { if (value < 1) { - throw new ArgumentOutOfRangeException("MaxSize must be at least 1"); + throw new ArgumentOutOfRangeException("Capacity must be at least 1"); } - maxSize = value; + capacity = value; } } @@ -105,7 +105,7 @@ public bool Put(TKey key, TValue value) timestamp = GetTimestamp() }; // We have added a new item, so we may need to remove the eldest - if (cache.Count > MaxSize) + if (cache.Count > Capacity) { // Remove the eldest item (lowest timestamp) from the cache cache.Remove(cache.OrderBy(x => x.Value.timestamp).First().Key); @@ -155,10 +155,12 @@ public bool ContainsKey(TKey key) return cache.ContainsKey(key); } - // LUCENENET TODO: Rename to Count (.NETify) - public int Size() + public int Count { - return cache.Count; + get + { + return cache.Count; + } } private long GetTimestamp() diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs index c08bca86c3..1f7afb1601 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs @@ -31,27 +31,27 @@ public class TestLRUHashMap : FacetTestCase public virtual void TestLru() { LRUHashMap lru = new LRUHashMap(3); - Assert.AreEqual(0, lru.Size()); + Assert.AreEqual(0, lru.Count); lru.Put("one", "Hello world"); - Assert.AreEqual(1, lru.Size()); + Assert.AreEqual(1, lru.Count); lru.Put("two", "Hi man"); - Assert.AreEqual(2, lru.Size()); + Assert.AreEqual(2, lru.Count); lru.Put("three", "Bonjour"); - Assert.AreEqual(3, lru.Size()); + Assert.AreEqual(3, lru.Count); lru.Put("four", "Shalom"); - Assert.AreEqual(3, lru.Size()); + Assert.AreEqual(3, lru.Count); Assert.NotNull(lru.Get("three")); Assert.NotNull(lru.Get("two")); Assert.NotNull(lru.Get("four")); Assert.Null(lru.Get("one")); lru.Put("five", "Yo!"); - Assert.AreEqual(3, lru.Size()); + Assert.AreEqual(3, lru.Count); Assert.Null(lru.Get("three")); // three was last used, so it got removed Assert.NotNull(lru.Get("five")); lru.Get("four"); lru.Put("six", "hi"); lru.Put("seven", "hey dude"); - Assert.AreEqual(3, lru.Size()); + Assert.AreEqual(3, lru.Count); Assert.Null(lru.Get("one")); Assert.Null(lru.Get("two")); Assert.Null(lru.Get("three")); From bcb5d136c22fcd5eb81c184598aab4f0915e2fbb Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 17:24:07 +0700 Subject: [PATCH 33/41] Renamed Facet.SortedSet.SortedSetDocValuesReaderState.Size to be Count (.NETified) --- .../SortedSet/DefaultSortedSetDocValuesReaderState.cs | 2 +- src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs | 2 +- src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesReaderState.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs b/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs index a5806c304e..9ecca3f1ad 100644 --- a/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs +++ b/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs @@ -143,7 +143,7 @@ public override IndexReader OrigReader /// /// Number of unique labels. - public override int Size + public override int Count { get { diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs index c1a1da9f0c..e552d830a3 100644 --- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs +++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs @@ -67,7 +67,7 @@ public SortedSetDocValuesFacetCounts(SortedSetDocValuesReaderState state, Facets this.state = state; this.field = state.Field; dv = state.DocValues; - counts = new int[state.Size]; + counts = new int[state.Count]; //System.out.println("field=" + field); Count(hits.GetMatchingDocs()); } diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesReaderState.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesReaderState.cs index f8952109c9..636d4345df 100644 --- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesReaderState.cs +++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesReaderState.cs @@ -93,6 +93,6 @@ protected internal SortedSetDocValuesReaderState() /// /// Number of unique labels. - public abstract int Size { get; } + public abstract int Count { get; } } } \ No newline at end of file From 64750067f5b462403d2069e8e7edd1ddcf5df992 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 17:27:09 +0700 Subject: [PATCH 34/41] Renamed Facet.Taxonomy.ITaxonomyWriter.Size to Count (.NETified) --- .../Directory/DirectoryTaxonomyWriter.cs | 2 +- .../Taxonomy/TaxonomyWriter.cs | 2 +- .../Directory/TestDirectoryTaxonomyWriter.cs | 2 +- .../Taxonomy/TestSearcherTaxonomyManager.cs | 4 +-- .../Taxonomy/TestTaxonomyCombined.cs | 30 +++++++++---------- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs index 9a7e4f9fba..dd497fd636 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs @@ -723,7 +723,7 @@ public virtual void PrepareCommit() } } - public virtual int Size + public virtual int Count { get { diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyWriter.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyWriter.cs index 6358dc1504..fdec22f2b9 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyWriter.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyWriter.cs @@ -102,7 +102,7 @@ public interface ITaxonomyWriter : IDisposable, TwoPhaseCommit /// are also added automatically (including the root, which always get /// ordinal 0). /// - int Size { get; } + int Count { get; } /// /// Sets the commit user data map. That method is considered a transaction and diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs index bd32d53311..4e6dd8566d 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs @@ -419,7 +419,7 @@ public virtual void TestReplaceTaxonomy() // LUCENE-4633: make sure that category "a" is not added again in any case taxoWriter.AddTaxonomy(input, new MemoryOrdinalMap()); - Assert.AreEqual(2, taxoWriter.Size, "no categories should have been added"); // root + 'a' + Assert.AreEqual(2, taxoWriter.Count, "no categories should have been added"); // root + 'a' Assert.AreEqual(ordA, taxoWriter.AddCategory(new FacetLabel("a")), "category 'a' received new ordinal?"); // add the same category again -- it should not receive the same ordinal ! diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs index 257ec1b46d..9e5e7b6bc8 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs @@ -114,10 +114,10 @@ public override void Run() if (VERBOSE) { - Console.WriteLine("TW size=" + tw.Size + " vs " + ordLimit); + Console.WriteLine("TW size=" + tw.Count + " vs " + ordLimit); } - if (tw.Size >= ordLimit) + if (tw.Count >= ordLimit) { break; } diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs index 45eeb3b283..e2058772ed 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs @@ -163,7 +163,7 @@ public virtual void TestWriter() FillTaxonomy(tw); // Also check ITaxonomyWriter.getSize() - see that the taxonomy's size // is what we expect it to be. - Assert.AreEqual(ExpectedCategories.Length, tw.Size); + Assert.AreEqual(ExpectedCategories.Length, tw.Count); tw.Dispose(); indexDir.Dispose(); } @@ -185,7 +185,7 @@ public virtual void TestWriterTwice() FillTaxonomy(tw); // Let's check the number of categories again, to see that no // extraneous categories were created: - Assert.AreEqual(ExpectedCategories.Length, tw.Size); + Assert.AreEqual(ExpectedCategories.Length, tw.Count); tw.Dispose(); indexDir.Dispose(); } @@ -210,7 +210,7 @@ public virtual void TestWriterTwice2() // ones, and that the number of categories hasn't grown by the new // additions FillTaxonomy(tw); - Assert.AreEqual(ExpectedCategories.Length, tw.Size); + Assert.AreEqual(ExpectedCategories.Length, tw.Count); tw.Dispose(); indexDir.Dispose(); } @@ -243,7 +243,7 @@ public virtual void TestWriterTwice3() // not be open (as explained above) but because it was not set to null, // we forgot that, tried to reopen it, and got an AlreadyClosedException. tw.Commit(); - Assert.AreEqual(ExpectedCategories.Length + 1, tw.Size); + Assert.AreEqual(ExpectedCategories.Length + 1, tw.Count); tw.Dispose(); indexDir.Dispose(); } @@ -259,37 +259,37 @@ public virtual void TestWriterSimpler() { var indexDir = NewDirectory(); var tw = new DirectoryTaxonomyWriter(indexDir); - Assert.AreEqual(1, tw.Size); // the root only + Assert.AreEqual(1, tw.Count); // the root only // Test that adding a new top-level category works Assert.AreEqual(1, tw.AddCategory(new FacetLabel("a"))); - Assert.AreEqual(2, tw.Size); + Assert.AreEqual(2, tw.Count); // Test that adding the same category again is noticed, and the // same ordinal (and not a new one) is returned. Assert.AreEqual(1, tw.AddCategory(new FacetLabel("a"))); - Assert.AreEqual(2, tw.Size); + Assert.AreEqual(2, tw.Count); // Test that adding another top-level category returns a new ordinal, // not the same one Assert.AreEqual(2, tw.AddCategory(new FacetLabel("b"))); - Assert.AreEqual(3, tw.Size); + Assert.AreEqual(3, tw.Count); // Test that adding a category inside one of the above adds just one // new ordinal: Assert.AreEqual(3, tw.AddCategory(new FacetLabel("a", "c"))); - Assert.AreEqual(4, tw.Size); + Assert.AreEqual(4, tw.Count); // Test that adding the same second-level category doesn't do anything: Assert.AreEqual(3, tw.AddCategory(new FacetLabel("a", "c"))); - Assert.AreEqual(4, tw.Size); + Assert.AreEqual(4, tw.Count); // Test that adding a second-level category with two new components // indeed adds two categories Assert.AreEqual(5, tw.AddCategory(new FacetLabel("d", "e"))); - Assert.AreEqual(6, tw.Size); + Assert.AreEqual(6, tw.Count); // Verify that the parents were added above in the order we expected Assert.AreEqual(4, tw.AddCategory(new FacetLabel("d"))); // Similar, but inside a category that already exists: Assert.AreEqual(7, tw.AddCategory(new FacetLabel("b", "d", "e"))); - Assert.AreEqual(8, tw.Size); + Assert.AreEqual(8, tw.Count); // And now inside two levels of categories that already exist: Assert.AreEqual(8, tw.AddCategory(new FacetLabel("b", "d", "f"))); - Assert.AreEqual(9, tw.Size); + Assert.AreEqual(9, tw.Count); tw.Dispose(); indexDir.Dispose(); @@ -307,7 +307,7 @@ public virtual void TestRootOnly() var tw = new DirectoryTaxonomyWriter(indexDir); // right after opening the index, it should already contain the // root, so have size 1: - Assert.AreEqual(1, tw.Size); + Assert.AreEqual(1, tw.Count); tw.Dispose(); var tr = new DirectoryTaxonomyReader(indexDir); Assert.AreEqual(1, tr.Count); @@ -1124,7 +1124,7 @@ public virtual void TestWriterCheckPaths() FillTaxonomyCheckPaths(tw); // Also check ITaxonomyWriter.getSize() - see that the taxonomy's size // is what we expect it to be. - Assert.AreEqual(ExpectedCategories.Length, tw.Size); + Assert.AreEqual(ExpectedCategories.Length, tw.Count); tw.Dispose(); indexDir.Dispose(); } From 007b217c72ae728b8a55ee76e3d747cf9dfc88ce Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 17:35:07 +0700 Subject: [PATCH 35/41] In Facet.Taxonomy.WriterCache.NameIntCacheLRU, renamed Size and MaxSize to Count and Capacity (.NETified) --- .../WriterCache/LruTaxonomyWriterCache.cs | 2 +- .../Taxonomy/WriterCache/NameIntCacheLRU.cs | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs index ad76ccdc35..7152094bb3 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs @@ -85,7 +85,7 @@ public virtual bool IsFull { lock (this) { - return cache.Size == cache.MaxSize; + return cache.Count == cache.Capacity; } } } diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs index e5c81e5b47..ca0011a7f0 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs @@ -33,27 +33,27 @@ public class NameIntCacheLRU private Dictionary cache; internal long nMisses = 0; // for debug internal long nHits = 0; // for debug - private int maxCacheSize; + private int capacity; - internal NameIntCacheLRU(int maxCacheSize) + internal NameIntCacheLRU(int capacity) { - this.maxCacheSize = maxCacheSize; - CreateCache(maxCacheSize); + this.capacity = capacity; + CreateCache(capacity); } /// /// Maximum number of cache entries before eviction. - public virtual int MaxSize + public virtual int Capacity { get { - return maxCacheSize; + return capacity; } } /// /// Number of entries currently in the cache. - public virtual int Size + public virtual int Count { get { @@ -63,6 +63,8 @@ public virtual int Size private void CreateCache(int maxSize) { + // LUCENENET TODO: Create an adapter so we can plug in either a generic + // dictionary or LRUHashMap or alternatively make LRUHashMap implement IDictionary //if (maxSize < int.MaxValue) //{ // cache = new LRUHashMap(1000,true); //for LRU @@ -120,7 +122,7 @@ private bool CacheFull { get { - return cache.Count > maxCacheSize; + return cache.Count > capacity; } } @@ -147,7 +149,7 @@ internal virtual bool MakeRoomLRU() { return false; } - int n = cache.Count - (2 * maxCacheSize) / 3; + int n = cache.Count - (2 * capacity) / 3; if (n <= 0) { return false; From 8cbc4927cff3c3fba36b944b854597045091df15 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 18:20:45 +0700 Subject: [PATCH 36/41] Fixed all Facet compiler warnings --- src/Lucene.Net.Facet/DrillSidewaysScorer.cs | 2 +- .../Taxonomy/Directory/DirectoryTaxonomyReader.cs | 2 +- src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs | 2 +- src/Lucene.Net.Tests.Facet/Range/TestRangeFacetCounts.cs | 2 +- src/Lucene.Net.Tests.Facet/SlowRAMDirectory.cs | 2 ++ src/Lucene.Net.Tests.Facet/TestDrillSideways.cs | 2 +- 6 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Lucene.Net.Facet/DrillSidewaysScorer.cs b/src/Lucene.Net.Facet/DrillSidewaysScorer.cs index 13d51e6882..18a0e06199 100644 --- a/src/Lucene.Net.Facet/DrillSidewaysScorer.cs +++ b/src/Lucene.Net.Facet/DrillSidewaysScorer.cs @@ -258,7 +258,7 @@ private void DoQueryFirstScoring(Collector collector, DocIdSetIterator[] disis, docID = baseScorer.NextDoc(); nextDocContinue:; } - nextDocBreak:; + //nextDocBreak:; // Not referenced } /// diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs index 0a60bff2a3..4552f08456 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs @@ -425,7 +425,7 @@ public virtual string ToString(int max) } sb.Append(i + ": " + category.ToString() + "\n"); } - catch (IOException e) + catch (IOException) { throw; } diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs index 99dbed1c12..ffe18dfdbd 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs @@ -200,7 +200,7 @@ public override double DoubleVal(int document) { return scorer.Score(); } - catch (Exception exception) + catch (Exception /*exception*/) { throw; } diff --git a/src/Lucene.Net.Tests.Facet/Range/TestRangeFacetCounts.cs b/src/Lucene.Net.Tests.Facet/Range/TestRangeFacetCounts.cs index d39cefd794..674e033072 100644 --- a/src/Lucene.Net.Tests.Facet/Range/TestRangeFacetCounts.cs +++ b/src/Lucene.Net.Tests.Facet/Range/TestRangeFacetCounts.cs @@ -1148,7 +1148,7 @@ private class DrillSidewaysAnonymousInnerClassHelper2 : DrillSideways private Filter fastMatchFilter; - public DrillSidewaysAnonymousInnerClassHelper2(TestRangeFacetCounts testRangeFacetCounts, IndexSearcher indexSearcher, FacetsConfig facetsConfig, TaxonomyReader org, ValueSource valueSource, DoubleRange[] doubleRanges, Filter filter) + public DrillSidewaysAnonymousInnerClassHelper2(TestRangeFacetCounts outerInstance, IndexSearcher indexSearcher, FacetsConfig facetsConfig, TaxonomyReader org, ValueSource valueSource, DoubleRange[] doubleRanges, Filter filter) : base(indexSearcher, facetsConfig, org) { this.outerInstance = outerInstance; diff --git a/src/Lucene.Net.Tests.Facet/SlowRAMDirectory.cs b/src/Lucene.Net.Tests.Facet/SlowRAMDirectory.cs index c444992605..5201f87ecd 100644 --- a/src/Lucene.Net.Tests.Facet/SlowRAMDirectory.cs +++ b/src/Lucene.Net.Tests.Facet/SlowRAMDirectory.cs @@ -241,6 +241,8 @@ public override long FilePointer return io.FilePointer; } } + + [Obsolete] public override void Seek(long pos) { io.Seek(pos); diff --git a/src/Lucene.Net.Tests.Facet/TestDrillSideways.cs b/src/Lucene.Net.Tests.Facet/TestDrillSideways.cs index e32693d2fc..8060f4957b 100644 --- a/src/Lucene.Net.Tests.Facet/TestDrillSideways.cs +++ b/src/Lucene.Net.Tests.Facet/TestDrillSideways.cs @@ -1137,7 +1137,7 @@ private TestFacetResult slowDrillSidewaysSearch(IndexSearcher s, IList docs } nextDocContinue: ; } - nextDocBreak: + //nextDocBreak:// Not referenced IDictionary idToDocID = new Dictionary(); for (int i = 0; i < s.IndexReader.MaxDoc; i++) From 44958102853fca1051996bfe6cd42b7b1c194c56 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 23:32:33 +0700 Subject: [PATCH 37/41] Facet: Updated documentation --- src/Lucene.Net.Facet/DrillDownQuery.cs | 50 +++--- src/Lucene.Net.Facet/DrillSideways.cs | 69 ++++---- src/Lucene.Net.Facet/DrillSidewaysQuery.cs | 3 +- src/Lucene.Net.Facet/DrillSidewaysScorer.cs | 10 +- src/Lucene.Net.Facet/FacetField.cs | 16 +- src/Lucene.Net.Facet/FacetResult.cs | 19 ++- src/Lucene.Net.Facet/Facets.cs | 19 +-- src/Lucene.Net.Facet/FacetsCollector.cs | 60 +++---- src/Lucene.Net.Facet/FacetsConfig.cs | 91 ++++++----- src/Lucene.Net.Facet/LabelAndValue.cs | 10 +- src/Lucene.Net.Facet/Lucene.Net.Facet.csproj | 4 + src/Lucene.Net.Facet/MultiFacets.cs | 8 +- .../RandomSamplingFacetsCollector.cs | 47 +++--- .../Range/DoubleRangeFacetCounts.cs | 36 ++--- .../Range/LongRangeCounter.cs | 17 +- .../Range/LongRangeFacetCounts.cs | 32 ++-- src/Lucene.Net.Facet/Range/Range.cs | 41 ++--- .../Range/RangeFacetCounts.cs | 8 +- .../DefaultSortedSetDocValuesReaderState.cs | 21 ++- .../SortedSetDocValuesFacetCounts.cs | 24 +-- .../SortedSet/SortedSetDocValuesFacetField.cs | 6 +- .../SortedSetDocValuesReaderState.cs | 36 ++--- .../Taxonomy/AssociationFacetField.cs | 29 ++-- .../Taxonomy/CachedOrdinalsReader.cs | 21 +-- src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs | 37 +++-- .../Directory/DirectoryTaxonomyReader.cs | 51 +++--- .../Directory/DirectoryTaxonomyWriter.cs | 148 +++++++++--------- .../Taxonomy/Directory/TaxonomyIndexArrays.cs | 25 +-- .../Taxonomy/DocValuesOrdinalsReader.cs | 13 +- src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs | 37 +++-- .../Taxonomy/FastTaxonomyFacetCounts.cs | 16 +- .../Taxonomy/FloatAssociationFacetField.cs | 17 +- .../Taxonomy/FloatTaxonomyFacets.cs | 8 +- .../Taxonomy/IntAssociationFacetField.cs | 18 +-- .../Taxonomy/IntTaxonomyFacets.cs | 8 +- src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs | 41 +++-- .../Taxonomy/OrdinalsReader.cs | 12 +- .../Taxonomy/ParallelTaxonomyArrays.cs | 35 +++-- .../Taxonomy/PrintTaxonomyStats.cs | 10 +- .../Taxonomy/SearcherTaxonomyManager.cs | 29 ++-- .../Taxonomy/TaxonomyFacetCounts.cs | 12 +- .../TaxonomyFacetSumFloatAssociations.cs | 12 +- .../TaxonomyFacetSumIntAssociations.cs | 12 +- .../Taxonomy/TaxonomyFacetSumValueSource.cs | 24 +-- .../Taxonomy/TaxonomyFacets.cs | 22 +-- .../Taxonomy/TaxonomyReader.cs | 88 ++++++----- .../Taxonomy/TaxonomyWriter.cs | 58 ++++--- .../Taxonomy/WriterCache/CategoryPathUtils.cs | 12 +- .../Taxonomy/WriterCache/CharBlockArray.cs | 2 +- .../WriterCache/Cl2oTaxonomyWriterCache.cs | 10 +- .../Taxonomy/WriterCache/CollisionMap.cs | 10 +- .../WriterCache/CompactLabelToOrdinal.cs | 27 ++-- .../Taxonomy/WriterCache/LabelToOrdinal.cs | 11 +- .../WriterCache/LruTaxonomyWriterCache.cs | 8 +- .../Taxonomy/WriterCache/NameIntCacheLRU.cs | 17 +- .../WriterCache/TaxonomyWriterCache.cs | 38 +++-- src/Lucene.Net.Facet/TopOrdAndFloatQueue.cs | 11 +- src/Lucene.Net.Facet/TopOrdAndIntQueue.cs | 11 +- 58 files changed, 844 insertions(+), 723 deletions(-) diff --git a/src/Lucene.Net.Facet/DrillDownQuery.cs b/src/Lucene.Net.Facet/DrillDownQuery.cs index d6fa03b322..67c36f2242 100644 --- a/src/Lucene.Net.Facet/DrillDownQuery.cs +++ b/src/Lucene.Net.Facet/DrillDownQuery.cs @@ -36,13 +36,13 @@ namespace Lucene.Net.Facet using TermQuery = Lucene.Net.Search.TermQuery; /// - /// A for drill-down over facet categories. You - /// should call for every group of categories you + /// A for drill-down over facet categories. You + /// should call for every group of categories you /// want to drill-down over. /// - /// NOTE: if you choose to create your own by calling - /// , it is recommended to wrap it with - /// and set the to {@code 0.0f}, + /// NOTE: if you choose to create your own by calling + /// , it is recommended to wrap it with + /// and set the boost to 0.0f, /// so that it does not affect the scores of the documents. /// /// @lucene.experimental @@ -51,7 +51,8 @@ namespace Lucene.Net.Facet public sealed class DrillDownQuery : Query { /// - /// Creates a drill-down term. + /// Creates a drill-down term. + /// public static Term Term(string field, string dim, params string[] path) { return new Term(field, FacetsConfig.PathToString(dim, path)); @@ -62,7 +63,8 @@ public static Term Term(string field, string dim, params string[] path) private readonly IDictionary drillDownDims = new Dictionary(); /// - /// Used by clone() + /// Used by + /// internal DrillDownQuery(FacetsConfig config, BooleanQuery query, IDictionary drillDownDims) { this.query = (BooleanQuery)query.Clone(); @@ -71,7 +73,8 @@ internal DrillDownQuery(FacetsConfig config, BooleanQuery query, IDictionary - /// Used by DrillSideways + /// Used by + /// internal DrillDownQuery(FacetsConfig config, Filter filter, DrillDownQuery other) { query = new BooleanQuery(true); // disable coord @@ -92,7 +95,8 @@ internal DrillDownQuery(FacetsConfig config, Filter filter, DrillDownQuery other } /// - /// Used by DrillSideways + /// Used by + /// internal DrillDownQuery(FacetsConfig config, Query baseQuery, IList clauses, IDictionary drillDownDims) { query = new BooleanQuery(true); @@ -109,9 +113,9 @@ internal DrillDownQuery(FacetsConfig config, Query baseQuery, IList claus } /// - /// Creates a new {@code DrillDownQuery} without a base query, - /// to perform a pure browsing query (equivalent to using - /// as base). + /// Creates a new without a base query, + /// to perform a pure browsing query (equivalent to using + /// as base). /// public DrillDownQuery(FacetsConfig config) : this(config, null) @@ -119,10 +123,10 @@ public DrillDownQuery(FacetsConfig config) } /// - /// Creates a new {@code DrillDownQuery} over the given base query. Can be - /// {@code null}, in which case the result from - /// will be a pure browsing query, filtering on - /// the added categories only. + /// Creates a new over the given base query. Can be + /// null, in which case the result from + /// will be a pure browsing query, filtering on + /// the added categories only. /// public DrillDownQuery(FacetsConfig config, Query baseQuery) { @@ -136,7 +140,7 @@ public DrillDownQuery(FacetsConfig config, Query baseQuery) /// /// Merges (ORs) a new path into an existing AND'd - /// clause. + /// clause. /// private void Merge(string dim, string[] path) { @@ -166,9 +170,9 @@ private void Merge(string dim, string[] path) /// /// Adds one dimension of drill downs; if you pass the same - /// dimension more than once it is OR'd with the previous - /// cofnstraints on that dimension, and all dimensions are - /// AND'd against each other and the base query. + /// dimension more than once it is OR'd with the previous + /// cofnstraints on that dimension, and all dimensions are + /// AND'd against each other and the base query. /// public void Add(string dim, params string[] path) { @@ -188,8 +192,8 @@ public void Add(string dim, params string[] path) /// /// Expert: add a custom drill-down subQuery. Use this - /// when you have a separate way to drill-down on the - /// dimension than the indexed facet ordinals. + /// when you have a separate way to drill-down on the + /// dimension than the indexed facet ordinals. /// public void Add(string dim, Query subQuery) { @@ -212,7 +216,7 @@ public void Add(string dim, Query subQuery) /// /// Expert: add a custom drill-down Filter, e.g. when - /// drilling down after range faceting. + /// drilling down after range faceting. /// public void Add(string dim, Filter subFilter) { diff --git a/src/Lucene.Net.Facet/DrillSideways.cs b/src/Lucene.Net.Facet/DrillSideways.cs index 457bed3ab1..408117b3ff 100644 --- a/src/Lucene.Net.Facet/DrillSideways.cs +++ b/src/Lucene.Net.Facet/DrillSideways.cs @@ -27,18 +27,18 @@ namespace Lucene.Net.Facet /// /// Computes drill down and sideways counts for the provided - /// . Drill sideways counts include + /// . Drill sideways counts include /// alternative values/aggregates for the drill-down /// dimensions so that a dimension does not disappear after /// the user drills down into it. /// /// Use one of the static search /// methods to do the search, and then get the hits and facet - /// results from the returned . + /// results from the returned . /// /// - /// NOTE: this allocates one {@link - /// FacetsCollector} for each drill-down, plus one. If your + /// NOTE: this allocates one + /// for each drill-down, plus one. If your /// index has high number of facet labels then this will /// multiply your memory usage. /// @@ -48,33 +48,37 @@ namespace Lucene.Net.Facet public class DrillSideways { /// - /// passed to constructor. + /// passed to constructor. + /// protected internal readonly IndexSearcher searcher; /// - /// passed to constructor. + /// passed to constructor. + /// protected internal readonly TaxonomyReader taxoReader; /// - /// passed to - /// constructor; can be null. + /// passed to + /// constructor; can be null. /// protected internal readonly SortedSetDocValuesReaderState state; /// - /// passed to constructor. + /// passed to constructor. + /// protected internal readonly FacetsConfig config; /// - /// Create a new {@code DrillSideways} instance. + /// Create a new instance. + /// public DrillSideways(IndexSearcher searcher, FacetsConfig config, TaxonomyReader taxoReader) : this(searcher, config, taxoReader, null) { } /// - /// Create a new {@code DrillSideways} instance, assuming the categories were - /// indexed with . + /// Create a new instance, assuming the categories were + /// indexed with . /// public DrillSideways(IndexSearcher searcher, FacetsConfig config, SortedSetDocValuesReaderState state) : this(searcher, config, null, state) @@ -82,10 +86,9 @@ public DrillSideways(IndexSearcher searcher, FacetsConfig config, SortedSetDocVa } /// - /// Create a new {@code DrillSideways} instance, where some - /// dimensions were indexed with {@link - /// SortedSetDocValuesFacetField} and others were indexed - /// with . + /// Create a new instance, where some + /// dimensions were indexed with + /// and others were indexed with . /// public DrillSideways(IndexSearcher searcher, FacetsConfig config, TaxonomyReader taxoReader, SortedSetDocValuesReaderState state) { @@ -97,7 +100,7 @@ public DrillSideways(IndexSearcher searcher, FacetsConfig config, TaxonomyReader /// /// Subclass can override to customize per-dim Facets - /// impl. + /// impl. /// protected virtual Facets BuildFacetsResult(FacetsCollector drillDowns, FacetsCollector[] drillSideways, string[] drillSidewaysDims) { @@ -139,7 +142,7 @@ protected virtual Facets BuildFacetsResult(FacetsCollector drillDowns, FacetsCol } /// - /// Search, collecting hits with a , and + /// Search, collecting hits with a , and /// computing drill down and sideways counts. /// public virtual DrillSidewaysResult Search(DrillDownQuery query, Collector hitCollector) @@ -194,7 +197,7 @@ public virtual DrillSidewaysResult Search(DrillDownQuery query, Collector hitCol } /// - /// Search, sorting by , and computing + /// Search, sorting by , and computing /// drill down and sideways counts. /// public virtual DrillSidewaysResult Search(DrillDownQuery query, Filter filter, FieldDoc after, int topN, Sort sort, bool doDocScores, bool doMaxScore) @@ -249,15 +252,14 @@ public virtual DrillSidewaysResult Search(ScoreDoc after, DrillDownQuery query, /// /// Override this and return true if your collector - /// (e.g., {@code ToParentBlockJoinCollector}) expects all - /// sub-scorers to be positioned on the document being - /// collected. This will cause some performance loss; - /// default is false. Note that if you return true from - /// this method (in a subclass) be sure your collector - /// also returns false from {@link - /// Collector#acceptsDocsOutOfOrder}: this will trick - /// {@code BooleanQuery} into also scoring all subDocs at - /// once. + /// (e.g., ) expects all + /// sub-scorers to be positioned on the document being + /// collected. This will cause some performance loss; + /// default is false. Note that if you return true from + /// this method (in a subclass) be sure your collector + /// also returns false from : + /// this will trick into also scoring all subDocs at + /// once. /// protected virtual bool ScoreSubDocsAtOnce() { @@ -266,20 +268,23 @@ protected virtual bool ScoreSubDocsAtOnce() /// /// Result of a drill sideways search, including the - /// and . + /// and . /// public class DrillSidewaysResult { /// - /// Combined drill down & sideways results. + /// Combined drill down & sideways results. + /// public Facets Facets { get; private set; } /// - /// Hits. + /// Hits. + /// public TopDocs Hits { get; private set; } /// - /// Sole constructor. + /// Sole constructor. + /// public DrillSidewaysResult(Facets facets, TopDocs hits) { this.Facets = facets; diff --git a/src/Lucene.Net.Facet/DrillSidewaysQuery.cs b/src/Lucene.Net.Facet/DrillSidewaysQuery.cs index 9b25dac8d8..38fac9694c 100644 --- a/src/Lucene.Net.Facet/DrillSidewaysQuery.cs +++ b/src/Lucene.Net.Facet/DrillSidewaysQuery.cs @@ -36,9 +36,8 @@ namespace Lucene.Net.Facet /// /// Only purpose is to punch through and return a - /// DrillSidewaysScorer + /// /// - internal class DrillSidewaysQuery : Query { internal readonly Query baseQuery; diff --git a/src/Lucene.Net.Facet/DrillSidewaysScorer.cs b/src/Lucene.Net.Facet/DrillSidewaysScorer.cs index 18a0e06199..0dcc2850be 100644 --- a/src/Lucene.Net.Facet/DrillSidewaysScorer.cs +++ b/src/Lucene.Net.Facet/DrillSidewaysScorer.cs @@ -169,10 +169,10 @@ public override bool Score(Collector collector, int maxDoc) /// /// Used when base query is highly constraining vs the - /// drilldowns, or when the docs must be scored at once - /// (i.e., like BooleanScorer2, not BooleanScorer). In - /// this case we just .next() on base and .advance() on - /// the dim filters. + /// drilldowns, or when the docs must be scored at once + /// (i.e., like , not ). In + /// this case we just .Next() on base and .Advance() on + /// the dim filters. /// private void DoQueryFirstScoring(Collector collector, DocIdSetIterator[] disis, Collector[] sidewaysCollectors, Bits[] bits, Collector[] bitsSidewaysCollectors) @@ -263,7 +263,7 @@ private void DoQueryFirstScoring(Collector collector, DocIdSetIterator[] disis, /// /// Used when drill downs are highly constraining vs - /// baseQuery. + /// baseQuery. /// private void DoDrillDownAdvanceScoring(Collector collector, DocIdSetIterator[] disis, Collector[] sidewaysCollectors) { diff --git a/src/Lucene.Net.Facet/FacetField.cs b/src/Lucene.Net.Facet/FacetField.cs index 794ec319a6..9934afbc01 100644 --- a/src/Lucene.Net.Facet/FacetField.cs +++ b/src/Lucene.Net.Facet/FacetField.cs @@ -24,11 +24,11 @@ namespace Lucene.Net.Facet using FieldType = Lucene.Net.Documents.FieldType; /// - /// Add an instance of this to your for every facet label. + /// Add an instance of this to your for every facet label. /// /// - /// NOTE: you must call before - /// you add the document to IndexWriter. + /// NOTE: you must call before + /// you add the document to . /// /// public class FacetField : Field @@ -41,16 +41,18 @@ static FacetField() } /// - /// Dimension for this field. + /// Dimension for this field. + /// public string Dim { get; private set; } /// - /// Path for this field. + /// Path for this field. + /// public string[] Path { get; private set; } /// - /// Creates the this from {@code dim} and - /// {@code path}. + /// Creates the this from and + /// . /// public FacetField(string dim, params string[] path) : base("dummy", TYPE) diff --git a/src/Lucene.Net.Facet/FacetResult.cs b/src/Lucene.Net.Facet/FacetResult.cs index 7dc73b918e..26040e8abf 100644 --- a/src/Lucene.Net.Facet/FacetResult.cs +++ b/src/Lucene.Net.Facet/FacetResult.cs @@ -23,30 +23,35 @@ namespace Lucene.Net.Facet */ /// - /// Counts or aggregates for a single dimension. + /// Counts or aggregates for a single dimension. + /// public sealed class FacetResult { /// - /// Dimension that was requested. + /// Dimension that was requested. + /// public string Dim { get; private set; } /// - /// Path whose children were requested. + /// Path whose children were requested. + /// public string[] Path { get; private set; } /// /// Total value for this path (sum of all child counts, or - /// sum of all child values), even those not included in - /// the topN. + /// sum of all child values), even those not included in + /// the topN. /// public float Value { get; private set; } /// - /// How many child labels were encountered. + /// How many child labels were encountered. + /// public int ChildCount { get; private set; } /// - /// Child counts. + /// Child counts. + /// public LabelAndValue[] LabelValues { get; private set; } /// diff --git a/src/Lucene.Net.Facet/Facets.cs b/src/Lucene.Net.Facet/Facets.cs index ce17c15644..669124fc65 100644 --- a/src/Lucene.Net.Facet/Facets.cs +++ b/src/Lucene.Net.Facet/Facets.cs @@ -27,31 +27,32 @@ namespace Lucene.Net.Facet public abstract class Facets { /// - /// Default constructor. + /// Default constructor. + /// public Facets() { } /// /// Returns the topN child labels under the specified - /// path. Returns null if the specified path doesn't - /// exist or if this dimension was never seen. + /// path. Returns null if the specified path doesn't + /// exist or if this dimension was never seen. /// public abstract FacetResult GetTopChildren(int topN, string dim, params string[] path); /// /// Return the count or value - /// for a specific path. Returns -1 if - /// this path doesn't exist, else the count. + /// for a specific path. Returns -1 if + /// this path doesn't exist, else the count. /// public abstract float GetSpecificValue(string dim, params string[] path); /// /// Returns topN labels for any dimension that had hits, - /// sorted by the number of hits that dimension matched; - /// this is used for "sparse" faceting, where many - /// different dimensions were indexed, for example - /// depending on the type of document. + /// sorted by the number of hits that dimension matched; + /// this is used for "sparse" faceting, where many + /// different dimensions were indexed, for example + /// depending on the type of document. /// public abstract List GetAllDims(int topN); } diff --git a/src/Lucene.Net.Facet/FacetsCollector.cs b/src/Lucene.Net.Facet/FacetsCollector.cs index 0b225d0117..c494a7bc71 100644 --- a/src/Lucene.Net.Facet/FacetsCollector.cs +++ b/src/Lucene.Net.Facet/FacetsCollector.cs @@ -25,11 +25,11 @@ namespace Lucene.Net.Facet /// /// Collects hits for subsequent faceting. Once you've run - /// a search and collect hits into this, instantiate one of - /// the subclasses to do the facet - /// counting. Use the {@code search} utility methods to - /// perform an "ordinary" search but also collect into a - /// . + /// a search and collect hits into this, instantiate one of + /// the subclasses to do the facet + /// counting. Use the utility methods to + /// perform an "ordinary" search but also collect into a + /// . /// public class FacetsCollector : Collector { @@ -43,29 +43,32 @@ public class FacetsCollector : Collector /// /// Used during collection to record matching docs and then return a - /// that contains them. + /// that contains them. /// protected internal abstract class Docs { /// - /// Solr constructor. + /// Sole constructor. + /// public Docs() { } /// - /// Record the given document. + /// Record the given document. + /// public abstract void AddDoc(int docId); /// - /// Return the which contains all the recorded docs. + /// Return the which contains all the recorded docs. + /// public abstract DocIdSet DocIdSet { get; } } /// - /// Holds the documents that were matched in the . - /// If scores were required, then {@code scores} is not null. + /// Holds the documents that were matched in the . + /// If scores were required, then is not null. /// public sealed class MatchingDocs { @@ -87,7 +90,8 @@ public sealed class MatchingDocs public int TotalHits { get; private set; } /// - /// Sole constructor. + /// Sole constructor. + /// public MatchingDocs(AtomicReaderContext context, DocIdSet bits, int totalHits, float[] scores) { this.Context = context; @@ -98,15 +102,16 @@ public MatchingDocs(AtomicReaderContext context, DocIdSet bits, int totalHits, f } /// - /// Default constructor + /// Default constructor + /// public FacetsCollector() : this(false) { } /// - /// Create this; if {@code keepScores} is true then a - /// float[] is allocated to hold score of all hits. + /// Create this; if is true then a + /// is allocated to hold score of all hits. /// public FacetsCollector(bool keepScores) { @@ -114,9 +119,9 @@ public FacetsCollector(bool keepScores) } /// - /// Creates a to record hits. The default uses + /// Creates a to record hits. The default uses /// to record hits and you can override to e.g. record the docs in your own - /// . + /// . /// protected virtual Docs CreateDocs(int maxDoc) { @@ -153,7 +158,8 @@ public override DocIdSet DocIdSet } /// - /// True if scores were saved. + /// True if scores were saved. + /// public bool KeepScores { get @@ -163,7 +169,7 @@ public bool KeepScores } /// - /// Returns the documents matched by the query, one per + /// Returns the documents matched by the query, one per /// visited segment. /// public virtual List GetMatchingDocs() @@ -231,7 +237,7 @@ public override sealed AtomicReaderContext NextReader /// /// Utility method, to search and also collect all hits - /// into the provided . + /// into the provided . /// public static TopDocs Search(IndexSearcher searcher, Query q, int n, Collector fc) { @@ -240,7 +246,7 @@ public static TopDocs Search(IndexSearcher searcher, Query q, int n, Collector f /// /// Utility method, to search and also collect all hits - /// into the provided . + /// into the provided . /// public static TopDocs Search(IndexSearcher searcher, Query q, Filter filter, int n, Collector fc) { @@ -249,7 +255,7 @@ public static TopDocs Search(IndexSearcher searcher, Query q, Filter filter, int /// /// Utility method, to search and also collect all hits - /// into the provided . + /// into the provided . /// public static TopFieldDocs Search(IndexSearcher searcher, Query q, Filter filter, int n, Sort sort, Collector fc) { @@ -262,7 +268,7 @@ public static TopFieldDocs Search(IndexSearcher searcher, Query q, Filter filter /// /// Utility method, to search and also collect all hits - /// into the provided . + /// into the provided . /// public static TopFieldDocs Search(IndexSearcher searcher, Query q, Filter filter, int n, Sort sort, bool doDocScores, bool doMaxScore, Collector fc) { @@ -275,7 +281,7 @@ public static TopFieldDocs Search(IndexSearcher searcher, Query q, Filter filter /// /// Utility method, to search and also collect all hits - /// into the provided . + /// into the provided . /// public virtual TopDocs SearchAfter(IndexSearcher searcher, ScoreDoc after, Query q, int n, Collector fc) { @@ -284,7 +290,7 @@ public virtual TopDocs SearchAfter(IndexSearcher searcher, ScoreDoc after, Query /// /// Utility method, to search and also collect all hits - /// into the provided . + /// into the provided . /// public static TopDocs SearchAfter(IndexSearcher searcher, ScoreDoc after, Query q, Filter filter, int n, Collector fc) { @@ -293,7 +299,7 @@ public static TopDocs SearchAfter(IndexSearcher searcher, ScoreDoc after, Query /// /// Utility method, to search and also collect all hits - /// into the provided . + /// into the provided . /// public static TopDocs SearchAfter(IndexSearcher searcher, ScoreDoc after, Query q, Filter filter, int n, Sort sort, Collector fc) { @@ -306,7 +312,7 @@ public static TopDocs SearchAfter(IndexSearcher searcher, ScoreDoc after, Query /// /// Utility method, to search and also collect all hits - /// into the provided . + /// into the provided . /// public static TopDocs SearchAfter(IndexSearcher searcher, ScoreDoc after, Query q, Filter filter, int n, Sort sort, bool doDocScores, bool doMaxScore, Collector fc) { diff --git a/src/Lucene.Net.Facet/FacetsConfig.cs b/src/Lucene.Net.Facet/FacetsConfig.cs index 48e97a1fdf..0df6e07c8a 100644 --- a/src/Lucene.Net.Facet/FacetsConfig.cs +++ b/src/Lucene.Net.Facet/FacetsConfig.cs @@ -44,15 +44,16 @@ namespace Lucene.Net.Facet /// /// Records per-dimension configuration. By default a - /// dimension is flat, single valued and does - /// not require count for the dimension; use - /// the setters in this class to change these settings for - /// each dim. + /// dimension is flat, single valued and does + /// not require count for the dimension; use + /// the setters in this class to change these settings for + /// each dim. /// - /// NOTE: this configuration is not saved into the - /// index, but it's vital, and up to the application to - /// ensure, that at search time the provided {@code - /// FacetsConfig} matches what was used during indexing. + /// + /// NOTE: this configuration is not saved into the + /// index, but it's vital, and up to the application to + /// ensure, that at search time the provided + /// matches what was used during indexing. /// /// @lucene.experimental /// @@ -61,7 +62,7 @@ public class FacetsConfig { /// /// Which Lucene field holds the drill-downs and ords (as - /// doc values). + /// doc values). /// public const string DEFAULT_INDEX_FIELD_NAME = "$facets"; @@ -99,7 +100,8 @@ public sealed class DimConfig public string IndexFieldName { get; set; } /// - /// Default constructor. + /// Default constructor. + /// public DimConfig() { IndexFieldName = DEFAULT_INDEX_FIELD_NAME; @@ -111,19 +113,21 @@ public DimConfig() public static readonly DimConfig DEFAULT_DIM_CONFIG = new DimConfig(); /// - /// Default constructor. + /// Default constructor. + /// public FacetsConfig() { } /// /// Get the default configuration for new dimensions. Useful when - /// the dimension is not known beforehand and may need different - /// global default settings, like {@code multivalue = - /// true}. + /// the dimension is not known beforehand and may need different + /// global default settings, like multivalue = true. /// - /// The default configuration to be used for dimensions that - /// are not yet set in the + /// + /// The default configuration to be used for dimensions that + /// are not yet set in the + /// protected virtual DimConfig DefaultDimConfig { get @@ -133,7 +137,8 @@ protected virtual DimConfig DefaultDimConfig } /// - /// Get the current configuration for a dimension. + /// Get the current configuration for a dimension. + /// public virtual DimConfig GetDimConfig(string dimName) { lock (this) @@ -148,8 +153,8 @@ public virtual DimConfig GetDimConfig(string dimName) } /// - /// Pass {@code true} if this dimension is hierarchical - /// (has depth > 1 paths). + /// Pass true if this dimension is hierarchical + /// (has depth > 1 paths). /// public virtual void SetHierarchical(string dimName, bool v) { @@ -168,8 +173,8 @@ public virtual void SetHierarchical(string dimName, bool v) } /// - /// Pass {@code true} if this dimension may have more than - /// one value per document. + /// Pass true if this dimension may have more than + /// one value per document. /// public virtual void SetMultiValued(string dimName, bool v) { @@ -188,9 +193,9 @@ public virtual void SetMultiValued(string dimName, bool v) } /// - /// Pass {@code true} if at search time you require - /// accurate counts of the dimension, i.e. how many - /// hits have this dimension. + /// Pass true if at search time you require + /// accurate counts of the dimension, i.e. how many + /// hits have this dimension. /// public virtual void SetRequireDimCount(string dimName, bool v) { @@ -210,8 +215,8 @@ public virtual void SetRequireDimCount(string dimName, bool v) /// /// Specify which index field name should hold the - /// ordinals for this dimension; this is only used by the - /// taxonomy based facet methods. + /// ordinals for this dimension; this is only used by the + /// taxonomy based facet methods. /// public virtual void SetIndexFieldName(string dimName, string indexFieldName) { @@ -230,7 +235,8 @@ public virtual void SetIndexFieldName(string dimName, string indexFieldName) } /// - /// Returns map of field name to . + /// Returns map of field name to . + /// public virtual IDictionary DimConfigs { get @@ -249,12 +255,12 @@ private static void CheckSeen(HashSet seenDims, string dim) } /// - /// Translates any added s into normal fields for indexing; - /// only use this version if you did not add any taxonomy-based fields ( - /// or ). + /// Translates any added s into normal fields for indexing; + /// only use this version if you did not add any taxonomy-based fields + /// ( or ). /// /// - /// NOTE: you should add the returned document to IndexWriter, not the + /// NOTE: you should add the returned document to , not the /// input one! /// /// @@ -264,10 +270,10 @@ public virtual Document Build(Document doc) } /// - /// Translates any added s into normal fields for indexing. + /// Translates any added s into normal fields for indexing. /// /// - /// NOTE: you should add the returned document to IndexWriter, not the + /// NOTE: you should add the returned document to , not the /// input one! /// /// @@ -527,8 +533,8 @@ private void ProcessAssocFacetFields(ITaxonomyWriter taxoWriter, IDictionary - /// Encodes ordinals into a BytesRef; expert: subclass can - /// override this to change encoding. + /// Encodes ordinals into a ; expert: subclass can + /// override this to change encoding. /// protected virtual BytesRef DedupAndEncode(IntsRef ordinals) { @@ -608,7 +614,8 @@ private void CheckTaxoWriter(ITaxonomyWriter taxoWriter) private const char ESCAPE_CHAR = '\u001E'; /// - /// Turns a dim + path into an encoded string. + /// Turns a dim + path into an encoded string. + /// public static string PathToString(string dim, string[] path) { string[] fullPath = new string[1 + path.Length]; @@ -618,15 +625,16 @@ public static string PathToString(string dim, string[] path) } /// - /// Turns a dim + path into an encoded string. + /// Turns a dim + path into an encoded string. + /// public static string PathToString(string[] path) { return PathToString(path, path.Length); } /// - /// Turns the first {@code length} elements of {@code - /// path} into an encoded string. + /// Turns the first elements of + /// into an encoded string. /// public static string PathToString(string[] path, int length) { @@ -661,9 +669,8 @@ public static string PathToString(string[] path, int length) } /// - /// Turns an encoded string (from a previous call to {@link - /// #pathToString}) back into the original {@code - /// String[]}. + /// Turns an encoded string (from a previous call to ) + /// back into the original . /// public static string[] StringToPath(string s) { diff --git a/src/Lucene.Net.Facet/LabelAndValue.cs b/src/Lucene.Net.Facet/LabelAndValue.cs index bf6271c413..b5719bf241 100644 --- a/src/Lucene.Net.Facet/LabelAndValue.cs +++ b/src/Lucene.Net.Facet/LabelAndValue.cs @@ -22,7 +22,7 @@ namespace Lucene.Net.Facet /// /// Single label and its value, usually contained in a - /// . + /// . /// public sealed class LabelAndValue { @@ -69,14 +69,14 @@ public override string ToString() return Label + " (" + valueString + ")"; } - public override bool Equals(object _other) + public override bool Equals(object other) { - if ((_other is LabelAndValue) == false) + if ((other is LabelAndValue) == false) { return false; } - LabelAndValue other = (LabelAndValue)_other; - return Label.Equals(other.Label) && Value.Equals(other.Value); + LabelAndValue _other = (LabelAndValue)other; + return Label.Equals(_other.Label) && Value.Equals(_other.Value); } public override int GetHashCode() diff --git a/src/Lucene.Net.Facet/Lucene.Net.Facet.csproj b/src/Lucene.Net.Facet/Lucene.Net.Facet.csproj index 1b33158ff4..0270457fea 100644 --- a/src/Lucene.Net.Facet/Lucene.Net.Facet.csproj +++ b/src/Lucene.Net.Facet/Lucene.Net.Facet.csproj @@ -107,6 +107,10 @@ {5d4ad9be-1ffb-41ab-9943-25737971bf57} Lucene.Net + + {e8a339c7-fcf6-4a72-8586-56d8961d7b99} + Lucene.Net.Join + {69d7956c-c2cc-4708-b399-a188fec384c4} Lucene.Net.Queries diff --git a/src/Lucene.Net.Facet/MultiFacets.cs b/src/Lucene.Net.Facet/MultiFacets.cs index 79bb07795b..340b706bef 100644 --- a/src/Lucene.Net.Facet/MultiFacets.cs +++ b/src/Lucene.Net.Facet/MultiFacets.cs @@ -20,8 +20,8 @@ namespace Lucene.Net.Facet */ /// - /// Maps specified dims to provided Facets impls; else, uses - /// the default Facets impl. + /// Maps specified dims to provided impls; else, uses + /// the default impl. /// public class MultiFacets : Facets { @@ -29,8 +29,8 @@ public class MultiFacets : Facets private readonly Facets defaultFacets; /// - /// Create this, with the specified default - /// for fields not included in {@code dimToFacets}. + /// Create this, with the specified default + /// for fields not included in . /// public MultiFacets(IDictionary dimToFacets, Facets defaultFacets = null) { diff --git a/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs b/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs index 491cf5e70d..436f9b0b6a 100644 --- a/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs +++ b/src/Lucene.Net.Facet/RandomSamplingFacetsCollector.cs @@ -32,14 +32,14 @@ namespace Lucene.Net.Facet /// /// Collects hits for subsequent faceting, using sampling if needed. Once you've /// run a search and collect hits into this, instantiate one of the - /// subclasses to do the facet counting. Note that this collector + /// subclasses to do the facet counting. Note that this collector /// does not collect the scores of matching docs (i.e. - /// ) is {@code null}. + /// ) is null. /// /// If you require the original set of hits, you can call - /// . Also, since the counts of the top-facets + /// . Also, since the counts of the top-facets /// is based on the sampled set, you can amortize the counts by calling - /// . + /// . /// /// public class RandomSamplingFacetsCollector : FacetsCollector @@ -56,14 +56,16 @@ private class XORShift64Random internal long x; /// - /// Creates a xorshift random generator using the provided seed + /// Creates a xorshift random generator using the provided seed + /// public XORShift64Random(long seed) { x = seed == 0 ? 0xdeadbeef : seed; } /// - /// Get the next random long value + /// Get the next random long value + /// public virtual long RandomLong() { x ^= (x << 21); @@ -73,7 +75,8 @@ public virtual long RandomLong() } /// - /// Get the next random int, between 0 (inclusive) and n (exclusive) + /// Get the next random int, between 0 (inclusive) and (exclusive) + /// public virtual int NextInt(int n) { int res = (int)(RandomLong() % n); @@ -95,7 +98,7 @@ public virtual int NextInt(int n) /// /// Constructor with the given sample size and default seed. /// - /// + /// public RandomSamplingFacetsCollector(int sampleSize) : this(sampleSize, 0) { @@ -111,7 +114,7 @@ public RandomSamplingFacetsCollector(int sampleSize) /// samplingRatio of 0.01. If the number of hits is lower, no sampling /// is done at all /// - /// The random seed. If {@code 0} then a seed will be chosen for you. + /// The random seed. If 0 then a seed will be chosen for you. public RandomSamplingFacetsCollector(int sampleSize, long seed) : base(false) { @@ -122,15 +125,15 @@ public RandomSamplingFacetsCollector(int sampleSize, long seed) /// /// Returns the sampled list of the matching documents. Note that a - /// instance is returned per segment, even + /// instance is returned per segment, even /// if no hits from that segment are included in the sampled set. /// - /// Note: One or more of the MatchingDocs might be empty (not containing any + /// Note: One or more of the might be empty (not containing any /// hits) as result of sampling. /// /// - /// Note: {@code MatchingDocs.totalHits} is copied from the original - /// MatchingDocs, scores is set to {@code null} + /// Note: is copied from the original + /// , scores is set to null /// /// public override List GetMatchingDocs() @@ -160,14 +163,16 @@ public override List GetMatchingDocs() } /// - /// Returns the original matching documents. + /// Returns the original matching documents. + /// public virtual List GetOriginalMatchingDocs() { return base.GetMatchingDocs(); } /// - /// Create a sampled copy of the matching documents list. + /// Create a sampled copy of the matching documents list. + /// private List CreateSampledDocs(IEnumerable matchingDocsList) { List sampledDocsList = new List(matchingDocsList.Count()); @@ -179,7 +184,8 @@ private List CreateSampledDocs(IEnumerable matchingD } /// - /// Create a sampled of the given hits. + /// Create a sampled of the given hits. + /// private MatchingDocs CreateSample(MatchingDocs docs) { int maxdoc = docs.Context.Reader.MaxDoc; @@ -254,9 +260,9 @@ private MatchingDocs CreateSample(MatchingDocs docs) } /// - /// Note: if you use a counting implementation, you can amortize the - /// sampled counts by calling this method. Uses the and - /// the to determine the upper bound for each facet value. + /// Note: if you use a counting implementation, you can amortize the + /// sampled counts by calling this method. Uses the and + /// the to determine the upper bound for each facet value. /// public virtual FacetResult AmortizeFacetCounts(FacetResult res, FacetsConfig config, IndexSearcher searcher) { @@ -296,7 +302,8 @@ public virtual FacetResult AmortizeFacetCounts(FacetResult res, FacetsConfig con } /// - /// Returns the sampling rate that was used. + /// Returns the sampling rate that was used. + /// public virtual double SamplingRate { get diff --git a/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs b/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs index 7905086a37..47f4b4172b 100644 --- a/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs +++ b/src/Lucene.Net.Facet/Range/DoubleRangeFacetCounts.cs @@ -30,20 +30,20 @@ namespace Lucene.Net.Facet.Range using ValueSource = Lucene.Net.Queries.Function.ValueSource; /// - /// implementation that computes counts for - /// dynamic double ranges from a provided {@link - /// ValueSource}, using . Use + /// implementation that computes counts for + /// dynamic double ranges from a provided , + /// using . Use /// this for dimensions that change in real-time (e.g. a /// relative time based dimension like "Past day", "Past 2 /// days", etc.) or that change for each request (e.g. - /// distance from the user's location, "< 1 km", "< 2 km", + /// distance from the user's location, "< 1 km", "< 2 km", /// etc.). /// - /// If you had indexed your field using {@link - /// FloatDocValuesField} then pass - /// as the ; if you used {@link - /// DoubleDocValuesField} then pass {@link - /// DoubleFieldSource} (this is the default used when you + /// If you had indexed your field using + /// then pass + /// as the ; if you used + /// then pass + /// (this is the default used when you /// pass just a the field name). /// /// @lucene.experimental @@ -52,8 +52,8 @@ namespace Lucene.Net.Facet.Range public class DoubleRangeFacetCounts : RangeFacetCounts { /// - /// Create {@code RangeFacetCounts}, using {@link - /// DoubleFieldSource} from the specified field. + /// Create , using + /// from the specified field. /// public DoubleRangeFacetCounts(string field, FacetsCollector hits, params DoubleRange[] ranges) : this(field, new DoubleFieldSource(field), hits, ranges) @@ -61,8 +61,8 @@ public DoubleRangeFacetCounts(string field, FacetsCollector hits, params DoubleR } /// - /// Create {@code RangeFacetCounts}, using the provided - /// . + /// Create , using the provided + /// . /// public DoubleRangeFacetCounts(string field, ValueSource valueSource, FacetsCollector hits, params DoubleRange[] ranges) : this(field, valueSource, hits, null, ranges) @@ -70,11 +70,11 @@ public DoubleRangeFacetCounts(string field, ValueSource valueSource, FacetsColle } /// - /// Create {@code RangeFacetCounts}, using the provided - /// , and using the provided Filter as - /// a fastmatch: only documents passing the filter are - /// checked for the matching ranges. The filter must be - /// random access (implement ). + /// Create , using the provided + /// , and using the provided Filter as + /// a fastmatch: only documents passing the filter are + /// checked for the matching ranges. The filter must be + /// random access (implement ). /// public DoubleRangeFacetCounts(string field, ValueSource valueSource, FacetsCollector hits, Filter fastMatchFilter, DoubleRange[] ranges) : base(field, ranges, fastMatchFilter) diff --git a/src/Lucene.Net.Facet/Range/LongRangeCounter.cs b/src/Lucene.Net.Facet/Range/LongRangeCounter.cs index f5753fa04b..a871e1eef5 100644 --- a/src/Lucene.Net.Facet/Range/LongRangeCounter.cs +++ b/src/Lucene.Net.Facet/Range/LongRangeCounter.cs @@ -23,11 +23,10 @@ namespace Lucene.Net.Facet.Range /// /// Counts how many times each range was seen; - /// per-hit it's just a binary search () - /// against the elementary intervals, and in the end we - /// rollup back to the original ranges. + /// per-hit it's just a binary search () + /// against the elementary intervals, and in the end we + /// rollup back to the original ranges. /// - internal sealed class LongRangeCounter { internal readonly LongRangeNode root; @@ -205,8 +204,8 @@ public void Add(long v) /// /// Fills counts corresponding to the original input - /// ranges, returning the missing count (how many hits - /// didn't match any ranges). + /// ranges, returning the missing count (how many hits + /// didn't match any ranges). /// public int FillCounts(int[] counts) { @@ -285,7 +284,8 @@ public override string ToString() } /// - /// Holds one node of the segment tree. + /// Holds one node of the segment tree. + /// public sealed class LongRangeNode { internal readonly LongRangeNode left; @@ -328,7 +328,8 @@ internal static void Indent(StringBuilder sb, int depth) } /// - /// Recursively assigns range outputs to each node. + /// Recursively assigns range outputs to each node. + /// internal void AddOutputs(int index, LongRange range) { if (start >= range.minIncl && end <= range.maxIncl) diff --git a/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs b/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs index 60451c4d38..e3a17e7829 100644 --- a/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs +++ b/src/Lucene.Net.Facet/Range/LongRangeFacetCounts.cs @@ -29,13 +29,13 @@ namespace Lucene.Net.Facet.Range using ValueSource = Lucene.Net.Queries.Function.ValueSource; /// - /// implementation that computes counts for - /// dynamic long ranges from a provided , - /// using . Use - /// this for dimensions that change in real-time (e.g. a - /// relative time based dimension like "Past day", "Past 2 - /// days", etc.) or that change for each request (e.g. - /// distance from the user's location, "< 1 km", "< 2 km", + /// implementation that computes counts for + /// dynamic long ranges from a provided , + /// using . Use + /// this for dimensions that change in real-time (e.g. a + /// relative time based dimension like "Past day", "Past 2 + /// days", etc.) or that change for each request (e.g. + /// distance from the user's location, "< 1 km", "< 2 km", /// etc.). /// /// @lucene.experimental @@ -44,8 +44,8 @@ public class LongRangeFacetCounts : RangeFacetCounts { /// - /// Create {@code LongRangeFacetCounts}, using {@link - /// LongFieldSource} from the specified field. + /// Create , using + /// from the specified field. /// public LongRangeFacetCounts(string field, FacetsCollector hits, params LongRange[] ranges) : this(field, new LongFieldSource(field), hits, ranges) @@ -53,8 +53,8 @@ public LongRangeFacetCounts(string field, FacetsCollector hits, params LongRange } /// - /// Create {@code RangeFacetCounts}, using the provided - /// . + /// Create , using the provided + /// . /// public LongRangeFacetCounts(string field, ValueSource valueSource, FacetsCollector hits, params LongRange[] ranges) : this(field, valueSource, hits, null, ranges) @@ -62,11 +62,11 @@ public LongRangeFacetCounts(string field, ValueSource valueSource, FacetsCollect } /// - /// Create {@code RangeFacetCounts}, using the provided - /// , and using the provided Filter as - /// a fastmatch: only documents passing the filter are - /// checked for the matching ranges. The filter must be - /// random access (implement ). + /// Create , using the provided + /// , and using the provided Filter as + /// a fastmatch: only documents passing the filter are + /// checked for the matching ranges. The filter must be + /// random access (implement ). /// public LongRangeFacetCounts(string field, ValueSource valueSource, FacetsCollector hits, Filter fastMatchFilter, params LongRange[] ranges) diff --git a/src/Lucene.Net.Facet/Range/Range.cs b/src/Lucene.Net.Facet/Range/Range.cs index 32ea72471e..ca2e2f487a 100644 --- a/src/Lucene.Net.Facet/Range/Range.cs +++ b/src/Lucene.Net.Facet/Range/Range.cs @@ -44,30 +44,30 @@ protected internal Range(string label) } /// - /// Returns a new accepting only documents - /// in this range. This filter is not general-purpose; - /// you should either use it with by - /// adding it to , or pass it to - /// using its {@link - /// FilteredQuery#QUERY_FIRST_FILTER_STRATEGY}. If the - /// is static, e.g. an indexed numeric - /// field, then it may be more efficient to use {@link - /// NumericRangeFilter}. The provided fastMatchFilter, - /// if non-null, will first be consulted, and only if - /// that is set for each document will the range then be - /// checked. + /// Returns a new accepting only documents + /// in this range. This filter is not general-purpose; + /// you should either use it with by + /// adding it to , or pass it to + /// using its + /// . + /// If the is static, e.g. an indexed numeric + /// field, then it may be more efficient to use + /// . The provided , + /// if non-null, will first be consulted, and only if + /// that is set for each document will the range then be + /// checked. /// public abstract Filter GetFilter(Filter fastMatchFilter, ValueSource valueSource); /// - /// Returns a new accepting only documents + /// Returns a new accepting only documents /// in this range. This filter is not general-purpose; - /// you should either use it with by - /// adding it to , or pass it to - /// using its {@link - /// FilteredQuery#QUERY_FIRST_FILTER_STRATEGY}. If the - /// is static, e.g. an indexed numeric - /// field, then it may be more efficient to use . + /// you should either use it with by + /// adding it to , or pass it to + /// using its + /// . If the + /// is static, e.g. an indexed numeric + /// field, then it may be more efficient to use . /// public virtual Filter GetFilter(ValueSource valueSource) { @@ -75,7 +75,8 @@ public virtual Filter GetFilter(ValueSource valueSource) } /// - /// Invoke this for a useless range. + /// Invoke this for a useless range. + /// protected internal virtual void FailNoMatch() { throw new System.ArgumentException("range \"" + Label + "\" matches nothing"); diff --git a/src/Lucene.Net.Facet/Range/RangeFacetCounts.cs b/src/Lucene.Net.Facet/Range/RangeFacetCounts.cs index 943f4e1577..26472388b6 100644 --- a/src/Lucene.Net.Facet/Range/RangeFacetCounts.cs +++ b/src/Lucene.Net.Facet/Range/RangeFacetCounts.cs @@ -38,9 +38,9 @@ public abstract class RangeFacetCounts : Facets /// /// Optional: if specified, we first test this Filter to - /// see whether the document should be checked for - /// matching ranges. If this is null, all documents are - /// checked. + /// see whether the document should be checked for + /// matching ranges. If this is null, all documents are + /// checked. /// protected internal readonly Filter fastMatchFilter; @@ -53,7 +53,7 @@ public abstract class RangeFacetCounts : Facets protected internal int totCount; /// - /// Create {@code RangeFacetCounts} + /// Create protected internal RangeFacetCounts(string field, Range[] ranges, Filter fastMatchFilter) { this.field = field; diff --git a/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs b/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs index 9ecca3f1ad..efbcbd0678 100644 --- a/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs +++ b/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs @@ -23,7 +23,7 @@ namespace Lucene.Net.Facet.SortedSet */ /// - /// Default implementation of + /// Default implementation of /// public class DefaultSortedSetDocValuesReaderState : SortedSetDocValuesReaderState { @@ -32,14 +32,14 @@ public class DefaultSortedSetDocValuesReaderState : SortedSetDocValuesReaderStat private readonly int valueCount; /// - /// passed to the constructor. + /// passed to the constructor. private readonly IndexReader origReader; private readonly IDictionary prefixToOrdRange = new Dictionary(); /// /// Creates this, pulling doc values from the specified - /// field. + /// field. /// public DefaultSortedSetDocValuesReaderState(IndexReader reader, string field = FacetsConfig.DEFAULT_INDEX_FIELD_NAME) { @@ -97,7 +97,8 @@ public DefaultSortedSetDocValuesReaderState(IndexReader reader, string field = F } /// - /// Return top-level doc values. + /// Return top-level doc values. + /// public override SortedSetDocValues DocValues { get @@ -107,7 +108,8 @@ public override SortedSetDocValues DocValues } /// - /// Returns mapping from prefix to . + /// Returns mapping from prefix to . + /// public override IDictionary PrefixToOrdRange { get @@ -117,14 +119,16 @@ public override IDictionary PrefixToOrdRange } /// - /// Returns the for this dimension. + /// Returns the for this dimension. + /// public override OrdRange GetOrdRange(string dim) { return prefixToOrdRange[dim]; } /// - /// Indexed field we are reading. + /// Indexed field we are reading. + /// public override string Field { get @@ -142,7 +146,8 @@ public override IndexReader OrigReader } /// - /// Number of unique labels. + /// Number of unique labels. + /// public override int Count { get diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs index e552d830a3..dc5dba3fea 100644 --- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs +++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs @@ -32,18 +32,18 @@ namespace Lucene.Net.Facet.SortedSet /// /// Compute facets counts from previously - /// indexed , - /// without require a separate taxonomy index. Faceting is - /// a bit slower (~25%), and there is added cost on every - /// open to create a new {@link - /// SortedSetDocValuesReaderState}. Furthermore, this does - /// not support hierarchical facets; only flat (dimension + - /// label) facets, but it uses quite a bit less RAM to do - /// so. + /// indexed , + /// without require a separate taxonomy index. Faceting is + /// a bit slower (~25%), and there is added cost on every + /// open to create a new + /// . Furthermore, this does + /// not support hierarchical facets; only flat (dimension + + /// label) facets, but it uses quite a bit less RAM to do + /// so. /// - /// NOTE: this class should be instantiated and - /// then used from a single thread, because it holds a - /// thread-private instance of . + /// NOTE: this class should be instantiated and + /// then used from a single thread, because it holds a + /// thread-private instance of . /// /// /// NOTE:: tie-break is by unicode sort order @@ -60,7 +60,7 @@ public class SortedSetDocValuesFacetCounts : Facets /// /// Sparse faceting: returns any dimension that had any - /// hits, topCount labels per dimension. + /// hits, topCount labels per dimension. /// public SortedSetDocValuesFacetCounts(SortedSetDocValuesReaderState state, FacetsCollector hits) { diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetField.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetField.cs index ba1f360b8f..3714679d5a 100644 --- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetField.cs +++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetField.cs @@ -21,13 +21,13 @@ using FieldType = Lucene.Net.Documents.FieldType; /// - /// Add an instance of this to your Document for every facet - /// label to be indexed via SortedSetDocValues. + /// Add an instance of this to your for every facet + /// label to be indexed via . /// public class SortedSetDocValuesFacetField : Field { /// - /// Indexed . + /// Indexed . public static readonly FieldType TYPE = new FieldType(); static SortedSetDocValuesFacetField() { diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesReaderState.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesReaderState.cs index 636d4345df..1584e4a0fc 100644 --- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesReaderState.cs +++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesReaderState.cs @@ -23,29 +23,29 @@ namespace Lucene.Net.Facet.SortedSet using SortedSetDocValues = Lucene.Net.Index.SortedSetDocValues; /// - /// Wraps a and resolves ords - /// using existing APIs without a - /// separate taxonomy index. This only supports flat facets - /// (dimension + label), and it makes faceting a bit - /// slower, adds some cost at reopen time, but avoids - /// managing the separate taxonomy index. It also requires - /// less RAM than the taxonomy index, as it manages the flat - /// (2-level) hierarchy more efficiently. In addition, the - /// tie-break during faceting is now meaningful (in label - /// sorted order). + /// Wraps a and resolves ords + /// using existing APIs without a + /// separate taxonomy index. This only supports flat facets + /// (dimension + label), and it makes faceting a bit + /// slower, adds some cost at reopen time, but avoids + /// managing the separate taxonomy index. It also requires + /// less RAM than the taxonomy index, as it manages the flat + /// (2-level) hierarchy more efficiently. In addition, the + /// tie-break during faceting is now meaningful (in label + /// sorted order). /// - /// NOTE: creating an instance of this class is - /// somewhat costly, as it computes per-segment ordinal maps, - /// so you should create it once and re-use that one instance - /// for a given . + /// NOTE: creating an instance of this class is + /// somewhat costly, as it computes per-segment ordinal maps, + /// so you should create it once and re-use that one instance + /// for a given . /// /// public abstract class SortedSetDocValuesReaderState { /// /// Holds start/end range of ords, which maps to one - /// dimension (someday we may generalize it to map to - /// hierarchies within one dimension). + /// dimension (someday we may generalize it to map to + /// hierarchies within one dimension). /// public sealed class OrdRange { @@ -80,11 +80,11 @@ protected internal SortedSetDocValuesReaderState() public abstract string Field { get; } /// - /// Returns the for this dimension. + /// Returns the for this dimension. public abstract OrdRange GetOrdRange(string dim); /// - /// Returns mapping from prefix to . + /// Returns mapping from prefix to . public abstract IDictionary PrefixToOrdRange { get; } /// diff --git a/src/Lucene.Net.Facet/Taxonomy/AssociationFacetField.cs b/src/Lucene.Net.Facet/Taxonomy/AssociationFacetField.cs index f2e70a7fbb..c9fd7af89a 100644 --- a/src/Lucene.Net.Facet/Taxonomy/AssociationFacetField.cs +++ b/src/Lucene.Net.Facet/Taxonomy/AssociationFacetField.cs @@ -25,20 +25,20 @@ namespace Lucene.Net.Facet.Taxonomy using FieldType = Lucene.Net.Documents.FieldType; /// - /// Add an instance of this to your to add - /// a facet label associated with an arbitrary byte[]. - /// This will require a custom - /// implementation at search time; see {@link - /// IntAssociationFacetField} and {@link - /// FloatAssociationFacetField} to use existing {@link - /// Facets} implementations. + /// Add an instance of this to your to add + /// a facet label associated with an arbitrary . + /// This will require a custom + /// implementation at search time; see + /// and to use existing + /// implementations. /// /// @lucene.experimental /// public class AssociationFacetField : Field { /// - /// Indexed . + /// Indexed . + /// public static readonly FieldType TYPE = new FieldType(); static AssociationFacetField() { @@ -47,20 +47,23 @@ static AssociationFacetField() } /// - /// Dimension for this field. + /// Dimension for this field. + /// public string Dim { get; private set; } /// - /// Facet path for this field. + /// Facet path for this field. + /// public string[] Path { get; private set; } /// - /// Associated value. + /// Associated value. + /// public BytesRef Assoc { get; private set; } /// - /// Creates this from {@code dim} and {@code path} and an - /// association + /// Creates this from and and an + /// association /// public AssociationFacetField(BytesRef assoc, string dim, params string[] path) : base("dummy", TYPE) diff --git a/src/Lucene.Net.Facet/Taxonomy/CachedOrdinalsReader.cs b/src/Lucene.Net.Facet/Taxonomy/CachedOrdinalsReader.cs index 62ee95f11f..6cb16de188 100644 --- a/src/Lucene.Net.Facet/Taxonomy/CachedOrdinalsReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/CachedOrdinalsReader.cs @@ -32,13 +32,13 @@ namespace Lucene.Net.Facet.Taxonomy /// /// A per-segment cache of documents' facet ordinals. Every - /// holds the ordinals in a raw {@code - /// int[]}, and therefore consumes as much RAM as the total + /// holds the ordinals in a raw , + /// and therefore consumes as much RAM as the total /// number of ordinals found in the segment, but saves the /// CPU cost of decoding ordinals during facet counting. /// /// - /// NOTE: every is limited to 2.1B + /// NOTE: every is limited to 2.1B /// total ordinals. If that is a limitation for you then /// consider limiting the segment size to fewer documents, or /// use an alternative cache which pages through the category @@ -47,7 +47,7 @@ namespace Lucene.Net.Facet.Taxonomy /// /// /// NOTE: when using this cache, it is advised to use - /// a that does not cache the data in + /// a that does not cache the data in /// memory, at least for the category lists fields, or /// otherwise you'll be doing double-caching. /// @@ -122,20 +122,23 @@ public override void Get(int docID, IntsRef ordinals) } /// - /// Holds the cached ordinals in two parallel {@code int[]} arrays. + /// Holds the cached ordinals in two parallel arrays. + /// public sealed class CachedOrds : Accountable { /// - /// Index into for each document. + /// Index into for each document. + /// public int[] Offsets { get; private set; } /// - /// Holds ords for all docs. + /// Holds ords for all docs. + /// public int[] Ordinals { get; private set; } /// - /// Creates a new from the . - /// Assumes that the is not {@code null}. + /// Creates a new from the . + /// Assumes that the is not null. /// public CachedOrds(OrdinalsSegmentReader source, int maxDoc) { diff --git a/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs b/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs index ae177b65ef..9b525033c6 100644 --- a/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs +++ b/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs @@ -31,19 +31,20 @@ namespace Lucene.Net.Facet.Taxonomy public class CategoryPath : IComparable { /// - /// An empty + /// An empty + /// public static readonly CategoryPath EMPTY = new CategoryPath(); /// - /// The components of this . Note that this array may be - /// shared with other instances, e.g. as a result of - /// , therefore you should traverse the array up to - /// for this path's components. + /// The components of this . Note that this array may be + /// shared with other instances, e.g. as a result of + /// , therefore you should traverse the array up to + /// for this path's components. /// public string[] Components { get; private set; } /// - /// The number of components of this . + /// The number of components of this . public int Length { get; private set; } // Used by singleton EMPTY @@ -65,7 +66,8 @@ private CategoryPath(CategoryPath copyFrom, int prefixLen) } /// - /// Construct from the given path components. + /// Construct from the given path . + /// public CategoryPath(params string[] components) { Debug.Assert(components.Length > 0, "use CategoryPath.EMPTY to create an empty path"); @@ -81,7 +83,8 @@ public CategoryPath(params string[] components) } /// - /// Construct from a given path, separating path components with {@code delimiter}. + /// Construct from a given path, separating path components with . + /// public CategoryPath(string pathString, char delimiter) { string[] comps = pathString.Split(new[] { delimiter }, StringSplitOptions.RemoveEmptyEntries); @@ -107,7 +110,7 @@ public CategoryPath(string pathString, char delimiter) /// /// Returns the number of characters needed to represent the path, including /// delimiter characters, for using with - /// . + /// . /// public virtual int FullPathLength() { @@ -126,7 +129,7 @@ public virtual int FullPathLength() } /// - /// Compares this path with another for lexicographic + /// Compares this path with another for lexicographic /// order. /// public virtual int CompareTo(CategoryPath other) @@ -167,14 +170,14 @@ private void NoDelimiter(char[] buf, int offset, int len, char delimiter) } /// - /// Copies the path components to the given {@code char[]}, starting at index - /// {@code start}. {@code delimiter} is copied between the path components. + /// Copies the path components to the given , starting at index + /// . is copied between the path components. /// Returns the number of chars copied. /// /// /// NOTE: this method relies on the array being large enough to hold the /// components and separators - the amount of needed space can be calculated - /// with . + /// with . /// /// public virtual int CopyFullPath(char[] buf, int start, char delimiter) @@ -241,7 +244,8 @@ public override int GetHashCode() } /// - /// Calculate a 64-bit hash function for this path. + /// Calculate a 64-bit hash function for this path. + /// public virtual long LongHashCode() { if (Length == 0) @@ -258,7 +262,8 @@ public virtual long LongHashCode() } /// - /// Returns a sub-path of this path up to {@code length} components. + /// Returns a sub-path of this path up to components. + /// public virtual CategoryPath Subpath(int length) { if (length >= this.Length || length < 0) @@ -279,7 +284,7 @@ public virtual CategoryPath Subpath(int length) /// Returns a string representation of the path, separating components with /// '/'. /// - /// + /// public override string ToString() { return ToString('/'); diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs index 4552f08456..09496140c5 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs @@ -34,8 +34,8 @@ namespace Lucene.Net.Facet.Taxonomy.Directory using MultiFields = Lucene.Net.Index.MultiFields; /// - /// A which retrieves stored taxonomy information from a - /// . + /// A which retrieves stored taxonomy information from a + /// . ///

/// Reading from the on-disk index on every method call is too slow, so this /// implementation employs caching: Some methods cache recent requests and their @@ -64,8 +64,8 @@ public class IntClass private volatile TaxonomyIndexArrays taxoArrays; ///

- /// Called only from . If the taxonomy has been - /// recreated, you should pass {@code null} as the caches and parent/children + /// Called only from . If the taxonomy has been + /// recreated, you should pass null as the caches and parent/children /// arrays. /// internal DirectoryTaxonomyReader(DirectoryReader indexReader, DirectoryTaxonomyWriter taxoWriter, @@ -84,14 +84,11 @@ internal DirectoryTaxonomyReader(DirectoryReader indexReader, DirectoryTaxonomyW } /// - /// Open for reading a taxonomy stored in a given . + /// Open for reading a taxonomy stored in a given . /// - /// - /// The in which the taxonomy resides. - /// - /// if the Taxonomy is corrupt. - /// - /// if another error occurred. + /// The in which the taxonomy resides. + /// if the Taxonomy is corrupt. + /// if another error occurred. public DirectoryTaxonomyReader(Directory directory) { indexReader = OpenIndexReader(directory); @@ -106,11 +103,11 @@ public DirectoryTaxonomyReader(Directory directory) } /// - /// Opens a over the given - /// (for NRT). + /// Opens a over the given + /// (for NRT). /// /// - /// The from which to obtain newly + /// The from which to obtain newly /// added categories, in real-time. public DirectoryTaxonomyReader(DirectoryTaxonomyWriter taxoWriter) { @@ -150,16 +147,16 @@ protected internal override void DoClose() } /// - /// Implements the opening of a new instance if + /// Implements the opening of a new instance if /// the taxonomy has changed. /// /// - /// NOTE: the returned shares the + /// NOTE: the returned shares the /// ordinal and category caches with this reader. This is not expected to cause /// any issues, unless the two instances continue to live. The reader /// guarantees that the two instances cannot affect each other in terms of /// correctness of the caches, however if the size of the cache is changed - /// through , it will affect both reader instances. + /// through , it will affect both reader instances. /// /// protected override TaxonomyReader DoOpenIfChanged() @@ -231,8 +228,7 @@ protected override TaxonomyReader DoOpenIfChanged() } /// - /// Open the from this {@link - /// Directory}. + /// Open the from this . /// protected virtual DirectoryReader OpenIndexReader(Directory directory) { @@ -240,8 +236,7 @@ protected virtual DirectoryReader OpenIndexReader(Directory directory) } /// - /// Open the from this {@link - /// IndexWriter}. + /// Open the from this . /// protected virtual DirectoryReader OpenIndexReader(IndexWriter writer) { @@ -249,8 +244,8 @@ protected virtual DirectoryReader OpenIndexReader(IndexWriter writer) } /// - /// Expert: returns the underlying instance that is - /// used by this . + /// Expert: returns the underlying instance that is + /// used by this . /// internal virtual DirectoryReader InternalIndexReader { @@ -379,13 +374,13 @@ public override int Count } /// - /// setCacheSize controls the maximum allowed size of each of the caches - /// used by and . + /// Setting controls the maximum allowed size of each of the caches + /// used by and . ///

/// Currently, if the given size is smaller than the current size of /// a cache, it will not shrink, and rather we be limited to its current /// size.

- /// the new maximum cache size, in number of entries. + /// the new maximum cache size, in number of entries. public virtual int CacheSize { set @@ -400,8 +395,8 @@ public virtual int CacheSize /// /// Returns ordinal -> label mapping, up to the provided - /// max ordinal or number of ordinals, whichever is - /// smaller. + /// max ordinal or number of ordinals, whichever is + /// smaller. /// public virtual string ToString(int max) { diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs index dd497fd636..f59337e630 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs @@ -54,20 +54,20 @@ namespace Lucene.Net.Facet.Taxonomy.Directory using TokenStream = Lucene.Net.Analysis.TokenStream; /// - /// which uses a to store the taxonomy + /// which uses a to store the taxonomy /// information on disk, and keeps an additional in-memory cache of some or all /// categories. /// - /// In addition to the permanently-stored information in the , - /// efficiency dictates that we also keep an in-memory cache of recently - /// seen or all categories, so that we do not need to go back to disk + /// In addition to the permanently-stored information in the , + /// efficiency dictates that we also keep an in-memory cache of recently + /// seen or all categories, so that we do not need to go back to disk /// for every category addition to see which ordinal this category already has, - /// if any. A object determines the specific caching + /// if any. A object determines the specific caching /// algorithm used. /// /// /// This class offers some hooks for extending classes to control the - /// instance that is used. See . + /// instance that is used. See . /// /// @lucene.experimental /// @@ -77,7 +77,7 @@ public class DirectoryTaxonomyWriter : ITaxonomyWriter /// /// Property name of user commit data that contains the index epoch. The epoch /// changes whenever the taxonomy is recreated (i.e. opened with - /// . + /// . /// /// Applications should not use this property in their commit data because it /// will be overridden by this taxonomy writer. @@ -107,12 +107,12 @@ public class DirectoryTaxonomyWriter : ITaxonomyWriter /// /// We call the cache "complete" if we know that every category in our - /// taxonomy is in the cache. When the cache is not complete, and + /// taxonomy is in the cache. When the cache is not complete, and /// we can't find a category in the cache, we still need to look for it /// in the on-disk index; Therefore when the cache is not complete, we /// need to open a "reader" to the taxonomy index. /// The cache becomes incomplete if it was never filled with the existing - /// categories, or if a put() to the cache ever returned true (meaning + /// categories, or if a Put() to the cache ever returned true (meaning /// that some of the cached data was cleared). /// private volatile bool cacheIsComplete; @@ -121,7 +121,7 @@ public class DirectoryTaxonomyWriter : ITaxonomyWriter private volatile int nextID; /// - /// Reads the commit data from a Directory. + /// Reads the commit data from a . private static IDictionary ReadCommitData(Directory dir) { SegmentInfos infos = new SegmentInfos(); @@ -136,9 +136,9 @@ private static IDictionary ReadCommitData(Directory dir) /// known that no other process nor thread is in fact currently accessing /// this taxonomy. ///

- /// This method is unnecessary if your uses a - /// instead of the default - /// . When the "native" lock is used, a lock + /// This method is unnecessary if your uses a + /// instead of the default + /// . When the "native" lock is used, a lock /// does not stay behind forever when the process using it dies. ///

public static void Unlock(Directory directory) @@ -150,28 +150,28 @@ public static void Unlock(Directory directory) /// Construct a Taxonomy writer. ///
/// - /// The in which to store the taxonomy. Note that + /// The in which to store the taxonomy. Note that /// the taxonomy is written directly to that directory (not to a /// subdirectory of it). /// - /// Specifies how to open a taxonomy for writing: APPEND + /// Specifies how to open a taxonomy for writing: /// means open an existing index for append (failing if the index does - /// not yet exist). CREATE means create a new index (first + /// not yet exist). means create a new index (first /// deleting the old one if it already existed). - /// APPEND_OR_CREATE appends to an existing index if there + /// appends to an existing index if there /// is one, otherwise it creates a new index. /// - /// A implementation which determines + /// A implementation which determines /// the in-memory caching policy. See for example - /// and . - /// If null or missing, is used. + /// and . + /// If null or missing, is used. /// /// if the taxonomy is corrupted. /// /// if the taxonomy is locked by another writer. If it is known /// that no other concurrent writer is active, the lock might /// have been left around by an old dead process, and should be - /// removed using . + /// removed using . /// /// if another error occurred. public DirectoryTaxonomyWriter(Directory directory, OpenMode openMode, @@ -250,18 +250,17 @@ public DirectoryTaxonomyWriter(Directory directory, OpenMode openMode, /// /// Open internal index writer, which contains the taxonomy data. /// - /// Extensions may provide their own implementation or instance. - ///
NOTE: the instance this method returns will be closed upon calling - /// to . + /// Extensions may provide their own implementation or instance. + ///
NOTE: the instance this method returns will be disposed upon calling + /// to . ///
NOTE: the merge policy in effect must not merge none adjacent segments. See - /// comment in for the logic behind this. + /// comment in for the logic behind this. /// ///
///
- /// + /// /// - /// the on top of which an + /// the on top of which an /// should be opened. /// /// configuration for the internal index writer. @@ -271,18 +270,17 @@ protected virtual IndexWriter OpenIndexWriter(Directory directory, IndexWriterCo } /// - /// Create the that would be used for opening the internal index writer. - ///
Extensions can configure the as they see fit, - /// including setting a , or - /// , different RAM size + /// Create the that would be used for opening the internal index writer. + ///
Extensions can configure the as they see fit, + /// including setting a , or + /// , different RAM size /// etc.
///
NOTE: internal docids of the configured index must not be altered. /// For that, categories are never deleted from the taxonomy index. /// In addition, merge policy in effect must not merge none adjacent segments. ///
- /// - /// see + /// + /// see protected virtual IndexWriterConfig CreateIndexWriterConfig(OpenMode openMode) { // TODO: should we use a more optimized Codec, e.g. Pulsing (or write custom)? @@ -295,7 +293,7 @@ protected virtual IndexWriterConfig CreateIndexWriterConfig(OpenMode openMode) } /// - /// Opens a from the internal . + /// Opens a from the internal . /// private void InitReaderManager() { @@ -317,7 +315,7 @@ private void InitReaderManager() /// /// Creates a new instance with a default cache as defined by - /// . + /// . /// public DirectoryTaxonomyWriter(Directory directory, OpenMode openMode = OpenMode.CREATE_OR_APPEND) : this(directory, openMode, DefaultTaxonomyWriterCache()) @@ -325,12 +323,13 @@ public DirectoryTaxonomyWriter(Directory directory, OpenMode openMode = OpenMode } /// - /// Defines the default to use in constructors + /// Defines the default to use in constructors /// which do not specify one. - ///

- /// The current default is constructed + /// + /// The current default is constructed /// with the parameters (1024, 0.15f, 3), i.e., the entire taxonomy is /// cached in memory while building it. + /// ///

public static ITaxonomyWriterCache DefaultTaxonomyWriterCache() { @@ -338,9 +337,9 @@ public static ITaxonomyWriterCache DefaultTaxonomyWriterCache() } /// - /// Frees used resources as well as closes the underlying , + /// Frees used resources as well as closes the underlying , /// which commits whatever changes made to it to the underlying - /// . + /// . /// public void Dispose() { @@ -363,10 +362,12 @@ private void DoClose() /// /// A hook for extending classes to close additional resources that were used. - /// The default implementation closes the as well as the - /// instances that were used.
+ /// The default implementation closes the as well as the + /// instances that were used. + /// /// NOTE: if you override this method, you should include a - /// super.closeResources() call in your implementation. + /// base.CloseResources() call in your implementation. + /// ///
protected virtual void CloseResources() { @@ -529,7 +530,7 @@ private int InternalAddCategory(FacetLabel cp) /// /// Verifies that this instance wasn't closed, or throws - /// if it is. + /// if it is. /// protected internal void EnsureOpen() { @@ -540,7 +541,7 @@ protected internal void EnsureOpen() } /// - /// Note that the methods calling addCategoryDocument() are synchornized, so + /// Note that the methods calling are synchornized, so /// this method is effectively synchronized as well. /// private int AddCategoryDocument(FacetLabel categoryPath, int parent) @@ -598,15 +599,16 @@ public SinglePositionTokenStream(string word) /// /// Set the value we want to keep, as the position increment. - /// Note that when TermPositions.nextPosition() is later used to + /// Note that when TermPositions.NextPosition() is later used to /// retrieve this value, val-1 will be returned, not val. - ///

+ /// /// IMPORTANT NOTE: Before Lucene 2.9, val>=0 were safe (for val==0, /// the retrieved position would be -1). But starting with Lucene 2.9, /// this unfortunately changed, and only val>0 are safe. val=0 can /// still be used, but don't count on the value you retrieve later /// (it could be 0 or -1, depending on circumstances or versions). - /// This change is described in Lucene's JIRA: LUCENE-1542. + /// This change is described in Lucene's JIRA: LUCENE-1542. + /// ///

public virtual void Set(int val) { @@ -679,7 +681,8 @@ public virtual void Commit() } /// - /// Combine original user data with the taxonomy epoch. + /// Combine original user data with the taxonomy epoch. + /// private IDictionary CombinedCommitData(IDictionary commitData) { IDictionary m = new Dictionary(); @@ -706,7 +709,7 @@ public virtual IDictionary CommitData /// /// prepare most of the work needed for a two-phase commit. - /// See . + /// See . /// public virtual void PrepareCommit() { @@ -744,7 +747,7 @@ public virtual int Count /// after a certain number (defined by this method) of cache misses. /// /// - /// If the number is set to {@code 0}, the entire taxonomy is read into the + /// If the number is set to 0, the entire taxonomy is read into the /// cache on first use, without fetching individual categories first. /// /// @@ -894,7 +897,7 @@ public virtual int GetParent(int ordinal) /// /// Takes the categories from the given taxonomy directory, and adds the /// missing ones to this taxonomy. Additionally, it fills the given - /// with a mapping from the original ordinal to the new + /// with a mapping from the original ordinal to the new /// ordinal. /// public virtual void AddTaxonomy(Directory taxoDir, IOrdinalMap map) @@ -935,13 +938,13 @@ public virtual void AddTaxonomy(Directory taxoDir, IOrdinalMap map) /// Mapping from old ordinal to new ordinals, used when merging indexes /// wit separate taxonomies. /// - /// addToTaxonomies() merges one or more taxonomies into the given taxonomy - /// (this). An IOrdinalMap is filled for each of the added taxonomies, + /// merges one or more taxonomies into the given taxonomy + /// (this). An is filled for each of the added taxonomies, /// containing the new ordinal (in the merged taxonomy) of each of the /// categories in the old taxonomy. ///

- /// There exist two implementations of IOrdinalMap: MemoryOrdinalMap and - /// DiskOrdinalMap. As their names suggest, the former keeps the map in + /// There exist two implementations of : and + /// . As their names suggest, the former keeps the map in /// memory and the latter in a temporary disk file. Because these maps will /// later be needed one by one (to remap the counting lists), not all at the /// same time, it is recommended to put the first taxonomy's map in memory, @@ -952,10 +955,10 @@ public virtual void AddTaxonomy(Directory taxoDir, IOrdinalMap map) public interface IOrdinalMap { ///

- /// Set the size of the map. This MUST be called before addMapping(). - /// It is assumed (but not verified) that addMapping() will then be - /// called exactly 'size' times, with different origOrdinals between 0 - /// and size-1. + /// Set the size of the map. This MUST be called before . + /// It is assumed (but not verified) that will then be + /// called exactly 'size' times, with different between 0 + /// and size - 1. /// void SetSize(int taxonomySize); @@ -964,7 +967,7 @@ public interface IOrdinalMap void AddMapping(int origOrdinal, int newOrdinal); /// - /// Call addDone() to say that all addMapping() have been done. + /// Call to say that all have been done. /// In some implementations this might free some resources. /// void AddDone(); @@ -981,7 +984,7 @@ public interface IOrdinalMap } /// - /// maintained in memory + /// maintained in memory /// public sealed class MemoryOrdinalMap : IOrdinalMap { @@ -1026,7 +1029,7 @@ public int[] Map } /// - /// maintained on file system + /// maintained on file system /// public sealed class DiskOrdinalMap : IOrdinalMap { @@ -1102,7 +1105,7 @@ public int[] Map /// /// Rollback changes to the taxonomy writer and closes the instance. Following /// this method the instance becomes unusable (calling any of its API methods - /// will yield an ). + /// will yield an ). /// public virtual void Rollback() { @@ -1117,7 +1120,7 @@ public virtual void Rollback() /// /// Replaces the current taxonomy with the given one. This method should /// generally be called in conjunction with - /// to replace both the taxonomy + /// to replace both the taxonomy /// as well as the search index content. /// public virtual void ReplaceTaxonomy(Directory taxoDir) @@ -1146,7 +1149,8 @@ public virtual void ReplaceTaxonomy(Directory taxoDir) } /// - /// Returns the of this taxonomy writer. + /// Returns the of this taxonomy writer. + /// public virtual Directory Directory { get @@ -1156,9 +1160,9 @@ public virtual Directory Directory } /// - /// Used by to support NRT. + /// Used by to support NRT. /// - /// NOTE: you should not use the obtained in any + /// NOTE: you should not use the obtained in any /// way, other than opening an IndexReader on it, or otherwise, the taxonomy /// index may become corrupt! /// @@ -1173,8 +1177,8 @@ internal IndexWriter InternalIndexWriter /// /// Expert: returns current index epoch, if this is a - /// near-real-time reader. Used by {@link - /// DirectoryTaxonomyReader} to support NRT. + /// near-real-time reader. Used by + /// to support NRT. /// /// @lucene.internal /// diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/TaxonomyIndexArrays.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/TaxonomyIndexArrays.cs index 9cbaaed8d0..a2613745ad 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/TaxonomyIndexArrays.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/TaxonomyIndexArrays.cs @@ -28,7 +28,7 @@ namespace Lucene.Net.Facet.Taxonomy.Directory using MultiFields = Lucene.Net.Index.MultiFields; /// - /// A that are initialized from the taxonomy + /// A that are initialized from the taxonomy /// index. /// /// @lucene.experimental @@ -45,7 +45,8 @@ internal class TaxonomyIndexArrays : ParallelTaxonomyArrays private int[] children, siblings; /// - /// Used by after the array grew. + /// Used by after the array grew. + /// private TaxonomyIndexArrays(int[] parents) { this.parents = parents; @@ -137,7 +138,9 @@ private void ComputeChildrenSiblings(int first) } } - // Read the parents of the new categories + /// + /// Read the parents of the new categories + /// private void InitParents(IndexReader reader, int first) { if (reader.MaxDoc == first) @@ -204,8 +207,8 @@ internal virtual TaxonomyIndexArrays Add(int ordinal, int parentOrdinal) } /// - /// Returns the parents array, where {@code parents[i]} denotes the parent of - /// category ordinal {@code i}. + /// Returns the parents array, where Parents[i] denotes the parent of + /// category ordinal i. /// public override int[] Parents { @@ -216,10 +219,10 @@ public override int[] Parents } /// - /// Returns the children array, where {@code children[i]} denotes the youngest - /// child of category ordinal {@code i}. The youngest child is defined as the + /// Returns the children array, where Children[i] denotes the youngest + /// child of category ordinal i. The youngest child is defined as the /// category that was added last to the taxonomy as an immediate child of - /// {@code i}. + /// i. /// public override int[] Children { @@ -236,9 +239,9 @@ public override int[] Children } /// - /// Returns the siblings array, where {@code siblings[i]} denotes the sibling - /// of category ordinal {@code i}. The sibling is defined as the previous - /// youngest child of {@code parents[i]}. + /// Returns the siblings array, where Siblings[i] denotes the sibling + /// of category ordinal i. The sibling is defined as the previous + /// youngest child of Parents[i]. /// public override int[] Siblings { diff --git a/src/Lucene.Net.Facet/Taxonomy/DocValuesOrdinalsReader.cs b/src/Lucene.Net.Facet/Taxonomy/DocValuesOrdinalsReader.cs index 3d5cc53963..b48eafd79e 100644 --- a/src/Lucene.Net.Facet/Taxonomy/DocValuesOrdinalsReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/DocValuesOrdinalsReader.cs @@ -25,21 +25,23 @@ using IntsRef = Lucene.Net.Util.IntsRef; /// - /// Decodes ordinals previously indexed into a BinaryDocValues field - + /// Decodes ordinals previously indexed into a field + /// public class DocValuesOrdinalsReader : OrdinalsReader { private readonly string field; /// - /// Default constructor. + /// Default constructor. + /// public DocValuesOrdinalsReader() : this(FacetsConfig.DEFAULT_INDEX_FIELD_NAME) { } /// - /// Create this, with the specified indexed field name. + /// Create this, with the specified indexed field name. + /// public DocValuesOrdinalsReader(string field) { this.field = field; @@ -87,7 +89,8 @@ public override string IndexFieldName } /// - /// Subclass & override if you change the encoding. + /// Subclass & override if you change the encoding. + /// protected virtual void Decode(BytesRef buf, IntsRef ordinals) { diff --git a/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs b/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs index edc68c0a99..56a16afabf 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FacetLabel.cs @@ -40,20 +40,21 @@ public class FacetLabel : IComparable * be on the safe side. */ /// - /// The maximum number of characters a can have. + /// The maximum number of characters a can have. /// public static readonly int MAX_CATEGORY_PATH_LENGTH = (BYTE_BLOCK_SIZE - 2) / 4; /// - /// The components of this . Note that this array may be - /// shared with other instances, e.g. as a result of - /// , therefore you should traverse the array up to - /// for this path's components. + /// The components of this . Note that this array may be + /// shared with other instances, e.g. as a result of + /// , therefore you should traverse the array up to + /// for this path's components. /// public string[] Components { get; private set; } /// - /// The number of components of this . + /// The number of components of this . + /// public int Length { get; private set; } // Used by subpath @@ -68,7 +69,8 @@ private FacetLabel(FacetLabel copyFrom, int prefixLen) } /// - /// Construct from the given path components. + /// Construct from the given path components. + /// public FacetLabel(params string[] components) { this.Components = components; @@ -77,7 +79,8 @@ public FacetLabel(params string[] components) } /// - /// Construct from the dimension plus the given path components. + /// Construct from the dimension plus the given path components. + /// public FacetLabel(string dim, string[] path) { Components = new string[1 + path.Length]; @@ -106,7 +109,7 @@ private void CheckComponents() } /// - /// Compares this path with another for lexicographic + /// Compares this path with another for lexicographic /// order. /// public virtual int CompareTo(FacetLabel other) @@ -171,10 +174,9 @@ public override int GetHashCode() /// /// Calculate a 64-bit hash function for this path. This - /// is necessary for (the - /// default cache impl for {@link - /// LruTaxonomyWriterCache}) to reduce the chance of - /// "silent but deadly" collisions. + /// is necessary for (the + /// default cache impl for ) + /// to reduce the chance of "silent but deadly" collisions. /// public virtual long LongHashCode() { @@ -192,16 +194,17 @@ public virtual long LongHashCode() } /// - /// Returns a sub-path of this path up to {@code length} components. - public virtual FacetLabel Subpath(int len) + /// Returns a sub-path of this path up to components. + /// + public virtual FacetLabel Subpath(int length) { - if (len >= this.Length || len < 0) + if (length >= this.Length || length < 0) { return this; } else { - return new FacetLabel(this, len); + return new FacetLabel(this, length); } } diff --git a/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs b/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs index 3511af8461..6cb5043b89 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs @@ -26,15 +26,15 @@ namespace Lucene.Net.Facet.Taxonomy /// /// Computes facets counts, assuming the default encoding - /// into DocValues was used. + /// into DocValues was used. /// /// @lucene.experimental /// public class FastTaxonomyFacetCounts : IntTaxonomyFacets { /// - /// Create {@code FastTaxonomyFacetCounts}, which also - /// counts all facet labels. + /// Create , which also + /// counts all facet labels. /// public FastTaxonomyFacetCounts(TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc) : this(FacetsConfig.DEFAULT_INDEX_FIELD_NAME, taxoReader, config, fc) @@ -42,11 +42,11 @@ public FastTaxonomyFacetCounts(TaxonomyReader taxoReader, FacetsConfig config, F } /// - /// Create {@code FastTaxonomyFacetCounts}, using the - /// specified {@code indexFieldName} for ordinals. Use - /// this if you had set {@link - /// FacetsConfig#setIndexFieldName} to change the index - /// field name for certain dimensions. + /// Create , using the + /// specified for ordinals. Use + /// this if you had set + /// to change the index + /// field name for certain dimensions. /// public FastTaxonomyFacetCounts(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc) : base(indexFieldName, taxoReader, config) diff --git a/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs b/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs index 1b070a6e18..dbcf6159a4 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs @@ -24,18 +24,17 @@ namespace Lucene.Net.Facet.Taxonomy using Document = Lucene.Net.Documents.Document; /// - /// Add an instance of this to your to add - /// a facet label associated with a float. Use {@link - /// TaxonomyFacetSumFloatAssociations} to aggregate float values - /// per facet label at search time. + /// Add an instance of this to your to add + /// a facet label associated with a float. Use + /// to aggregate float values per facet label at search time. /// /// @lucene.experimental /// public class FloatAssociationFacetField : AssociationFacetField { /// - /// Creates this from {@code dim} and {@code path} and a - /// float association + /// Creates this from and and a + /// float association /// public FloatAssociationFacetField(float assoc, string dim, params string[] path) : base(FloatToBytesRef(assoc), dim, path) @@ -43,14 +42,16 @@ public FloatAssociationFacetField(float assoc, string dim, params string[] path) } /// - /// Encodes a {@code float} as a 4-byte . + /// Encodes a as a 4-byte . + /// public static BytesRef FloatToBytesRef(float v) { return IntAssociationFacetField.IntToBytesRef(Number.FloatToIntBits(v)); } /// - /// Decodes a previously encoded {@code float}. + /// Decodes a previously encoded . + /// public static float BytesRefToFloat(BytesRef b) { return Number.IntBitsToFloat(IntAssociationFacetField.BytesRefToInt(b)); diff --git a/src/Lucene.Net.Facet/Taxonomy/FloatTaxonomyFacets.cs b/src/Lucene.Net.Facet/Taxonomy/FloatTaxonomyFacets.cs index 27c8effd01..70dffb41ba 100644 --- a/src/Lucene.Net.Facet/Taxonomy/FloatTaxonomyFacets.cs +++ b/src/Lucene.Net.Facet/Taxonomy/FloatTaxonomyFacets.cs @@ -25,7 +25,7 @@ namespace Lucene.Net.Facet.Taxonomy /// /// Base class for all taxonomy-based facets that aggregate - /// to a per-ords float[]. + /// to a per-ords . /// public abstract class FloatTaxonomyFacets : TaxonomyFacets { @@ -34,7 +34,8 @@ public abstract class FloatTaxonomyFacets : TaxonomyFacets protected readonly float[] values; /// - /// Sole constructor. + /// Sole constructor. + /// protected internal FloatTaxonomyFacets(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config) : base(indexFieldName, taxoReader, config) { @@ -42,7 +43,8 @@ protected internal FloatTaxonomyFacets(string indexFieldName, TaxonomyReader tax } /// - /// Rolls up any single-valued hierarchical dimensions. + /// Rolls up any single-valued hierarchical dimensions. + /// protected virtual void Rollup() { // Rollup any necessary dims: diff --git a/src/Lucene.Net.Facet/Taxonomy/IntAssociationFacetField.cs b/src/Lucene.Net.Facet/Taxonomy/IntAssociationFacetField.cs index e7b56d7049..3cdf52830d 100644 --- a/src/Lucene.Net.Facet/Taxonomy/IntAssociationFacetField.cs +++ b/src/Lucene.Net.Facet/Taxonomy/IntAssociationFacetField.cs @@ -23,18 +23,17 @@ namespace Lucene.Net.Facet.Taxonomy using Document = Lucene.Net.Documents.Document; /// - /// Add an instance of this to your to add - /// a facet label associated with an int. Use {@link - /// TaxonomyFacetSumIntAssociations} to aggregate int values - /// per facet label at search time. + /// Add an instance of this to your to add + /// a facet label associated with an int. Use + /// to aggregate int values per facet label at search time. /// /// @lucene.experimental /// public class IntAssociationFacetField : AssociationFacetField { /// - /// Creates this from {@code dim} and {@code path} and an - /// int association + /// Creates this from and and an + /// int association /// public IntAssociationFacetField(int assoc, string dim, params string[] path) : base(IntToBytesRef(assoc), dim, path) @@ -42,8 +41,8 @@ public IntAssociationFacetField(int assoc, string dim, params string[] path) } /// - /// Encodes an {@code int} as a 4-byte , - /// big-endian. + /// Encodes an as a 4-byte , + /// big-endian. /// public static BytesRef IntToBytesRef(int v) { @@ -58,7 +57,8 @@ public static BytesRef IntToBytesRef(int v) } /// - /// Decodes a previously encoded {@code int}. + /// Decodes a previously encoded . + /// public static int BytesRefToInt(BytesRef b) { return ((b.Bytes[b.Offset] & 0xFF) << 24) | ((b.Bytes[b.Offset + 1] & 0xFF) << 16) | diff --git a/src/Lucene.Net.Facet/Taxonomy/IntTaxonomyFacets.cs b/src/Lucene.Net.Facet/Taxonomy/IntTaxonomyFacets.cs index 2c4e533a61..60b59c9ca5 100644 --- a/src/Lucene.Net.Facet/Taxonomy/IntTaxonomyFacets.cs +++ b/src/Lucene.Net.Facet/Taxonomy/IntTaxonomyFacets.cs @@ -24,7 +24,7 @@ namespace Lucene.Net.Facet.Taxonomy /// /// Base class for all taxonomy-based facets that aggregate - /// to a per-ords int[]. + /// to a per-ords . /// public abstract class IntTaxonomyFacets : TaxonomyFacets @@ -34,7 +34,8 @@ public abstract class IntTaxonomyFacets : TaxonomyFacets protected internal readonly int[] values; /// - /// Sole constructor. + /// Sole constructor. + /// protected internal IntTaxonomyFacets(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config) : base(indexFieldName, taxoReader, config) { @@ -42,7 +43,8 @@ protected internal IntTaxonomyFacets(string indexFieldName, TaxonomyReader taxoR } /// - /// Rolls up any single-valued hierarchical dimensions. + /// Rolls up any single-valued hierarchical dimensions. + /// protected virtual void Rollup() { // Rollup any necessary dims: diff --git a/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs b/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs index 059f834cb7..5ff77fb6ff 100644 --- a/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs +++ b/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs @@ -22,33 +22,17 @@ namespace Lucene.Net.Facet.Taxonomy */ /// - /// LRUHashMap is an extension of Java's HashMap, which has a bounded size(); - /// When it reaches that size, each time a new element is added, the least + /// is similar to of Java's HashMap, which has a bounded ; + /// When it reaches that , each time a new element is added, the least /// recently used (LRU) entry is removed. /// - /// Java makes it very easy to implement LRUHashMap - all its functionality is - /// already available from , and we just need to - /// configure that properly. + /// Unlike the Java Lucene implementation, this one is thread safe. Do note + /// that every time an element is read from , + /// a write operation also takes place to update the element's last access time. + /// This is because the LRU order needs to be remembered to determine which element + /// to evict when the is exceeded. /// /// - /// Note that like HashMap, LRUHashMap is unsynchronized, and the user MUST - /// synchronize the access to it if used from several threads. Moreover, while - /// with HashMap this is only a concern if one of the threads is modifies the - /// map, with LURHashMap every read is a modification (because the LRU order - /// needs to be remembered) so proper synchronization is always necessary. - /// - /// - /// With the usual synchronization mechanisms available to the user, this - /// unfortunately means that LRUHashMap will probably perform sub-optimally under - /// heavy contention: while one thread uses the hash table (reads or writes), any - /// other thread will be blocked from using it - or even just starting to use it - /// (e.g., calculating the hash function). A more efficient approach would be not - /// to use LinkedHashMap at all, but rather to use a non-locking (as much as - /// possible) thread-safe solution, something along the lines of - /// java.util.concurrent.ConcurrentHashMap (though that particular class does not - /// support the additional LRU semantics, which will need to be added separately - /// using a concurrent linked list or additional storage of timestamps (in an - /// array or inside the entry objects), or whatever). /// /// @lucene.experimental /// @@ -74,6 +58,17 @@ public LRUHashMap(int capacity) this.cache = new Dictionary(capacity); } + /// + /// allows changing the map's maximal number of elements + /// which was defined at construction time. + /// + /// Note that if the map is already larger than maxSize, the current + /// implementation does not shrink it (by removing the oldest elements); + /// Rather, the map remains in its current size as new elements are + /// added, and will only start shrinking (until settling again on the + /// given ) if existing elements are explicitly deleted. + /// + /// public virtual int Capacity { get { return capacity; } diff --git a/src/Lucene.Net.Facet/Taxonomy/OrdinalsReader.cs b/src/Lucene.Net.Facet/Taxonomy/OrdinalsReader.cs index c8e48432a0..3223b6acb8 100644 --- a/src/Lucene.Net.Facet/Taxonomy/OrdinalsReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/OrdinalsReader.cs @@ -23,16 +23,16 @@ /// /// Provides per-document ordinals. /// - public abstract class OrdinalsReader { /// - /// Returns ordinals for documents in one segment. + /// Returns ordinals for documents in one segment. + /// public abstract class OrdinalsSegmentReader { /// - /// Get the ordinals for this document. ordinals.offset - /// must always be 0! + /// Get the ordinals for this document. The . + /// must always be 0! /// public abstract void Get(int doc, IntsRef ordinals); @@ -57,8 +57,8 @@ public OrdinalsReader() public abstract OrdinalsSegmentReader GetReader(AtomicReaderContext context); /// - /// Returns the indexed field name this {@code - /// OrdinalsReader} is reading from. + /// Returns the indexed field name this + /// is reading from. /// public abstract string IndexFieldName { get; } } diff --git a/src/Lucene.Net.Facet/Taxonomy/ParallelTaxonomyArrays.cs b/src/Lucene.Net.Facet/Taxonomy/ParallelTaxonomyArrays.cs index 1b51568441..297c5c27c7 100644 --- a/src/Lucene.Net.Facet/Taxonomy/ParallelTaxonomyArrays.cs +++ b/src/Lucene.Net.Facet/Taxonomy/ParallelTaxonomyArrays.cs @@ -19,18 +19,18 @@ /// /// Returns 3 arrays for traversing the taxonomy: - ///
    - ///
  • {@code parents}: {@code parents[i]} denotes the parent of category - /// ordinal {@code i}.
  • - ///
  • {@code children}: {@code children[i]} denotes a child of category ordinal - /// {@code i}.
  • - ///
  • {@code siblings}: {@code siblings[i]} denotes the sibling of category - /// ordinal {@code i}.
  • - ///
+ /// + /// : Parents[i] denotes the parent of category + /// ordinal i. + /// : Children[i] denotes a child of category ordinal + /// i. + /// : Siblings[i] denotes the sibling of category + /// ordinal i. + /// /// - /// To traverse the taxonomy tree, you typically start with {@code children[0]} + /// To traverse the taxonomy tree, you typically start with Children[0] /// (ordinal 0 is reserved for ROOT), and then depends if you want to do DFS or - /// BFS, you call {@code children[children[0]]} or {@code siblings[children[0]]} + /// BFS, you call Children[Children[0]] or Siblings[Children[0]] /// and so forth, respectively. /// /// @@ -43,26 +43,27 @@ public abstract class ParallelTaxonomyArrays { /// - /// Sole constructor. + /// Sole constructor. + ///
public ParallelTaxonomyArrays() { } /// - /// Returns the parents array, where {@code parents[i]} denotes the parent of - /// category ordinal {@code i}. + /// Returns the parents array, where Parents[i] denotes the parent of + /// category ordinal i. /// public abstract int[] Parents { get; } /// - /// Returns the children array, where {@code children[i]} denotes a child of - /// category ordinal {@code i}. + /// Returns the children array, where Children[i] denotes a child of + /// category ordinal i. /// public abstract int[] Children { get; } /// - /// Returns the siblings array, where {@code siblings[i]} denotes the sibling - /// of category ordinal {@code i}. + /// Returns the siblings array, where Siblings[i] denotes the sibling + /// of category ordinal i. /// public abstract int[] Siblings { get; } } diff --git a/src/Lucene.Net.Facet/Taxonomy/PrintTaxonomyStats.cs b/src/Lucene.Net.Facet/Taxonomy/PrintTaxonomyStats.cs index 601e5d83a5..1f94b867ed 100644 --- a/src/Lucene.Net.Facet/Taxonomy/PrintTaxonomyStats.cs +++ b/src/Lucene.Net.Facet/Taxonomy/PrintTaxonomyStats.cs @@ -26,19 +26,22 @@ namespace Lucene.Net.Facet.Taxonomy using FSDirectory = Lucene.Net.Store.FSDirectory; /// - /// Prints how many ords are under each dimension. + /// Prints how many ords are under each dimension. + /// // java -cp ../build/core/classes/java:../build/facet/classes/java org.apache.lucene.facet.util.PrintTaxonomyStats -printTree /s2/scratch/indices/wikibig.trunk.noparents.facets.Lucene41.nd1M/facets public class PrintTaxonomyStats { /// - /// Sole constructor. + /// Sole constructor. + /// public PrintTaxonomyStats() { } /// - /// Command-line tool. + /// Command-line tool. + /// public static void Main(string[] args) { bool printTree = false; @@ -56,6 +59,7 @@ public static void Main(string[] args) } if (args.Length != (printTree ? 2 : 1)) { + // LUCENENET TODO: Usage depends on wrapping this into a console application assembly. Console.WriteLine("\nUsage: java -classpath ... org.apache.lucene.facet.util.PrintTaxonomyStats [-printTree] /path/to/taxononmy/index\n"); Environment.Exit(1); } diff --git a/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs b/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs index 2c8edb388c..8fb75d8cac 100644 --- a/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs +++ b/src/Lucene.Net.Facet/Taxonomy/SearcherTaxonomyManager.cs @@ -32,32 +32,35 @@ namespace Lucene.Net.Facet.Taxonomy using SearcherManager = Lucene.Net.Search.SearcherManager; /// - /// Manages near-real-time reopen of both an IndexSearcher - /// and a TaxonomyReader. + /// Manages near-real-time reopen of both an + /// and a . /// - /// NOTE: If you call {@link - /// DirectoryTaxonomyWriter#replaceTaxonomy} then you must - /// open a new {@code SearcherTaxonomyManager} afterwards. + /// + /// NOTE: If you call + /// then you must open a new afterwards. /// /// public class SearcherTaxonomyManager : ReferenceManager { /// - /// Holds a matched pair of and - /// + /// Holds a matched pair of and + /// /// public class SearcherAndTaxonomy { /// - /// Point-in-time . + /// Point-in-time . + /// public IndexSearcher Searcher { get; private set; } /// - /// Matching point-in-time . + /// Matching point-in-time . + /// public DirectoryTaxonomyReader TaxonomyReader { get; private set; } /// - /// Create a SearcherAndTaxonomy + /// Create a + /// public SearcherAndTaxonomy(IndexSearcher searcher, DirectoryTaxonomyReader taxonomyReader) { this.Searcher = searcher; @@ -71,7 +74,7 @@ public SearcherAndTaxonomy(IndexSearcher searcher, DirectoryTaxonomyReader taxon /// /// Creates near-real-time searcher and taxonomy reader - /// from the corresponding writers. + /// from the corresponding writers. /// public SearcherTaxonomyManager(IndexWriter writer, bool applyAllDeletes, SearcherFactory searcherFactory, DirectoryTaxonomyWriter taxoWriter) @@ -93,8 +96,8 @@ public SearcherTaxonomyManager(IndexWriter writer, bool applyAllDeletes, /// /// /// NOTE: you should only use this constructor if you commit and call - /// in the same thread. Otherwise it could lead to an - /// unsync'd and pair. + /// in the same thread. Otherwise it could lead to an + /// unsync'd and pair. /// /// public SearcherTaxonomyManager(Store.Directory indexDir, Store.Directory taxoDir, SearcherFactory searcherFactory) diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs index b86c924c0b..aa4acac0cd 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetCounts.cs @@ -25,9 +25,8 @@ namespace Lucene.Net.Facet.Taxonomy using MatchingDocs = FacetsCollector.MatchingDocs; /// - /// Reads from any ; use {@link - /// FastTaxonomyFacetCounts} if you are using the - /// default encoding from . + /// Reads from any ; use + /// if you are using the default encoding from . /// /// @lucene.experimental /// @@ -36,10 +35,9 @@ public class TaxonomyFacetCounts : IntTaxonomyFacets private readonly OrdinalsReader ordinalsReader; /// - /// Create {@code TaxonomyFacetCounts}, which also - /// counts all facet labels. Use this for a non-default - /// ; otherwise use {@link - /// FastTaxonomyFacetCounts}. + /// Create , which also + /// counts all facet labels. Use this for a non-default + /// ; otherwise use . /// public TaxonomyFacetCounts(OrdinalsReader ordinalsReader, TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc) : base(ordinalsReader.IndexFieldName, taxoReader, config) diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs index e30cef21a7..242466d002 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs @@ -27,16 +27,16 @@ namespace Lucene.Net.Facet.Taxonomy /// /// Aggregates sum of int values previously indexed with - /// , assuming the default - /// encoding. + /// , assuming the default + /// encoding. /// /// @lucene.experimental /// public class TaxonomyFacetSumFloatAssociations : FloatTaxonomyFacets { /// - /// Create {@code TaxonomyFacetSumFloatAssociations} against - /// the default index field. + /// Create against + /// the default index field. /// public TaxonomyFacetSumFloatAssociations(TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc) : this(FacetsConfig.DEFAULT_INDEX_FIELD_NAME, taxoReader, config, fc) @@ -44,8 +44,8 @@ public TaxonomyFacetSumFloatAssociations(TaxonomyReader taxoReader, FacetsConfig } /// - /// Create {@code TaxonomyFacetSumFloatAssociations} against - /// the specified index field. + /// Create against + /// the specified index field. /// public TaxonomyFacetSumFloatAssociations(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc) : base(indexFieldName, taxoReader, config) diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs index 7ff982b722..07b78b0efa 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs @@ -26,16 +26,16 @@ namespace Lucene.Net.Facet.Taxonomy /// /// Aggregates sum of int values previously indexed with - /// , assuming the default - /// encoding. + /// , assuming the default + /// encoding. /// /// @lucene.experimental /// public class TaxonomyFacetSumIntAssociations : IntTaxonomyFacets { /// - /// Create {@code TaxonomyFacetSumIntAssociations} against - /// the default index field. + /// Create against + /// the default index field. /// public TaxonomyFacetSumIntAssociations(TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc) : this(FacetsConfig.DEFAULT_INDEX_FIELD_NAME, taxoReader, config, fc) @@ -43,8 +43,8 @@ public TaxonomyFacetSumIntAssociations(TaxonomyReader taxoReader, FacetsConfig c } /// - /// Create {@code TaxonomyFacetSumIntAssociations} against - /// the specified index field. + /// Create against + /// the specified index field. /// public TaxonomyFacetSumIntAssociations(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc) : base(indexFieldName, taxoReader, config) diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs index ffe18dfdbd..c5e5cb5683 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs @@ -33,8 +33,8 @@ namespace Lucene.Net.Facet.Taxonomy using Weight = Lucene.Net.Search.Weight; /// - /// Aggregates sum of values from {@link - /// FunctionValues#doubleVal}, for each facet label. + /// Aggregates sum of values from , + /// for each facet label. /// /// @lucene.experimental /// @@ -44,10 +44,9 @@ public class TaxonomyFacetSumValueSource : FloatTaxonomyFacets /// /// Aggreggates float facet values from the provided - /// , pulling ordinals using {@link - /// DocValuesOrdinalsReader} against the default indexed - /// facet field {@link - /// FacetsConfig#DEFAULT_INDEX_FIELD_NAME}. + /// , pulling ordinals using + /// against the default indexed + /// facet field . /// public TaxonomyFacetSumValueSource(TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc, ValueSource valueSource) @@ -58,8 +57,8 @@ public TaxonomyFacetSumValueSource(TaxonomyReader taxoReader, FacetsConfig confi /// /// Aggreggates float facet values from the provided - /// , and pulls ordinals from the - /// provided . + /// , and pulls ordinals from the + /// provided . /// public TaxonomyFacetSumValueSource(OrdinalsReader ordinalsReader, TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc, ValueSource valueSource) @@ -158,15 +157,16 @@ private void SumValues(IList matchingDocs, bool keepScores, ValueS } /// - /// that returns the score for each - /// hit; use this to aggregate the sum of all hit scores - /// for each facet label. + /// that returns the score for each + /// hit; use this to aggregate the sum of all hit scores + /// for each facet label. /// public class ScoreValueSource : ValueSource { /// - /// Sole constructor. + /// Sole constructor. + /// public ScoreValueSource() { } diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs index ef8dedecf4..87ea6d09b7 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacets.cs @@ -25,7 +25,8 @@ namespace Lucene.Net.Facet.Taxonomy using DimConfig = Lucene.Net.Facet.FacetsConfig.DimConfig; // javadocs /// - /// Base class for all taxonomy-based facets impls. + /// Base class for all taxonomy-based facets impls. + /// public abstract class TaxonomyFacets : Facets { private static readonly IComparer BY_VALUE_THEN_DIM = new ComparatorAnonymousInnerClassHelper(); @@ -54,26 +55,29 @@ public virtual int Compare(FacetResult a, FacetResult b) } /// - /// Index field name provided to the constructor. + /// Index field name provided to the constructor. + /// protected readonly string indexFieldName; /// - /// {@code TaxonomyReader} provided to the constructor. + /// provided to the constructor. + /// protected readonly TaxonomyReader taxoReader; /// - /// {@code FacetsConfig} provided to the constructor. + /// provided to the constructor. + /// protected readonly FacetsConfig config; /// /// Maps parent ordinal to its child, or -1 if the parent - /// is childless. + /// is childless. /// protected readonly int[] children; /// /// Maps an ordinal to its sibling, or -1 if there is no - /// sibling. + /// sibling. /// protected readonly int[] siblings; @@ -91,9 +95,9 @@ protected internal TaxonomyFacets(string indexFieldName, TaxonomyReader taxoRead } /// - /// Throws {@code IllegalArgumentException} if the - /// dimension is not recognized. Otherwise, returns the - /// for this dimension. + /// Throws if the + /// dimension is not recognized. Otherwise, returns the + /// for this dimension. /// protected internal virtual DimConfig VerifyDim(string dim) { diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs index db56dc222d..4cf132d268 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs @@ -28,32 +28,37 @@ namespace Lucene.Net.Facet.Taxonomy /// /// TaxonomyReader is the read-only interface with which the faceted-search /// library uses the taxonomy during search time. - ///

+ /// /// A TaxonomyReader holds a list of categories. Each category has a serial /// number which we call an "ordinal", and a hierarchical "path" name: - ///

    - ///
  • + /// + /// /// The ordinal is an integer that starts at 0 for the first category (which is /// always the root category), and grows contiguously as more categories are /// added; Note that once a category is added, it can never be deleted. - ///
  • + /// + /// /// The path is a CategoryPath object specifying the category's position in the /// hierarchy. - ///
- /// Notes about concurrent access to the taxonomy: - ///

+ /// + /// + /// + /// Notes about concurrent access to the taxonomy: + /// /// An implementation must allow multiple readers to be active concurrently /// with a single writer. Readers follow so-called "point in time" semantics, /// i.e., a TaxonomyReader object will only see taxonomy entries which were /// available at the time it was created. What the writer writes is only - /// available to (new) readers after the writer's commit() is called. - ///

+ /// available to (new) readers after the writer's is called. + /// + /// /// In faceted search, two separate indices are used: the main Lucene index, /// and the taxonomy. Because the main index refers to the categories listed /// in the taxonomy, it is important to open the taxonomy *after* opening the - /// main index, and it is also necessary to reopen() the taxonomy after - /// reopen()ing the main index. - ///

+ /// main index, and it is also necessary to Reopen() the taxonomy after + /// Reopen()ing the main index. + /// + /// /// This order is important, otherwise it would be possible for the main index /// to refer to a category which is not yet visible in the old snapshot of /// the taxonomy. Note that it is indeed fine for the the taxonomy to be opened @@ -61,13 +66,15 @@ namespace Lucene.Net.Facet.Taxonomy /// a category is added to the taxonomy, it can never be changed or deleted, /// so there is no danger that a "too new" taxonomy not being consistent with /// an older index. + /// /// /// @lucene.experimental ///

public abstract class TaxonomyReader { /// - /// An iterator over a category's children. + /// An iterator over a category's children. + /// public class ChildrenIterator { private readonly int[] siblings; @@ -80,7 +87,7 @@ internal ChildrenIterator(int child, int[] siblings) } /// - /// Return the next child ordinal, or + /// Return the next child ordinal, or /// if no more children. /// public virtual int Next() @@ -95,35 +102,36 @@ public virtual int Next() } /// - /// Sole constructor. + /// Sole constructor. + /// public TaxonomyReader() { } /// /// The root category (the category with the empty path) always has the ordinal - /// 0, to which we give a name ROOT_ORDINAL. - /// of an empty path will always return {@code ROOT_ORDINAL}, and - /// with {@code ROOT_ORDINAL} will return the empty path. + /// 0, to which we give a name ROOT_ORDINAL. + /// of an empty path will always return , and + /// with will return the empty path. /// public const int ROOT_ORDINAL = 0; /// /// Ordinals are always non-negative, so a negative ordinal can be used to - /// signify an error. Methods here return INVALID_ORDINAL (-1) in this case. + /// signify an error. Methods here return (-1) in this case. /// public const int INVALID_ORDINAL = -1; /// /// If the taxonomy has changed since the provided reader was opened, open and - /// return a new ; else, return {@code null}. The new - /// reader, if not {@code null}, will be the same type of reader as the one + /// return a new ; else, return null. The new + /// reader, if not null, will be the same type of reader as the one /// given to this method. /// /// /// This method is typically far less costly than opening a fully new - /// as it shares resources with the provided - /// , when possible. + /// as it shares resources with the provided + /// , when possible. /// /// public static T OpenIfChanged(T oldTaxoReader) where T : TaxonomyReader @@ -145,14 +153,14 @@ public static T OpenIfChanged(T oldTaxoReader) where T : TaxonomyReader protected internal abstract void DoClose(); /// - /// Implements the actual opening of a new instance if + /// Implements the actual opening of a new instance if /// the taxonomy has changed. /// - /// + /// protected abstract TaxonomyReader DoOpenIfChanged(); /// - /// Throws if this IndexReader is closed + /// Throws if this is disposed /// protected void EnsureOpen() { @@ -211,13 +219,14 @@ public void DecRef() } /// - /// Returns a object which can be used to + /// Returns a object which can be used to /// efficiently traverse the taxonomy tree. /// public abstract ParallelTaxonomyArrays ParallelTaxonomyArrays { get; } /// - /// Returns an iterator over the children of the given ordinal. + /// Returns an iterator over the children of the given ordinal. + /// public virtual ChildrenIterator GetChildren(int ordinal) { ParallelTaxonomyArrays arrays = ParallelTaxonomyArrays; @@ -228,7 +237,7 @@ public virtual ChildrenIterator GetChildren(int ordinal) /// /// Retrieve user committed data. /// - /// + /// public abstract IDictionary CommitUserData { get; } /// @@ -237,12 +246,13 @@ public virtual ChildrenIterator GetChildren(int ordinal) /// categories are added (note that once a category is added, it can never be /// deleted). /// - /// the category's ordinal or if the category - /// wasn't foun. + /// the category's ordinal or if the category + /// wasn't found. public abstract int GetOrdinal(FacetLabel categoryPath); /// - /// Returns ordinal for the dim + path. + /// Returns ordinal for the dim + path. + /// public virtual int GetOrdinal(string dim, string[] path) { string[] fullPath = new string[path.Length + 1]; @@ -252,11 +262,13 @@ public virtual int GetOrdinal(string dim, string[] path) } /// - /// Returns the path name of the category with the given ordinal. + /// Returns the path name of the category with the given ordinal. + /// public abstract FacetLabel GetPath(int ordinal); /// - /// Returns the current refCount for this taxonomy reader. + /// Returns the current refCount for this taxonomy reader. + /// public int RefCount { get @@ -278,8 +290,8 @@ public int RefCount /// Expert: increments the refCount of this TaxonomyReader instance. RefCounts /// can be used to determine when a taxonomy reader can be closed safely, i.e. /// as soon as there are no more references. Be sure to always call a - /// corresponding decRef(), in a finally clause; otherwise the reader may never - /// be closed. + /// corresponding , in a finally clause; otherwise the reader may never + /// be disposed. /// public void IncRef() { @@ -289,8 +301,8 @@ public void IncRef() /// /// Expert: increments the refCount of this TaxonomyReader - /// instance only if it has not been closed yet. Returns - /// true on success. + /// instance only if it has not been closed yet. Returns + /// true on success. /// public bool TryIncRef() { diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyWriter.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyWriter.cs index fdec22f2b9..94f62a1b69 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyWriter.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyWriter.cs @@ -23,17 +23,19 @@ namespace Lucene.Net.Facet.Taxonomy using TwoPhaseCommit = Lucene.Net.Index.TwoPhaseCommit; /// - /// ITaxonomyWriter is the interface which the faceted-search library uses + /// is the interface which the faceted-search library uses /// to dynamically build the taxonomy at indexing time. - ///

+ /// /// Notes about concurrent access to the taxonomy: - ///

+ /// + /// /// An implementation must allow multiple readers and a single writer to be /// active concurrently. Readers follow so-called "point in time" semantics, /// i.e., a reader object will only see taxonomy entries which were available /// at the time it was created. What the writer writes is only available to - /// (new) readers after the writer's commit() is called. - ///

+ /// (new) readers after the writer's is called. + /// + /// /// Faceted search keeps two indices - namely Lucene's main index, and this /// taxonomy index. When one or more readers are active concurrently with the /// writer, care must be taken to avoid an inconsistency between the state of @@ -41,24 +43,25 @@ namespace Lucene.Net.Facet.Taxonomy /// be committed to disk *before* the main index, because the main index /// refers to categories listed in the taxonomy. /// Such control can best be achieved by turning off the main index's - /// "autocommit" feature, and explicitly calling commit() for both indices + /// "autocommit" feature, and explicitly calling for both indices /// (first for the taxonomy, then for the main index). /// In old versions of Lucene (2.2 or earlier), when autocommit could not be /// turned off, a more complicated solution needs to be used. E.g., use /// some sort of (possibly inter-process) locking to ensure that a reader /// is being opened only right after both indices have been flushed (and /// before anything else is written to them). + /// /// /// @lucene.experimental ///

public interface ITaxonomyWriter : IDisposable, TwoPhaseCommit { /// - /// addCategory() adds a category with a given path name to the taxonomy, + /// adds a category with a given path name to the taxonomy, /// and returns its ordinal. If the category was already present in /// the taxonomy, its existing ordinal is returned. ///

- /// Before adding a category, addCategory() makes sure that all its + /// Before adding a category, makes sure that all its /// ancestor categories exist in the taxonomy as well. As result, the /// ordinal of a category is guaranteed to be smaller then the ordinal of /// any of its descendants. @@ -66,37 +69,42 @@ public interface ITaxonomyWriter : IDisposable, TwoPhaseCommit int AddCategory(FacetLabel categoryPath); ///

- /// getParent() returns the ordinal of the parent category of the category + /// returns the ordinal of the parent category of the category /// with the given ordinal. - ///

+ /// /// When a category is specified as a path name, finding the path of its /// parent is as trivial as dropping the last component of the path. - /// getParent() is functionally equivalent to calling getPath() on the + /// is functionally equivalent to calling on the /// given ordinal, dropping the last component of the path, and then calling - /// getOrdinal() to get an ordinal back. - ///

- /// If the given ordinal is the ROOT_ORDINAL, an INVALID_ORDINAL is returned. - /// If the given ordinal is a top-level category, the ROOT_ORDINAL is returned. + /// to get an ordinal back. + /// + /// + /// If the given ordinal is the , an + /// is returned. + /// If the given ordinal is a top-level category, the + /// is returned. /// If an invalid ordinal is given (negative or beyond the last available - /// ordinal), an ArrayIndexOutOfBoundsException is thrown. However, it is - /// expected that getParent will only be called for ordinals which are + /// ordinal), an is thrown. However, it is + /// expected that will only be called for ordinals which are /// already known to be in the taxonomy. - /// TODO (Facet): instead of a getParent(ordinal) method, consider having a - ///

- /// getCategory(categorypath, prefixlen) which is similar to addCategory + /// + /// + /// TODO (Facet): instead of a GetParent(ordinal) method, consider having a + /// GetCategory(categorypath, prefixlen) which is similar to /// except it doesn't add new categories; This method can be used to get /// the ordinals of all prefixes of the given category, and it can use - /// exactly the same code and cache used by addCategory() so it means less code. + /// exactly the same code and cache used by so it means less code. + /// ///

int GetParent(int ordinal); /// - /// getSize() returns the number of categories in the taxonomy. + /// returns the number of categories in the taxonomy. ///

/// Because categories are numbered consecutively starting with 0, it - /// means the taxonomy contains ordinals 0 through getSize()-1. + /// means the taxonomy contains ordinals 0 through -1. ///

- /// Note that the number returned by getSize() is often slightly higher + /// Note that the number returned by is often slightly higher /// than the number of categories inserted into the taxonomy; This is /// because when a category is added to the taxonomy, its ancestors /// are also added automatically (including the root, which always get @@ -106,7 +114,7 @@ public interface ITaxonomyWriter : IDisposable, TwoPhaseCommit ///

/// Sets the commit user data map. That method is considered a transaction and - /// will be even if no other changes were made to + /// will be committed even if no other changes were made to /// the writer instance. /// /// NOTE: the map is cloned internally, therefore altering the map's diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CategoryPathUtils.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CategoryPathUtils.cs index 800fda0653..c2714c64ac 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CategoryPathUtils.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CategoryPathUtils.cs @@ -20,11 +20,13 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache */ /// - /// Utilities for use of by . + /// Utilities for use of by . + /// internal class CategoryPathUtils { /// - /// Serializes the given to the . + /// Serializes the given to the . + ///
public static void Serialize(FacetLabel cp, CharBlockArray charBlockArray) { charBlockArray.Append((char)cp.Length); @@ -41,7 +43,7 @@ public static void Serialize(FacetLabel cp, CharBlockArray charBlockArray) /// /// Calculates a hash function of a path that was serialized with - /// . + /// . /// public static int HashCodeOfSerialized(CharBlockArray charBlockArray, int offset) { @@ -62,8 +64,8 @@ public static int HashCodeOfSerialized(CharBlockArray charBlockArray, int offset } /// - /// Check whether the is equal to the one serialized in - /// . + /// Check whether the is equal to the one serialized in + /// . /// public static bool EqualsToSerialized(FacetLabel cp, CharBlockArray charBlockArray, int offset) { diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs index 60a0726417..a461da2ac5 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CharBlockArray.cs @@ -24,7 +24,7 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache */ /// - /// Similar to , but with a more efficient growing strategy. + /// Similar to , but with a more efficient growing strategy. /// This class uses char array blocks to grow. /// /// @lucene.experimental diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs index 6cbff1f761..a6f6ff8903 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs @@ -20,9 +20,9 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache */ /// - /// using . Although + /// using . Although /// called cache, it maintains in memory all the mappings from category to - /// ordinal, relying on that is an efficient + /// ordinal, relying on that is an efficient /// mapping for this purpose. /// /// @lucene.experimental @@ -37,7 +37,8 @@ public class Cl2oTaxonomyWriterCache : ITaxonomyWriterCache private volatile CompactLabelToOrdinal cache; /// - /// Sole constructor. + /// Sole constructor. + /// public Cl2oTaxonomyWriterCache(int initialCapcity, float loadFactor, int numHashArrays) { this.cache = new CompactLabelToOrdinal(initialCapcity, loadFactor, numHashArrays); @@ -106,7 +107,8 @@ public virtual bool Put(FacetLabel categoryPath, int ordinal) } /// - /// Returns the number of bytes in memory used by this object. + /// Returns the number of bytes in memory used by this object. + /// public virtual int GetMemoryUsage() { return cache == null ? 0 : cache.GetMemoryUsage(); diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs index b199513d8c..a03f1bb2dc 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs @@ -22,7 +22,7 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache */ /// - /// HashMap to store colliding labels. See for + /// HashMap to store colliding labels. See for /// details. /// /// @lucene.experimental @@ -75,7 +75,8 @@ private CollisionMap(int initialCapacity, float loadFactor, CharBlockArray label } /// - /// How many mappings. + /// How many mappings. + /// public virtual int Count { get @@ -125,9 +126,8 @@ private void Grow() } /// - /// Return the mapping, or {@link - /// LabelToOrdinal#INVALID_ORDINAL} if the label isn't - /// recognized. + /// Return the mapping, or + /// if the label isn't recognized. /// public virtual int Get(FacetLabel label, int hash) { diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs index 35d3ee5bb8..da3a8fc976 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CompactLabelToOrdinal.cs @@ -22,21 +22,21 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache */ /// - /// This is a very efficient LabelToOrdinal implementation that uses a - /// CharBlockArray to store all labels and a configurable number of HashArrays to + /// This is a very efficient implementation that uses a + /// to store all labels and a configurable number of s to /// reference the labels. /// - /// Since the HashArrays don't handle collisions, a is used + /// Since the s don't handle collisions, a is used /// to store the colliding labels. /// /// /// This data structure grows by adding a new HashArray whenever the number of - /// collisions in the exceeds {@code loadFactor} * - /// . Growing also includes reinserting all colliding - /// labels into the HashArrays to possibly reduce the number of collisions. + /// collisions in the exceeds * + /// . Growing also includes reinserting all colliding + /// labels into the s to possibly reduce the number of collisions. /// - /// For setting the {@code loadFactor} see - /// . + /// For setting the see + /// . /// /// /// @@ -66,7 +66,8 @@ public class CompactLabelToOrdinal : LabelToOrdinal private float loadFactor; /// - /// How many labels. + /// How many labels. + /// public virtual int SizeOfMap { get @@ -80,7 +81,8 @@ private CompactLabelToOrdinal() } /// - /// Sole constructor. + /// Sole constructor. + ///
public CompactLabelToOrdinal(int initialCapacity, float loadFactor, int numHashArrays) { this.hashArrays = new HashArray[numHashArrays]; @@ -293,7 +295,8 @@ private int GetOrdinal(HashArray a, FacetLabel label, int hash) } /// - /// Returns index for hash code h. + /// Returns index for hash code h. + /// internal static int IndexFor(int h, int length) { return h & (length - 1); @@ -389,7 +392,7 @@ internal virtual int GetMemoryUsage() /// /// Opens the file and reloads the CompactLabelToOrdinal. The file it expects - /// is generated from the command. + /// is generated from the command. /// internal static CompactLabelToOrdinal Open(FileInfo file, float loadFactor, int numHashArrays) { diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LabelToOrdinal.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LabelToOrdinal.cs index c9b36d6493..bcb53adec0 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LabelToOrdinal.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LabelToOrdinal.cs @@ -29,13 +29,14 @@ public abstract class LabelToOrdinal protected internal int counter; /// - /// Returned by when the label isn't - /// recognized. + /// Returned by when the label isn't + /// recognized. /// public const int INVALID_ORDINAL = -2; /// - /// Default constructor. + /// Default constructor. + /// public LabelToOrdinal() { } @@ -62,14 +63,14 @@ public virtual int GetNextOrdinal() /// /// Adds a new label if its not yet in the table. - /// Throws an if the same label with + /// Throws an if the same label with /// a different ordinal was previoulsy added to this table. /// public abstract void AddLabel(FacetLabel label, int ordinal); /// /// Returns the ordinal assigned to the given label, - /// or if the label cannot be found in this table. + /// or if the label cannot be found in this table. /// public abstract int GetOrdinal(FacetLabel label); } diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs index 7152094bb3..3f6c4dce5d 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs @@ -18,7 +18,7 @@ */ /// - /// LRU - good choice for huge taxonomies. + /// LRU - good choice for huge taxonomies. /// /// @lucene.experimental /// @@ -47,7 +47,8 @@ public enum LRUType private NameIntCacheLRU cache; /// - /// Creates this with method. + /// Creates this with method. + /// public LruTaxonomyWriterCache(int cacheSize) : this(cacheSize, LRUType.LRU_HASHED) { @@ -60,7 +61,8 @@ public LruTaxonomyWriterCache(int cacheSize) } /// - /// Creates this with the specified method. + /// Creates this with the specified method. + /// public LruTaxonomyWriterCache(int cacheSize, LRUType lruType) { // TODO (Facet): choose between NameHashIntCacheLRU and NameIntCacheLRU. diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs index ca0011a7f0..b7264a092f 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs @@ -26,8 +26,10 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache /// /// @lucene.experimental /// - // Note: Nothing in this class is synchronized. The caller is assumed to be - // synchronized so that no two methods of this class are called concurrently. + /// + /// Note: Nothing in this class is synchronized. The caller is assumed to be + /// synchronized so that no two methods of this class are called concurrently. + /// public class NameIntCacheLRU { private Dictionary cache; @@ -42,7 +44,8 @@ internal NameIntCacheLRU(int capacity) } /// - /// Maximum number of cache entries before eviction. + /// Maximum number of cache entries before eviction. + /// public virtual int Capacity { get @@ -52,7 +55,8 @@ public virtual int Capacity } /// - /// Number of entries currently in the cache. + /// Number of entries currently in the cache. + /// public virtual int Count { get @@ -91,7 +95,8 @@ private void CreateCache(int maxSize) } /// - /// Subclasses can override this to provide caching by e.g. hash of the string. + /// Subclasses can override this to provide caching by e.g. hash of the string. + /// internal virtual object Key(FacetLabel name) { return name; @@ -140,7 +145,7 @@ internal virtual string Stats() /// If cache is full remove least recently used entries from cache. Return true /// if anything was removed, false otherwise. /// - /// See comment in DirectoryTaxonomyWriter.addToCache(CategoryPath, int) for an + /// See comment in for an /// explanation why we clean 2/3rds of the cache, and not just one entry. /// internal virtual bool MakeRoomLRU() diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs index 1dc4d64bcd..bb2eec8ec5 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs @@ -22,22 +22,22 @@ /// /// ITaxonomyWriterCache is a relatively simple interface for a cache of /// category->ordinal mappings, used in ITaxonomyWriter implementations (such as - /// ). + /// ). /// - /// It basically has put() methods for adding a mapping, and get() for looking a - /// mapping up the cache. The cache does not guarantee to hold everything + /// It basically has methods for adding a mapping, and for looking a + /// mapping up the cache. The cache does not guarantee to hold everything /// that has been put into it, and might in fact selectively delete some of the - /// mappings (e.g., the ones least recently used). This means that if get() + /// mappings (e.g., the ones least recently used). This means that if /// returns a negative response, it does not necessarily mean that the category /// doesn't exist - just that it is not in the cache. The caller can only infer /// that the category doesn't exist if it knows the cache to be complete (because - /// all the categories were loaded into the cache, and since then no put() + /// all the categories were loaded into the cache, and since then no /// returned true). /// /// /// However, if it does so, it should clear out large parts of the cache at once, /// because the user will typically need to work hard to recover from every cache - /// cleanup (see 's return value). + /// cleanup (see 's return value). /// /// /// NOTE: the cache may be accessed concurrently by multiple threads, @@ -49,7 +49,7 @@ public interface ITaxonomyWriterCache { /// - /// Let go of whatever resources the cache is holding. After a close(), + /// Let go of whatever resources the cache is holding. After a , /// this object can no longer be used. /// void Close(); @@ -57,43 +57,47 @@ public interface ITaxonomyWriterCache /// /// Lookup a category in the cache, returning its ordinal, or a negative /// number if the category is not in the cache. - ///

+ /// /// It is up to the caller to remember what a negative response means: - /// If the caller knows the cache is complete (it was initially - /// fed with all the categories, and since then put() never returned true) + /// If the caller knows the cache is complete (it was initially + /// fed with all the categories, and since then never returned true) /// it means the category does not exist. Otherwise, the category might /// still exist, but just be missing from the cache. + /// ///

int Get(FacetLabel categoryPath); /// /// Add a category to the cache, with the given ordinal as the value. - ///

+ /// /// If the implementation keeps only a partial cache (e.g., an LRU cache) /// and finds that its cache is full, it should clear up part of the cache - /// and return true. Otherwise, it should return - /// false. - ///

+ /// and return true. Otherwise, it should return + /// false. + /// + /// /// The reason why the caller needs to know if part of the cache was /// cleared is that in that case it will have to commit its on-disk index /// (so that all the latest category additions can be searched on disk, if /// we can't rely on the cache to contain them). - ///

+ /// + /// /// Ordinals should be non-negative. Currently there is no defined way to /// specify that a cache should remember a category does NOT exist. /// It doesn't really matter, because normally the next thing we do after /// finding that a category does not exist is to add it. + /// ///

bool Put(FacetLabel categoryPath, int ordinal); /// - /// Returns true if the cache is full, such that the next will + /// Returns true if the cache is full, such that the next will /// evict entries from it, false otherwise. /// bool IsFull { get; } /// - /// Clears the content of the cache. Unlike , the caller can + /// Clears the content of the cache. Unlike , the caller can /// assume that the cache is still operable after this method returns. /// void Clear(); diff --git a/src/Lucene.Net.Facet/TopOrdAndFloatQueue.cs b/src/Lucene.Net.Facet/TopOrdAndFloatQueue.cs index 9c81f3103b..756bd94dcc 100644 --- a/src/Lucene.Net.Facet/TopOrdAndFloatQueue.cs +++ b/src/Lucene.Net.Facet/TopOrdAndFloatQueue.cs @@ -21,12 +21,13 @@ namespace Lucene.Net.Facet /// /// Keeps highest results, first by largest float value, - /// then tie break by smallest ord. + /// then tie break by smallest ord. /// public class TopOrdAndFloatQueue : PriorityQueue { /// - /// Holds a single entry. + /// Holds a single entry. + ///
public sealed class OrdAndValue { /// @@ -38,14 +39,16 @@ public sealed class OrdAndValue public float Value { get; set; } /// - /// Default constructor. + /// Default constructor. + /// public OrdAndValue() { } } /// - /// Sole constructor. + /// Sole constructor. + /// public TopOrdAndFloatQueue(int topN) : base(topN, false) { } diff --git a/src/Lucene.Net.Facet/TopOrdAndIntQueue.cs b/src/Lucene.Net.Facet/TopOrdAndIntQueue.cs index 7016e806e8..d9fbbfe069 100644 --- a/src/Lucene.Net.Facet/TopOrdAndIntQueue.cs +++ b/src/Lucene.Net.Facet/TopOrdAndIntQueue.cs @@ -21,12 +21,13 @@ namespace Lucene.Net.Facet /// /// Keeps highest results, first by largest int value, - /// then tie break by smallest ord. + /// then tie break by smallest ord. /// public class TopOrdAndIntQueue : PriorityQueue { /// - /// Holds a single entry. + /// Holds a single entry. + /// public sealed class OrdAndValue { /// @@ -38,14 +39,16 @@ public sealed class OrdAndValue public int Value { get; set; } /// - /// Default constructor. + /// Default constructor. + /// public OrdAndValue() { } } /// - /// Sole constructor. + /// Sole constructor. + /// public TopOrdAndIntQueue(int topN) : base(topN, false) { From 49e25039131cb5b2d577e38d60094690f5321155 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 23:47:13 +0700 Subject: [PATCH 38/41] Changed Close() to IDisposable.Dispose() in Facet.Taxonomy.WriterCache.ITaxonomyWriterCache. --- .../Directory/DirectoryTaxonomyWriter.cs | 2 +- .../WriterCache/Cl2oTaxonomyWriterCache.cs | 2 +- .../WriterCache/LruTaxonomyWriterCache.cs | 9 ++-- .../WriterCache/TaxonomyWriterCache.cs | 43 ++++++++----------- .../TestConcurrentFacetedIndexing.cs | 2 +- .../Directory/TestDirectoryTaxonomyWriter.cs | 2 +- 6 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs index f59337e630..7ecfe94d6f 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs @@ -381,7 +381,7 @@ protected virtual void CloseResources() } if (cache != null) { - cache.Close(); + cache.Dispose(); } } } diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs index a6f6ff8903..6d26448802 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/Cl2oTaxonomyWriterCache.cs @@ -60,7 +60,7 @@ public virtual void Clear() } } - public virtual void Close() + public virtual void Dispose() { lock (this) { diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs index 3f6c4dce5d..abad1ea6ed 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs @@ -100,12 +100,15 @@ public virtual void Clear() } } - public virtual void Close() + public virtual void Dispose() { lock (this) { - cache.Clear(); - cache = null; + if (cache != null) + { + cache.Clear(); + cache = null; + } } } diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs index bb2eec8ec5..127e752fcb 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/TaxonomyWriterCache.cs @@ -1,26 +1,27 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache { + using System; /* - * 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 DirectoryTaxonomyWriter = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter; /// - /// ITaxonomyWriterCache is a relatively simple interface for a cache of + /// is a relatively simple interface for a cache of /// category->ordinal mappings, used in ITaxonomyWriter implementations (such as /// ). /// @@ -46,14 +47,8 @@ /// @lucene.experimental /// /// - public interface ITaxonomyWriterCache + public interface ITaxonomyWriterCache : IDisposable { - /// - /// Let go of whatever resources the cache is holding. After a , - /// this object can no longer be used. - /// - void Close(); - /// /// Lookup a category in the cache, returning its ordinal, or a negative /// number if the category is not in the cache. @@ -97,7 +92,7 @@ public interface ITaxonomyWriterCache bool IsFull { get; } /// - /// Clears the content of the cache. Unlike , the caller can + /// Clears the content of the cache. Unlike , the caller can /// assume that the cache is still operable after this method returns. /// void Clear(); diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs index abd82f8a8a..30de593147 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs @@ -49,7 +49,7 @@ public TaxonomyWriterCacheAnonymousInnerClassHelper() } - public virtual void Close() + public virtual void Dispose() { } public virtual int Get(FacetLabel categoryPath) diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs index 4e6dd8566d..ef6db80e2d 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs @@ -54,7 +54,7 @@ public class TestDirectoryTaxonomyWriter : FacetTestCase private class TaxonomyWriterCacheAnonymousInnerClassHelper : ITaxonomyWriterCache { - public virtual void Close() + public virtual void Dispose() { } public virtual int Get(FacetLabel categoryPath) From d86688897061bc280a730fe2235a5cb398298ee6 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 25 Sep 2016 23:55:42 +0700 Subject: [PATCH 39/41] Fixed "identityHashCode" call in Facet.Taxonomy.TaxonomyFacetSumValueSource. --- src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs index c5e5cb5683..a08021cee1 100644 --- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs +++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumValueSource.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; using System.Threading; namespace Lucene.Net.Facet.Taxonomy @@ -222,11 +223,9 @@ protected bool Equals(ScoreValueSource other) public override int GetHashCode() { - return hcode; + return RuntimeHelpers.GetHashCode(this); } - private static readonly int hcode = typeof(DoubleDocValuesAnonymousInnerClassHelper).GetHashCode(); - public override string Description { get From 36cde0630890082c3dd23fd54820de9a87be1bc3 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Mon, 26 Sep 2016 01:36:34 +0700 Subject: [PATCH 40/41] Added CSharpTest.Net.Collections.LurchTable to our Support namespace and modified the DirectoryTaxonomyReader and NameIntCacheLRU to utilize it. --- src/Lucene.Net.Core/Lucene.Net.csproj | 1 + src/Lucene.Net.Core/Support/LurchTable.cs | 1670 +++++++++++++++++ .../Directory/DirectoryTaxonomyReader.cs | 64 +- src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs | 202 +- .../WriterCache/LruTaxonomyWriterCache.cs | 8 +- .../Taxonomy/WriterCache/NameIntCacheLRU.cs | 60 +- .../Taxonomy/TestLRUHashMap.cs | 6 + 7 files changed, 1859 insertions(+), 152 deletions(-) create mode 100644 src/Lucene.Net.Core/Support/LurchTable.cs diff --git a/src/Lucene.Net.Core/Lucene.Net.csproj b/src/Lucene.Net.Core/Lucene.Net.csproj index e06e7049e2..f9a3e28394 100644 --- a/src/Lucene.Net.Core/Lucene.Net.csproj +++ b/src/Lucene.Net.Core/Lucene.Net.csproj @@ -637,6 +637,7 @@ + diff --git a/src/Lucene.Net.Core/Support/LurchTable.cs b/src/Lucene.Net.Core/Support/LurchTable.cs new file mode 100644 index 0000000000..dcb8ca6891 --- /dev/null +++ b/src/Lucene.Net.Core/Support/LurchTable.cs @@ -0,0 +1,1670 @@ +#region Copyright 2012-2014 by Roger Knapp, Licensed under the Apache License, Version 2.0 +/* Licensed 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. + */ + + // 2016-10-03: Modified from the original version by Shad Storhaug to + // allow read-write access to the Limit property +#endregion +using System; +using System.Collections; +using System.Collections.Generic; +using System.Threading; + +namespace Lucene.Net.Support +{ + /// + /// Defines if and how items added to a LurchTable are linked together, this defines + /// the value returned from Peek/Dequeue as the oldest entry of the specified operation. + /// + public enum LurchTableOrder + { + /// No linking + None, + /// Linked in insertion order + Insertion, + /// Linked by most recently inserted or updated + Modified, + /// Linked by most recently inserted, updated, or fetched + Access, + } + + /// + /// LurchTable stands for "Least Used Recently Concurrent Hash Table" and has definate + /// similarities to both the .NET 4 ConcurrentDictionary as well as Java's LinkedHashMap. + /// This gives you a thread-safe dictionary/hashtable that stores element ordering by + /// insertion, updates, or access. In addition it can be configured to use a 'hard-limit' + /// count of items that will automatically 'pop' the oldest item in the collection. + /// + /// The type of keys in the dictionary. + /// The type of values in the dictionary. + public class LurchTable : IDictionary + { + /// Method signature for the ItemUpdated event + public delegate void ItemUpdatedMethod(KeyValuePair previous, KeyValuePair next); + + /// Event raised after an item is removed from the collection + public event Action> ItemRemoved; + /// Event raised after an item is updated in the collection + public event ItemUpdatedMethod ItemUpdated; + /// Event raised after an item is added to the collection + public event Action> ItemAdded; + + private const int OverAlloc = 128; + private const int FreeSlots = 32; + + private readonly IEqualityComparer _comparer; + private readonly int _hsize, _lsize; + private int _limit; // LUCENENET: Changed to read-write + private readonly int _allocSize, _shift, _shiftMask; + private readonly LurchTableOrder _ordering; + private readonly object[] _locks; + private readonly int[] _buckets; + private readonly FreeList[] _free; + + private Entry[][] _entries; + private int _used, _count; + private int _allocNext, _freeVersion; + + /// Creates a LurchTable that can store up to (capacity) items efficiently. + public LurchTable(int capacity) + : this(LurchTableOrder.None, int.MaxValue, capacity >> 1, capacity >> 4, capacity >> 8, EqualityComparer.Default) { } + + /// Creates a LurchTable that can store up to (capacity) items efficiently. + public LurchTable(int capacity, LurchTableOrder ordering) + : this(ordering, int.MaxValue, capacity >> 1, capacity >> 4, capacity >> 8, EqualityComparer.Default) { } + + /// Creates a LurchTable that can store up to (capacity) items efficiently. + public LurchTable(int capacity, LurchTableOrder ordering, IEqualityComparer comparer) + : this(ordering, int.MaxValue, capacity >> 1, capacity >> 4, capacity >> 8, comparer) { } + + /// Creates a LurchTable that orders items by (ordering) and removes items once the specified (limit) is reached. + public LurchTable(LurchTableOrder ordering, int limit) + : this(ordering, limit, limit >> 1, limit >> 4, limit >> 8, EqualityComparer.Default) { } + + /// Creates a LurchTable that orders items by (ordering) and removes items once the specified (limit) is reached. + public LurchTable(LurchTableOrder ordering, int limit, IEqualityComparer comparer) + : this(ordering, limit, limit >> 1, limit >> 4, limit >> 8, comparer) { } + + /// + /// Creates a LurchTable that orders items by (ordering) and removes items once the specified (limit) is reached. + /// + /// The type of linking for the items + /// The maximum allowable number of items, or int.MaxValue for unlimited + /// The number of hash buckets to use for the collection, usually 1/2 estimated capacity + /// The number of entries to allocate at a time, usually 1/16 estimated capacity + /// The number of concurrency locks to preallocate, usually 1/256 estimated capacity + /// The element hash generator for keys + public LurchTable(LurchTableOrder ordering, int limit, int hashSize, int allocSize, int lockSize, IEqualityComparer comparer) + { + if (limit <= 0) + throw new ArgumentOutOfRangeException("limit"); + if (ordering == LurchTableOrder.None && limit < int.MaxValue) + throw new ArgumentOutOfRangeException("ordering"); + + _limit = limit <= 0 ? int.MaxValue : limit; + _comparer = comparer; + _ordering = ordering; + + allocSize = (int)Math.Min((long)allocSize + OverAlloc, 0x3fffffff); + //last power of 2 that is less than allocSize + for (_shift = 7; _shift < 24 && (1 << (_shift + 1)) < allocSize; _shift++) { } + _allocSize = 1 << _shift; + _shiftMask = _allocSize - 1; + + _hsize = HashUtilities.SelectPrimeNumber(Math.Max(127, hashSize)); + _buckets = new int[_hsize]; + + _lsize = HashUtilities.SelectPrimeNumber(lockSize); + _locks = new object[_lsize]; + for (int i = 0; i < _lsize; i++) + _locks[i] = new object(); + + _free = new FreeList[FreeSlots]; + Initialize(); + } + + #region IDisposable Members + + /// + /// Clears references to all objects and invalidates the collection + /// + public void Dispose() + { + _entries = null; + _used = _count = 0; + } + + #endregion + + /// + /// Gets the number of elements contained in the . + /// + public int Count { get { return _count; } } + /// + /// Retrieves the LurchTableOrder Ordering enumeration this instance was created with. + /// + public LurchTableOrder Ordering { get { return _ordering; } } + /// + /// Retrives the key comparer being used by this instance. + /// + public IEqualityComparer Comparer { get { return _comparer; } } + /// + /// Gets or Sets the record limit allowed in this instance. + /// + public int Limit + { + get { return _limit; } + set { _limit = value; } + } + + /// + /// WARNING: not thread-safe, reinitializes all internal structures. Use Clear() for a thread-safe + /// delete all. If you have externally provided exclusive access this method may be used to more + /// efficiently clear the collection. + /// + public void Initialize() + { + lock (this) + { + _freeVersion = _allocNext = 0; + _count = 0; + _used = 1; + + Array.Clear(_buckets, 0, _hsize); + _entries = new[] { new Entry[_allocSize] }; + for (int slot = 0; slot < FreeSlots; slot++) + { + var index = Interlocked.CompareExchange(ref _used, _used + 1, _used); + if (index != slot + 1) + throw new LurchTableCorruptionException(); + + _free[slot].Tail = index; + _free[slot].Head = index; + } + + if (_count != 0 || _used != FreeSlots + 1) + throw new LurchTableCorruptionException(); + } + } + + #region IDictionary Members + + /// + /// Removes all items from the . + /// + public void Clear() + { + if (_entries == null) throw new ObjectDisposedException(GetType().Name); + foreach (var item in this) + Remove(item.Key); + } + + /// + /// Determines whether the contains an element with the specified key. + /// + public bool ContainsKey(TKey key) + { + if (_entries == null) throw new ObjectDisposedException(GetType().Name); + TValue value; + return TryGetValue(key, out value); + } + + /// + /// Gets or sets the element with the specified key. + /// + public TValue this[TKey key] + { + set + { + var info = new AddInfo { Value = value, CanUpdate = true }; + Insert(key, ref info); + } + get + { + TValue value; + if (!TryGetValue(key, out value)) + throw new ArgumentOutOfRangeException(); + return value; + } + } + + /// + /// Gets the value associated with the specified key. + /// + /// + /// true if the object that implements contains an element with the specified key; otherwise, false. + /// + public bool TryGetValue(TKey key, out TValue value) + { + int hash = _comparer.GetHashCode(key) & int.MaxValue; + return InternalGetValue(hash, key, out value); + } + + /// + /// Adds an element with the provided key and value to the . + /// + public void Add(TKey key, TValue value) + { + var info = new AddInfo { Value = value }; + if (InsertResult.Inserted != Insert(key, ref info)) + throw new ArgumentOutOfRangeException(); + } + + /// + /// Removes the element with the specified key from the . + /// + /// + /// true if the element is successfully removed; otherwise, false. This method also returns false if was not found in the original . + /// + /// The key of the element to remove. + public bool Remove(TKey key) + { + var del = new DelInfo(); + return Delete(key, ref del); + } + + #endregion + + #region IDictionaryEx Members + + /// + /// Adds a key/value pair to the if the key does not already exist. + /// + /// The key of the element to add. + /// The value to be added, if the key does not already exist. + public TValue GetOrAdd(TKey key, TValue value) + { + var info = new AddInfo { Value = value, CanUpdate = false }; + if (InsertResult.Exists == Insert(key, ref info)) + return info.Value; + return value; + } + + /// + /// Adds an element with the provided key and value to the . + /// + /// The object to use as the key of the element to add. + /// The object to use as the value of the element to add. + public bool TryAdd(TKey key, TValue value) + { + var info = new AddInfo { Value = value, CanUpdate = false }; + return InsertResult.Inserted == Insert(key, ref info); + } + + /// + /// Updates an element with the provided key to the value if it exists. + /// + /// Returns true if the key provided was found and updated to the value. + /// The object to use as the key of the element to update. + /// The new value for the key if found. + public bool TryUpdate(TKey key, TValue value) + { + var info = new UpdateInfo { Value = value }; + return InsertResult.Updated == Insert(key, ref info); + } + + /// + /// Updates an element with the provided key to the value if it exists. + /// + /// Returns true if the key provided was found and updated to the value. + /// The object to use as the key of the element to update. + /// The new value for the key if found. + /// The value that is compared to the value of the element with key. + public bool TryUpdate(TKey key, TValue value, TValue comparisonValue) + { + var info = new UpdateInfo(comparisonValue) { Value = value }; + return InsertResult.Updated == Insert(key, ref info); + } + + /// + /// Removes the element with the specified key from the . + /// + /// + /// true if the element is successfully removed; otherwise, false. This method also returns false if was not found in the original . + /// + /// The key of the element to remove. + /// The value that was removed. + public bool TryRemove(TKey key, out TValue value) + { + var info = new DelInfo(); + if (Delete(key, ref info)) + { + value = info.Value; + return true; + } + value = default(TValue); + return false; + } + + #endregion + + #region IConcurrentDictionary Members + + /// + /// Adds a key/value pair to the if the key does not already exist. + /// + /// The key of the element to add. + /// Constructs a new value for the key. + public TValue GetOrAdd(TKey key, Converter fnCreate) + { + var info = new Add2Info { Create = fnCreate }; + Insert(key, ref info); + return info.Value; + } + + /// + /// Adds a key/value pair to the if the key does not already exist, + /// or updates a key/value pair if the key already exists. + /// + public TValue AddOrUpdate(TKey key, TValue addValue, KeyValueUpdate fnUpdate) + { + var info = new Add2Info(addValue) { Update = fnUpdate }; + Insert(key, ref info); + return info.Value; + } + + /// + /// Adds a key/value pair to the if the key does not already exist, + /// or updates a key/value pair if the key already exists. + /// + /// + /// Adds or modifies an element with the provided key and value. If the key does not exist in the collection, + /// the factory method fnCreate will be called to produce the new value, if the key exists, the converter method + /// fnUpdate will be called to create an updated value. + /// + public TValue AddOrUpdate(TKey key, Converter fnCreate, KeyValueUpdate fnUpdate) + { + var info = new Add2Info { Create = fnCreate, Update = fnUpdate }; + Insert(key, ref info); + return info.Value; + } + + /// + /// Add, update, or fetche a key/value pair from the dictionary via an implementation of the + /// interface. + /// + public bool AddOrUpdate(TKey key, ref T createOrUpdateValue) where T : ICreateOrUpdateValue + { + var result = Insert(key, ref createOrUpdateValue); + return result == InsertResult.Inserted || result == InsertResult.Updated; + } + + /// + /// Adds an element with the provided key and value to the + /// by calling the provided factory method to construct the value if the key is not already present in the collection. + /// + public bool TryAdd(TKey key, Converter fnCreate) + { + var info = new Add2Info { Create = fnCreate }; + return InsertResult.Inserted == Insert(key, ref info); + } + + /// + /// Modify the value associated with the result of the provided update method + /// as an atomic operation, Allows for reading/writing a single record within + /// the syncronization lock. + /// + public bool TryUpdate(TKey key, KeyValueUpdate fnUpdate) + { + var info = new Add2Info { Update = fnUpdate }; + return InsertResult.Updated == Insert(key, ref info); + } + + /// + /// Removes the element with the specified key from the + /// if the fnCondition predicate is null or returns true. + /// + public bool TryRemove(TKey key, KeyValuePredicate fnCondition) + { + var info = new DelInfo { Condition = fnCondition }; + return Delete(key, ref info); + } + + /// + /// Conditionally removes a key/value pair from the dictionary via an implementation of the + /// interface. + /// + public bool TryRemove(TKey key, ref T removeValue) where T : IRemoveValue + { + return Delete(key, ref removeValue); + } + + #endregion + + #region ICollection> Members + + bool ICollection>.IsReadOnly + { + get { return false; } + } + + void ICollection>.Add(KeyValuePair item) + { + Add(item.Key, item.Value); + } + + bool ICollection>.Contains(KeyValuePair item) + { + TValue test; + if (TryGetValue(item.Key, out test)) + return EqualityComparer.Default.Equals(item.Value, test); + return false; + } + + void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) + { + foreach (var item in this) + array[arrayIndex++] = item; + } + + bool ICollection>.Remove(KeyValuePair item) + { + var del = new DelInfo(item.Value); + return Delete(item.Key, ref del); + } + + #endregion + + #region IEnumerator> + + private bool MoveNext(ref EnumState state) + { + if (_entries == null) throw new ObjectDisposedException(GetType().Name); + + if (state.Current > 0) + state.Current = state.Next; + + if (state.Current > 0) + { + state.Next = _entries[state.Current >> _shift][state.Current & _shiftMask].Link; + return true; + } + + state.Unlock(); + while (++state.Bucket < _hsize) + { + if (_buckets[state.Bucket] == 0) + continue; + + state.Lock(_locks[state.Bucket % _lsize]); + + state.Current = _buckets[state.Bucket]; + if (state.Current > 0) + { + state.Next = _entries[state.Current >> _shift][state.Current & _shiftMask].Link; + return true; + } + + state.Unlock(); + } + + return false; + } + + /// + /// Provides an enumerator that iterates through the collection. + /// + public struct Enumerator : IEnumerator> + { + private readonly LurchTable _owner; + private EnumState _state; + + internal Enumerator(LurchTable owner) + { + _owner = owner; + _state = new EnumState(); + _state.Init(); + } + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + _state.Unlock(); + } + + object IEnumerator.Current { get { return Current; } } + + /// + /// Gets the element in the collection at the current position of the enumerator. + /// + public KeyValuePair Current + { + get + { + int index = _state.Current; + if (index <= 0) + throw new InvalidOperationException(); + if (_owner._entries == null) + throw new ObjectDisposedException(GetType().Name); + + return new KeyValuePair + ( + _owner._entries[index >> _owner._shift][index & _owner._shiftMask].Key, + _owner._entries[index >> _owner._shift][index & _owner._shiftMask].Value + ); + } + } + + /// + /// Advances the enumerator to the next element of the collection. + /// + public bool MoveNext() + { + return _owner.MoveNext(ref _state); + } + + /// + /// Sets the enumerator to its initial position, which is before the first element in the collection. + /// + public void Reset() + { + _state.Unlock(); + _state.Init(); + } + } + + /// + /// Returns an enumerator that iterates through the collection. + /// + public Enumerator GetEnumerator() { return new Enumerator(this); } + IEnumerator> IEnumerable>.GetEnumerator() + { return GetEnumerator(); } + IEnumerator IEnumerable.GetEnumerator() + { return GetEnumerator(); } + #endregion + + #region KeyCollection + /// + /// Provides the collection of Keys for the LurchTable + /// + public class KeyCollection : ICollection + { + private readonly LurchTable _owner; + + internal KeyCollection(LurchTable owner) + { + _owner = owner; + } + + #region ICollection Members + + /// + /// Determines whether the contains a specific value. + /// + public bool Contains(TKey item) + { + return _owner.ContainsKey(item); + } + + /// + /// Copies the elements of the to an , starting at a particular index. + /// + public void CopyTo(TKey[] array, int arrayIndex) + { + foreach (var item in _owner) + array[arrayIndex++] = item.Key; + } + + /// + /// Gets the number of elements contained in the . + /// + public int Count + { + get { return _owner.Count; } + } + + /// + /// Returns an enumerator that iterates through the collection. + /// + public Enumerator GetEnumerator() + { + return new Enumerator(_owner); + } + + /// + /// Provides an enumerator that iterates through the collection. + /// + public struct Enumerator : IEnumerator + { + private readonly LurchTable _owner; + private EnumState _state; + + internal Enumerator(LurchTable owner) + { + _owner = owner; + _state = new EnumState(); + _state.Init(); + } + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + _state.Unlock(); + } + + object IEnumerator.Current { get { return Current; } } + + /// + /// Gets the element in the collection at the current position of the enumerator. + /// + public TKey Current + { + get + { + int index = _state.Current; + if (index <= 0) + throw new InvalidOperationException(); + if (_owner._entries == null) + throw new ObjectDisposedException(GetType().Name); + return _owner._entries[index >> _owner._shift][index & _owner._shiftMask].Key; + } + } + + /// + /// Advances the enumerator to the next element of the collection. + /// + public bool MoveNext() + { + return _owner.MoveNext(ref _state); + } + + /// + /// Sets the enumerator to its initial position, which is before the first element in the collection. + /// + public void Reset() + { + _state.Unlock(); + _state.Init(); + } + } + [Obsolete] + IEnumerator IEnumerable.GetEnumerator() + { + return new Enumerator(_owner); + } + [Obsolete] + IEnumerator IEnumerable.GetEnumerator() + { + return new Enumerator(_owner); + } + [Obsolete] + bool ICollection.IsReadOnly + { + get { return true; } + } + [Obsolete] + void ICollection.Add(TKey item) + { + throw new NotSupportedException(); + } + [Obsolete] + void ICollection.Clear() + { + throw new NotSupportedException(); + } + [Obsolete] + bool ICollection.Remove(TKey item) + { + throw new NotSupportedException(); + } + + #endregion + } + + private KeyCollection _keyCollection; + /// + /// Gets an containing the keys of the . + /// + public KeyCollection Keys { get { return _keyCollection ?? (_keyCollection = new KeyCollection(this)); } } + [Obsolete] + ICollection IDictionary.Keys { get { return Keys; } } + #endregion + + #region ValueCollection + /// + /// Provides the collection of Values for the LurchTable + /// + public class ValueCollection : ICollection + { + private readonly LurchTable _owner; + + internal ValueCollection(LurchTable owner) + { + _owner = owner; + } + + #region ICollection Members + + /// + /// Determines whether the contains a specific value. + /// + public bool Contains(TValue value) + { + var comparer = EqualityComparer.Default; + foreach (var item in _owner) + { + if (comparer.Equals(item.Value, value)) + return true; + } + return false; + } + + /// + /// Copies the elements of the to an , starting at a particular index. + /// + public void CopyTo(TValue[] array, int arrayIndex) + { + foreach (var item in _owner) + array[arrayIndex++] = item.Value; + } + + /// + /// Gets the number of elements contained in the . + /// + public int Count + { + get { return _owner.Count; } + } + + /// + /// Returns an enumerator that iterates through the collection. + /// + public Enumerator GetEnumerator() + { + return new Enumerator(_owner); + } + + /// + /// Provides an enumerator that iterates through the collection. + /// + public struct Enumerator : IEnumerator + { + private readonly LurchTable _owner; + private EnumState _state; + + internal Enumerator(LurchTable owner) + { + _owner = owner; + _state = new EnumState(); + _state.Init(); + } + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + _state.Unlock(); + } + + object IEnumerator.Current { get { return Current; } } + + /// + /// Gets the element in the collection at the current position of the enumerator. + /// + public TValue Current + { + get + { + int index = _state.Current; + if (index <= 0) + throw new InvalidOperationException(); + if (_owner._entries == null) + throw new ObjectDisposedException(GetType().Name); + return _owner._entries[index >> _owner._shift][index & _owner._shiftMask].Value; + } + } + + /// + /// Advances the enumerator to the next element of the collection. + /// + public bool MoveNext() + { + return _owner.MoveNext(ref _state); + } + + /// + /// Sets the enumerator to its initial position, which is before the first element in the collection. + /// + public void Reset() + { + _state.Unlock(); + _state.Init(); + } + } + [Obsolete] + IEnumerator IEnumerable.GetEnumerator() + { + return new Enumerator(_owner); + } + [Obsolete] + IEnumerator IEnumerable.GetEnumerator() + { + return new Enumerator(_owner); + } + [Obsolete] + bool ICollection.IsReadOnly + { + get { return true; } + } + [Obsolete] + void ICollection.Add(TValue item) + { + throw new NotSupportedException(); + } + [Obsolete] + void ICollection.Clear() + { + throw new NotSupportedException(); + } + [Obsolete] + bool ICollection.Remove(TValue item) + { + throw new NotSupportedException(); + } + + #endregion + } + + private ValueCollection _valueCollection; + /// + /// Gets an containing the values in the . + /// + public ValueCollection Values { get { return _valueCollection ?? (_valueCollection = new ValueCollection(this)); } } + [Obsolete] + ICollection IDictionary.Values { get { return Values; } } + + #endregion + + #region Peek/Dequeue + + /// + /// Retrieves the oldest entry in the collection based on the ordering supplied to the constructor. + /// + /// True if the out parameter value was set. + /// Raised if the table is unordered + public bool Peek(out KeyValuePair value) + { + if (_ordering == LurchTableOrder.None) + throw new InvalidOperationException(); + if (_entries == null) + throw new ObjectDisposedException(GetType().Name); + + while (true) + { + int index = Interlocked.CompareExchange(ref _entries[0][0].Prev, 0, 0); + if (index == 0) + { + value = default(KeyValuePair); + return false; + } + + int hash = _entries[index >> _shift][index & _shiftMask].Hash; + if (hash >= 0) + { + int bucket = hash % _hsize; + lock (_locks[bucket % _lsize]) + { + if (index == _entries[0][0].Prev && + hash == _entries[index >> _shift][index & _shiftMask].Hash) + { + value = new KeyValuePair( + _entries[index >> _shift][index & _shiftMask].Key, + _entries[index >> _shift][index & _shiftMask].Value + ); + return true; + } + } + } + } + } + + /// + /// Removes the oldest entry in the collection based on the ordering supplied to the constructor. + /// If an item is not available a busy-wait loop is used to wait for for an item. + /// + /// The Key/Value pair removed. + /// Raised if the table is unordered + public KeyValuePair Dequeue() + { + if (_ordering == LurchTableOrder.None) + throw new InvalidOperationException(); + if (_entries == null) + throw new ObjectDisposedException(GetType().Name); + + KeyValuePair value; + while (!TryDequeue(out value)) + { + while (0 == Interlocked.CompareExchange(ref _entries[0][0].Prev, 0, 0)) + Thread.Sleep(0); + } + return value; + } + + /// + /// Removes the oldest entry in the collection based on the ordering supplied to the constructor. + /// + /// False if no item was available + /// Raised if the table is unordered + public bool TryDequeue(out KeyValuePair value) + { + return TryDequeue(null, out value); + } + + /// + /// Removes the oldest entry in the collection based on the ordering supplied to the constructor. + /// + /// False if no item was available + /// Raised if the table is unordered + public bool TryDequeue(Predicate> predicate, out KeyValuePair value) + { + if (_ordering == LurchTableOrder.None) + throw new InvalidOperationException(); + if (_entries == null) + throw new ObjectDisposedException(GetType().Name); + + while (true) + { + int index = Interlocked.CompareExchange(ref _entries[0][0].Prev, 0, 0); + if (index == 0) + { + value = default(KeyValuePair); + return false; + } + + int hash = _entries[index >> _shift][index & _shiftMask].Hash; + if (hash >= 0) + { + int bucket = hash % _hsize; + lock (_locks[bucket % _lsize]) + { + if (index == _entries[0][0].Prev && + hash == _entries[index >> _shift][index & _shiftMask].Hash) + { + if (predicate != null) + { + var item = new KeyValuePair( + _entries[index >> _shift][index & _shiftMask].Key, + _entries[index >> _shift][index & _shiftMask].Value + ); + if (!predicate(item)) + { + value = item; + return false; + } + } + + int next = _entries[index >> _shift][index & _shiftMask].Link; + bool removed = false; + + if (_buckets[bucket] == index) + { + _buckets[bucket] = next; + removed = true; + } + else + { + int test = _buckets[bucket]; + while (test != 0) + { + int cmp = _entries[test >> _shift][test & _shiftMask].Link; + if (cmp == index) + { + _entries[test >> _shift][test & _shiftMask].Link = next; + removed = true; + break; + } + test = cmp; + } + } + if (!removed) + throw new LurchTableCorruptionException(); + + value = new KeyValuePair( + _entries[index >> _shift][index & _shiftMask].Key, + _entries[index >> _shift][index & _shiftMask].Value + ); + Interlocked.Decrement(ref _count); + if (_ordering != LurchTableOrder.None) + InternalUnlink(index); + FreeSlot(ref index, Interlocked.Increment(ref _freeVersion)); + + var handler = ItemRemoved; + if (handler != null) + handler(value); + + return true; + } + } + } + } + } + + #endregion + + #region Internal Implementation + + enum InsertResult { Inserted = 1, Updated = 2, Exists = 3, NotFound = 4 } + + bool InternalGetValue(int hash, TKey key, out TValue value) + { + if (_entries == null) + throw new ObjectDisposedException(GetType().Name); + + int bucket = hash % _hsize; + lock (_locks[bucket % _lsize]) + { + int index = _buckets[bucket]; + while (index != 0) + { + if (hash == _entries[index >> _shift][index & _shiftMask].Hash && + _comparer.Equals(key, _entries[index >> _shift][index & _shiftMask].Key)) + { + value = _entries[index >> _shift][index & _shiftMask].Value; + if (hash == _entries[index >> _shift][index & _shiftMask].Hash) + { + if (_ordering == LurchTableOrder.Access) + { + InternalUnlink(index); + InternalLink(index); + } + return true; + } + } + index = _entries[index >> _shift][index & _shiftMask].Link; + } + + value = default(TValue); + return false; + } + } + + InsertResult Insert(TKey key, ref T value) where T : ICreateOrUpdateValue + { + if (_entries == null) + throw new ObjectDisposedException(GetType().Name); + + int hash = _comparer.GetHashCode(key) & int.MaxValue; + int added; + + InsertResult result = InternalInsert(hash, key, out added, ref value); + + if (added > _limit && _ordering != LurchTableOrder.None) + { + KeyValuePair ignore; + TryDequeue(out ignore); + } + return result; + } + + InsertResult InternalInsert(int hash, TKey key, out int added, ref T value) where T : ICreateOrUpdateValue + { + int bucket = hash % _hsize; + lock (_locks[bucket % _lsize]) + { + TValue temp; + int index = _buckets[bucket]; + while (index != 0) + { + if (hash == _entries[index >> _shift][index & _shiftMask].Hash && + _comparer.Equals(key, _entries[index >> _shift][index & _shiftMask].Key)) + { + temp = _entries[index >> _shift][index & _shiftMask].Value; + var original = temp; + if (value.UpdateValue(key, ref temp)) + { + _entries[index >> _shift][index & _shiftMask].Value = temp; + + if (_ordering == LurchTableOrder.Modified || _ordering == LurchTableOrder.Access) + { + InternalUnlink(index); + InternalLink(index); + } + + var handler = ItemUpdated; + if (handler != null) + handler(new KeyValuePair(key, original), new KeyValuePair(key, temp)); + + added = -1; + return InsertResult.Updated; + } + + added = -1; + return InsertResult.Exists; + } + index = _entries[index >> _shift][index & _shiftMask].Link; + } + if (value.CreateValue(key, out temp)) + { +#pragma warning disable 612,618 + index = AllocSlot(); +#pragma warning restore 612,618 + _entries[index >> _shift][index & _shiftMask].Hash = hash; + _entries[index >> _shift][index & _shiftMask].Key = key; + _entries[index >> _shift][index & _shiftMask].Value = temp; + _entries[index >> _shift][index & _shiftMask].Link = _buckets[bucket]; + _buckets[bucket] = index; + + added = Interlocked.Increment(ref _count); + if (_ordering != LurchTableOrder.None) + InternalLink(index); + + var handler = ItemAdded; + if (handler != null) + handler(new KeyValuePair(key, temp)); + + return InsertResult.Inserted; + } + } + + added = -1; + return InsertResult.NotFound; + } + + bool Delete(TKey key, ref T value) where T : IRemoveValue + { + if (_entries == null) + throw new ObjectDisposedException(GetType().Name); + + int hash = _comparer.GetHashCode(key) & int.MaxValue; + int bucket = hash % _hsize; + lock (_locks[bucket % _lsize]) + { + int prev = 0; + int index = _buckets[bucket]; + while (index != 0) + { + if (hash == _entries[index >> _shift][index & _shiftMask].Hash && + _comparer.Equals(key, _entries[index >> _shift][index & _shiftMask].Key)) + { + TValue temp = _entries[index >> _shift][index & _shiftMask].Value; + + if (value.RemoveValue(key, temp)) + { + int next = _entries[index >> _shift][index & _shiftMask].Link; + if (prev == 0) + _buckets[bucket] = next; + else + _entries[prev >> _shift][prev & _shiftMask].Link = next; + + Interlocked.Decrement(ref _count); + if (_ordering != LurchTableOrder.None) + InternalUnlink(index); + FreeSlot(ref index, Interlocked.Increment(ref _freeVersion)); + + var handler = ItemRemoved; + if (handler != null) + handler(new KeyValuePair(key, temp)); + + return true; + } + return false; + } + + prev = index; + index = _entries[index >> _shift][index & _shiftMask].Link; + } + } + return false; + } + + void InternalLink(int index) + { + Interlocked.Exchange(ref _entries[index >> _shift][index & _shiftMask].Prev, 0); + Interlocked.Exchange(ref _entries[index >> _shift][index & _shiftMask].Next, ~0); + int next = Interlocked.Exchange(ref _entries[0][0].Next, index); + if (next < 0) + throw new LurchTableCorruptionException(); + + while (0 != Interlocked.CompareExchange(ref _entries[next >> _shift][next & _shiftMask].Prev, index, 0)) + { } + + Interlocked.Exchange(ref _entries[index >> _shift][index & _shiftMask].Next, next); + } + + void InternalUnlink(int index) + { + while (true) + { + int cmp; + int prev = _entries[index >> _shift][index & _shiftMask].Prev; + while (prev >= 0 && prev != (cmp = Interlocked.CompareExchange( + ref _entries[index >> _shift][index & _shiftMask].Prev, ~prev, prev))) + prev = cmp; + if (prev < 0) + throw new LurchTableCorruptionException(); + + int next = _entries[index >> _shift][index & _shiftMask].Next; + while (next >= 0 && next != (cmp = Interlocked.CompareExchange( + ref _entries[index >> _shift][index & _shiftMask].Next, ~next, next))) + next = cmp; + if (next < 0) + throw new LurchTableCorruptionException(); + + if ((Interlocked.CompareExchange( + ref _entries[prev >> _shift][prev & _shiftMask].Next, next, index) == index)) + { + while (Interlocked.CompareExchange( + ref _entries[next >> _shift][next & _shiftMask].Prev, prev, index) != index) + { } + return; + } + + //cancel the delete markers and retry + if (~next != Interlocked.CompareExchange( + ref _entries[index >> _shift][index & _shiftMask].Next, next, ~next)) + throw new LurchTableCorruptionException(); + if (~prev != Interlocked.CompareExchange( + ref _entries[index >> _shift][index & _shiftMask].Prev, prev, ~prev)) + throw new LurchTableCorruptionException(); + } + } + + [Obsolete("Release build inlining, so we need to ignore for testing.")] + int AllocSlot() + { + while (true) + { + int allocated = _entries.Length * _allocSize; + var previous = _entries; + + while (_count + OverAlloc < allocated || _used < allocated) + { + int next; + if (_count + FreeSlots < _used) + { + int freeSlotIndex = Interlocked.Increment(ref _allocNext); + int slot = (freeSlotIndex & int.MaxValue) % FreeSlots; + next = Interlocked.Exchange(ref _free[slot].Head, 0); + if (next != 0) + { + int nextFree = _entries[next >> _shift][next & _shiftMask].Link; + if (nextFree == 0) + { + Interlocked.Exchange(ref _free[slot].Head, next); + } + else + { + Interlocked.Exchange(ref _free[slot].Head, nextFree); + return next; + } + } + } + + next = _used; + if (next < allocated) + { + int alloc = Interlocked.CompareExchange(ref _used, next + 1, next); + if (alloc == next) + { + return next; + } + } + } + + lock (this) + { + //time to grow... + if (ReferenceEquals(_entries, previous)) + { + Entry[][] arentries = new Entry[_entries.Length + 1][]; + _entries.CopyTo(arentries, 0); + arentries[arentries.Length - 1] = new Entry[_allocSize]; + + Interlocked.CompareExchange(ref _entries, arentries, previous); + } + } + } + } + + void FreeSlot(ref int index, int ver) + { + _entries[index >> _shift][index & _shiftMask].Key = default(TKey); + _entries[index >> _shift][index & _shiftMask].Value = default(TValue); + Interlocked.Exchange(ref _entries[index >> _shift][index & _shiftMask].Link, 0); + + int slot = (ver & int.MaxValue) % FreeSlots; + int prev = Interlocked.Exchange(ref _free[slot].Tail, index); + + if (prev <= 0 || 0 != Interlocked.CompareExchange(ref _entries[prev >> _shift][prev & _shiftMask].Link, index, 0)) + { + throw new LurchTableCorruptionException(); + } + } + + #endregion + + #region Internal Structures + + struct FreeList + { + public int Head; + public int Tail; + } + + struct Entry + { + public int Prev, Next; // insertion/access sequence ordering + public int Link; + public int Hash; // hash value of entry's Key + public TKey Key; // key of entry + public TValue Value; // value of entry + } + + struct EnumState + { + private object _locked; + public int Bucket, Current, Next; + public void Init() + { + Bucket = -1; + Current = 0; + Next = 0; + _locked = null; + } + + public void Unlock() + { + if (_locked != null) + { + Monitor.Exit(_locked); + _locked = null; + } + } + + public void Lock(object lck) + { + if (_locked != null) + Monitor.Exit(_locked); + Monitor.Enter(_locked = lck); + } + } + + struct DelInfo : IRemoveValue + { + public TValue Value; + readonly bool _hasTestValue; + readonly TValue _testValue; + public KeyValuePredicate Condition; + + public DelInfo(TValue expected) + { + Value = default(TValue); + _testValue = expected; + _hasTestValue = true; + Condition = null; + } + + public bool RemoveValue(TKey key, TValue value) + { + Value = value; + + if (_hasTestValue && !EqualityComparer.Default.Equals(_testValue, value)) + return false; + if (Condition != null && !Condition(key, value)) + return false; + + return true; + } + } + + struct AddInfo : ICreateOrUpdateValue + { + public bool CanUpdate; + public TValue Value; + public bool CreateValue(TKey key, out TValue value) + { + value = Value; + return true; + } + + public bool UpdateValue(TKey key, ref TValue value) + { + if (!CanUpdate) + { + Value = value; + return false; + } + + value = Value; + return true; + } + } + + struct Add2Info : ICreateOrUpdateValue + { + readonly bool _hasAddValue; + readonly TValue _addValue; + public TValue Value; + public Converter Create; + public KeyValueUpdate Update; + + public Add2Info(TValue addValue) : this() + { + _hasAddValue = true; + _addValue = addValue; + } + + public bool CreateValue(TKey key, out TValue value) + { + if (_hasAddValue) + { + value = Value = _addValue; + return true; + } + if (Create != null) + { + value = Value = Create(key); + return true; + } + value = Value = default(TValue); + return false; + } + + public bool UpdateValue(TKey key, ref TValue value) + { + if (Update == null) + { + Value = value; + return false; + } + + value = Value = Update(key, value); + return true; + } + } + + struct UpdateInfo : ICreateOrUpdateValue + { + public TValue Value; + readonly bool _hasTestValue; + readonly TValue _testValue; + + public UpdateInfo(TValue expected) + { + Value = default(TValue); + _testValue = expected; + _hasTestValue = true; + } + + bool ICreateValue.CreateValue(TKey key, out TValue value) + { + value = default(TValue); + return false; + } + public bool UpdateValue(TKey key, ref TValue value) + { + if (_hasTestValue && !EqualityComparer.Default.Equals(_testValue, value)) + return false; + + value = Value; + return true; + } + } + #endregion + } + + #region LurchTable Support + + #region Exceptions + + /// + /// Exception class: LurchTableCorruptionException + /// The LurchTable internal datastructure appears to be corrupted. + /// + [System.SerializableAttribute()] + [global::System.Diagnostics.DebuggerStepThroughAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("CSharpTest.Net.Generators", "2.13.222.435")] + public partial class LurchTableCorruptionException : System.ApplicationException + { + /// + /// Serialization constructor + /// + protected LurchTableCorruptionException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) + { + } + /// + /// Used to create this exception from an hresult and message bypassing the message formatting + /// + internal static System.Exception Create(int hResult, string message) + { + return new LurchTableCorruptionException((System.Exception)null, hResult, message); + } + /// + /// Constructs the exception from an hresult and message bypassing the message formatting + /// + protected LurchTableCorruptionException(System.Exception innerException, int hResult, string message) : base(message, innerException) + { + base.HResult = hResult; + } + /// + /// The LurchTable internal datastructure appears to be corrupted. + /// + public LurchTableCorruptionException() + : this((System.Exception)null, -1, "The LurchTable internal datastructure appears to be corrupted.") + { + } + /// + /// The LurchTable internal datastructure appears to be corrupted. + /// + public LurchTableCorruptionException(System.Exception innerException) + : this(innerException, -1, "The LurchTable internal datastructure appears to be corrupted.") + { + } + /// + /// if(condition == false) throws The LurchTable internal datastructure appears to be corrupted. + /// + public static void Assert(bool condition) + { + if (!condition) throw new LurchTableCorruptionException(); + } + } + + #endregion // Exceptions + + #region Delegates + + /// Provides a delegate that performs an atomic update of a key/value pair + public delegate TValue KeyValueUpdate(TKey key, TValue original); + + /// Provides a delegate that performs a test on key/value pair + public delegate bool KeyValuePredicate(TKey key, TValue original); + + #endregion // Delegates + + #region Interfaces + + /// + /// An interface to provide conditional or custom creation logic to a concurrent dictionary. + /// + public interface ICreateValue + { + /// + /// Called when the key was not found within the dictionary to produce a new value that can be added. + /// Return true to continue with the insertion, or false to prevent the key/value from being inserted. + /// + bool CreateValue(TKey key, out TValue value); + } + /// + /// An interface to provide conditional or custom update logic to a concurrent dictionary. + /// + public interface IUpdateValue + { + /// + /// Called when the key was found within the dictionary to produce a modified value to update the item + /// to. Return true to continue with the update, or false to prevent the key/value from being updated. + /// + bool UpdateValue(TKey key, ref TValue value); + } + /// + /// An interface to provide conditional or custom creation or update logic to a concurrent dictionary. + /// + /// + /// Generally implemented as a struct and passed by ref to save stack space and to retrieve the values + /// that where inserted or updated. + /// + public interface ICreateOrUpdateValue : ICreateValue, IUpdateValue + { + } + + /// + /// An interface to provide conditional removal of an item from a concurrent dictionary. + /// + /// + /// Generally implemented as a struct and passed by ref to save stack space and to retrieve the values + /// that where inserted or updated. + /// + public interface IRemoveValue + { + /// + /// Called when the dictionary is about to remove the key/value pair provided, return true to allow + /// it's removal, or false to prevent it from being removed. + /// + bool RemoveValue(TKey key, TValue value); + } + + #endregion // interfaces + + #region Classes + + internal class HashUtilities + { + private static readonly int[] PrimeNumbers = + new[] + { + 17, 37, 67, 131, 257, 521, // ROK - Added smaller primes + 1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861, 5839, 7013, 8419, 10103, 12143, 14591, + 17519, 21023, 25229, 30293, 36353, 43627, 52361, 62851, 75431, 90523, 108631, 130363, 156437, + 187751, 225307, 270371, 324449, 389357, 467237, 560689, 672827, 807403, 968897, 1162687, + 1395263, 1674319, 2009191, 2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369 + }; + + internal static int SelectPrimeNumber(int hashSize) + { + int offset = Array.BinarySearch(PrimeNumbers, hashSize); + if (offset < 0) + offset = ~offset; + return PrimeNumbers[Math.Min(offset, PrimeNumbers.Length - 1)]; + } + } + + #endregion // Classes + + #endregion // LurchTable Support +} diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs index 09496140c5..1aeac45514 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs @@ -287,26 +287,26 @@ public override int GetOrdinal(FacetLabel cp) } // First try to find the answer in the LRU cache: - lock (ordinalCache) + + // LUCENENET: Lock was removed here because the underlying cache is thread-safe, + // and removing the lock seems to make the performance better. + IntClass res = ordinalCache.Get(cp); + if (res != null && res.IntItem != null) { - IntClass res = ordinalCache.Get(cp); - if (res != null && res.IntItem != null) + if ((int)res.IntItem.Value < indexReader.MaxDoc) { - if ((int)res.IntItem.Value < indexReader.MaxDoc) - { - // Since the cache is shared with DTR instances allocated from - // doOpenIfChanged, we need to ensure that the ordinal is one that - // this DTR instance recognizes. - return (int)res.IntItem.Value; - } - else - { - // if we get here, it means that the category was found in the cache, - // but is not recognized by this TR instance. Therefore there's no - // need to continue search for the path on disk, because we won't find - // it there too. - return TaxonomyReader.INVALID_ORDINAL; - } + // Since the cache is shared with DTR instances allocated from + // doOpenIfChanged, we need to ensure that the ordinal is one that + // this DTR instance recognizes. + return (int)res.IntItem.Value; + } + else + { + // if we get here, it means that the category was found in the cache, + // but is not recognized by this TR instance. Therefore there's no + // need to continue search for the path on disk, because we won't find + // it there too. + return TaxonomyReader.INVALID_ORDINAL; } } @@ -323,10 +323,10 @@ public override int GetOrdinal(FacetLabel cp) // that are allocated from doOpenIfChanged. Therefore, if we only store // information about found categories, we cannot accidently tell a new // generation of DTR that a category does not exist. - lock (ordinalCache) - { - ordinalCache.Put(cp, new IntClass { IntItem = Convert.ToInt32(ret) }); - } + + // LUCENENET: Lock was removed here because the underlying cache is thread-safe, + // and removing the lock seems to make the performance better. + ordinalCache.Put(cp, new IntClass { IntItem = Convert.ToInt32(ret) }); } return ret; @@ -348,10 +348,10 @@ public override FacetLabel GetPath(int ordinal) // TODO: can we use an int-based hash impl, such as IntToObjectMap, // wrapped as LRU? - // LUCENENET NOTE: We don't need to convert int to int here. - // Also, our cache implementation is thread safe, so we can nix the - // locks. + // LUCENENET NOTE: We don't need to convert ordinal from int to int here as was done in Java. FacetLabel res; + // LUCENENET: Lock was removed here because the underlying cache is thread-safe, + // and removing the lock seems to make the performance better. if (categoryCache.TryGetValue(ordinal, out res)) { return res; @@ -359,6 +359,8 @@ public override FacetLabel GetPath(int ordinal) Document doc = indexReader.Document(ordinal); res = new FacetLabel(FacetsConfig.StringToPath(doc.Get(Consts.FULL))); + // LUCENENET: Lock was removed here because the underlying cache is thread-safe, + // and removing the lock seems to make the performance better. categoryCache.Put(ordinal, res); return res; @@ -386,10 +388,14 @@ public virtual int CacheSize set { EnsureOpen(); - // LUCENENET NOTE: No locking required here, - // since our LRU implementation is thread-safe - categoryCache.Capacity = value; - ordinalCache.Capacity = value; + lock (categoryCache) + { + categoryCache.Limit = value; + } + lock (ordinalCache) + { + ordinalCache.Limit = value; + } } } diff --git a/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs b/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs index 5ff77fb6ff..956922f050 100644 --- a/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs +++ b/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs @@ -1,6 +1,7 @@ -using System; +using Lucene.Net.Support; +using System; +using System.Collections; using System.Collections.Generic; -using System.Linq; namespace Lucene.Net.Facet.Taxonomy { @@ -26,8 +27,8 @@ namespace Lucene.Net.Facet.Taxonomy /// When it reaches that , each time a new element is added, the least /// recently used (LRU) entry is removed. /// - /// Unlike the Java Lucene implementation, this one is thread safe. Do note - /// that every time an element is read from , + /// Unlike the Java Lucene implementation, this one is thread safe because it is backed by the . + /// Do note that every time an element is read from , /// a write operation also takes place to update the element's last access time. /// This is because the LRU order needs to be remembered to determine which element /// to evict when the is exceeded. @@ -37,157 +38,162 @@ namespace Lucene.Net.Facet.Taxonomy /// @lucene.experimental /// /// - public class LRUHashMap where TValue : class //this is implementation of LRU Cache + public class LRUHashMap : IDictionary { - private readonly Dictionary cache; - // We can't use a ReaderWriterLockSlim because every read is also a - // write, so we gain nothing by doing so - private readonly object syncLock = new object(); - // Record last access so we can tie break if 2 calls make it in within - // the same millisecond. - private long lastAccess; - private int capacity; + private LurchTable cache; public LRUHashMap(int capacity) { - if (capacity < 1) - { - throw new ArgumentOutOfRangeException("capacity must be at least 1"); - } - this.capacity = capacity; - this.cache = new Dictionary(capacity); + cache = new LurchTable(LurchTableOrder.Access, capacity); } /// /// allows changing the map's maximal number of elements /// which was defined at construction time. /// - /// Note that if the map is already larger than maxSize, the current + /// Note that if the map is already larger than , the current /// implementation does not shrink it (by removing the oldest elements); /// Rather, the map remains in its current size as new elements are /// added, and will only start shrinking (until settling again on the - /// given ) if existing elements are explicitly deleted. + /// given ) if existing elements are explicitly deleted. /// /// - public virtual int Capacity + public virtual int Limit { - get { return capacity; } + get + { + return cache.Limit; + } set { if (value < 1) { - throw new ArgumentOutOfRangeException("Capacity must be at least 1"); + throw new ArgumentOutOfRangeException("Limit must be at least 1"); } - capacity = value; + cache.Limit = value; } } - public bool Put(TKey key, TValue value) + public TValue Put(TKey key, TValue value) { - lock (syncLock) - { - CacheDataObject cdo; - if (cache.TryGetValue(key, out cdo)) - { - // Item already exists, update our last access time - cdo.timestamp = GetTimestamp(); - } - else - { - cache[key] = new CacheDataObject - { - value = value, - timestamp = GetTimestamp() - }; - // We have added a new item, so we may need to remove the eldest - if (cache.Count > Capacity) - { - // Remove the eldest item (lowest timestamp) from the cache - cache.Remove(cache.OrderBy(x => x.Value.timestamp).First().Key); - } - } - } - return true; + TValue oldValue = default(TValue); + cache.AddOrUpdate(key, value, (k, v) => + { + oldValue = cache[key]; + return value; + }); + return oldValue; } public TValue Get(TKey key) { - lock (syncLock) + TValue result; + if (!cache.TryGetValue(key, out result)) { - CacheDataObject cdo; - if (cache.TryGetValue(key, out cdo)) - { - // Write our last access time - cdo.timestamp = GetTimestamp(); - - return cdo.value; - } + return default(TValue); } - return null; + return result; } - public bool TryGetValue(TKey key, out TValue value) + #region IDictionary members + + public TValue this[TKey key] { - lock (syncLock) + get { - CacheDataObject cdo; - if (cache.TryGetValue(key, out cdo)) - { - // Write our last access time - cdo.timestamp = GetTimestamp(); - value = cdo.value; - - return true; - } - - value = null; - return false; + return cache[key]; + } + set + { + cache[key] = value; } } - public bool ContainsKey(TKey key) + public int Count { - return cache.ContainsKey(key); + get + { + return cache.Count; + } } - public int Count + public bool IsReadOnly { get { - return cache.Count; + return false; } } - private long GetTimestamp() + public ICollection Keys { - long ticks = DateTime.UtcNow.Ticks; - if (ticks <= lastAccess) + get { - // Tie break by incrementing - // when 2 calls happen within the - // same millisecond - ticks = ++lastAccess; + return cache.Keys; } - else + } + + public ICollection Values + { + get { - lastAccess = ticks; + return cache.Values; } - return ticks; } - - #region Nested type: CacheDataObject + public void Add(KeyValuePair item) + { + throw new NotSupportedException(); + } - private class CacheDataObject + public void Add(TKey key, TValue value) { - // Ticks representing the last access time - public long timestamp; - public TValue value; + cache.Add(key, value); + } - public override string ToString() - { - return "Last Access: " + timestamp.ToString() + " - " + value.ToString(); - } + public void Clear() + { + cache.Clear(); + } + + public bool Contains(KeyValuePair item) + { + throw new NotSupportedException(); + } + + public bool ContainsKey(TKey key) + { + return cache.ContainsKey(key); + } + + public void CopyTo(KeyValuePair[] array, int arrayIndex) + { + throw new NotSupportedException(); + } + + public IEnumerator> GetEnumerator() + { + return cache.GetEnumerator(); + } + + public bool Remove(KeyValuePair item) + { + throw new NotSupportedException(); + } + + public bool Remove(TKey key) + { + return cache.Remove(key); + } + + public bool TryGetValue(TKey key, out TValue value) + { + return cache.TryGetValue(key, out value); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return cache.GetEnumerator(); } #endregion diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs index abad1ea6ed..d7d5676ec2 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/LruTaxonomyWriterCache.cs @@ -116,13 +116,13 @@ public virtual int Get(FacetLabel categoryPath) { lock (this) { - int? res = cache.Get(categoryPath); - if (res == null) + int result; + if (!cache.TryGetValue(categoryPath, out result)) { return -1; } - return (int)res; + return result; } } @@ -130,7 +130,7 @@ public virtual bool Put(FacetLabel categoryPath, int ordinal) { lock (this) { - bool ret = cache.Put(categoryPath, new int?(ordinal)); + bool ret = cache.Put(categoryPath, ordinal); // If the cache is full, we need to clear one or more old entries // from the cache. However, if we delete from the cache a recent // addition that isn't yet in our reader, for this entry to be diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs index b7264a092f..6b849f8218 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using Lucene.Net.Support; +using System.Collections.Generic; using System.Linq; namespace Lucene.Net.Facet.Taxonomy.WriterCache @@ -32,7 +33,7 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache /// public class NameIntCacheLRU { - private Dictionary cache; + private IDictionary cache; internal long nMisses = 0; // for debug internal long nHits = 0; // for debug private int capacity; @@ -67,31 +68,36 @@ public virtual int Count private void CreateCache(int maxSize) { - // LUCENENET TODO: Create an adapter so we can plug in either a generic - // dictionary or LRUHashMap or alternatively make LRUHashMap implement IDictionary - //if (maxSize < int.MaxValue) - //{ - // cache = new LRUHashMap(1000,true); //for LRU - //} - //else + if (maxSize < int.MaxValue) { - cache = new Dictionary(1000); //no need for LRU + cache = new LurchTable(1000, LurchTableOrder.Access); //for LRU + } + else + { + cache = new Dictionary(1000); //no need for LRU } } - internal virtual int? Get(FacetLabel name) + internal virtual int Get(FacetLabel name) + { + int result; + TryGetValue(name, out result); + return result; + } + + internal virtual bool TryGetValue(FacetLabel name, out int value) { object key = Key(name); - int? res = cache.ContainsKey(key) ? cache[key] : null; - if (res == null) + if (!cache.TryGetValue(key, out value)) { nMisses++; + return false; } else { nHits++; + return true; } - return res; } /// @@ -111,13 +117,13 @@ internal virtual object Key(FacetLabel name, int prefixLen) /// Add a new value to cache. /// Return true if cache became full and some room need to be made. /// - internal virtual bool Put(FacetLabel name, int? val) + internal virtual bool Put(FacetLabel name, int val) { cache[Key(name)] = val; return CacheFull; } - internal virtual bool Put(FacetLabel name, int prefixLen, int? val) + internal virtual bool Put(FacetLabel name, int prefixLen, int val) { cache[Key(name, prefixLen)] = val; return CacheFull; @@ -160,12 +166,24 @@ internal virtual bool MakeRoomLRU() return false; } - // LUCENENET: Loop in reverse so we can safely delete - // a range of items (0 - n) without a - // "Collection was modified" conflict - for (int i = n - 1; i >= 0; i--) + lock (this) { - cache.Remove(cache.Keys.ElementAt(i)); + // Double-check that another thread didn't beat us to the operation + n = cache.Count - (2 * capacity) / 3; + if (n <= 0) + { + return false; + } + + //System.Diagnostics.Debug.WriteLine("Removing cache entries in MakeRoomLRU"); + + // LUCENENET: Loop in reverse so we can safely delete + // a range of items (0 - n) without a + // "Collection was modified" conflict + for (int i = n - 1; i >= 0; i--) + { + cache.Remove(cache.Keys.ElementAt(i)); + } } return true; } diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs index 1f7afb1601..e19a9004d5 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs @@ -59,6 +59,12 @@ public virtual void TestLru() Assert.Null(lru.Get("five")); Assert.NotNull(lru.Get("six")); Assert.NotNull(lru.Get("seven")); + + // LUCENENET specific tests to ensure Put is implemented correctly + Assert.Null(lru.Put("ten", "oops")); + assertEquals("oops", lru.Put("ten", "not oops")); + assertEquals("not oops", lru.Put("ten", "new value")); + assertEquals("new value", lru.Put("ten", "new value2")); } } From ddfb46c1024e57609f2c3df26ffd921ac95bb663 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Mon, 3 Oct 2016 23:56:52 +0700 Subject: [PATCH 41/41] Fixed QueryParser project merge conflict. --- Lucene.Net.sln | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/Lucene.Net.sln b/Lucene.Net.sln index 25ab1ab8d7..0322498604 100644 --- a/Lucene.Net.sln +++ b/Lucene.Net.sln @@ -51,6 +51,7 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.QueryParser", "src\Lucene.Net.QueryParser\Lucene.Net.QueryParser.csproj", "{949BA34B-6AE6-4CE3-B578-61E13E4D76BF}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.Tests.QueryParser", "src\Lucene.Net.Tests.QueryParser\Lucene.Net.Tests.QueryParser.csproj", "{5719FB4F-BF80-40E5-BACC-37E8E18FCA2E}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.Misc", "src\Lucene.Net.Misc\Lucene.Net.Misc.csproj", "{A3A0D943-B91A-4B7A-9FCB-6160EA575D95}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.Tests.Misc", "src\Lucene.Net.Tests.Misc\Lucene.Net.Tests.Misc.csproj", "{7895E023-EB91-401C-B2B3-754EEC42134B}" @@ -59,10 +60,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.Suggest", "src\L EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.Tests.Suggest", "src\Lucene.Net.Tests.Suggest\Lucene.Net.Tests.Suggest.csproj", "{A6511598-3008-4A3B-AE68-2D1DA792CA8A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.QueryParser", "src\Lucene.Net.QueryParser\Lucene.Net.QueryParser.csproj", "{949BA34B-6AE6-4CE3-B578-61E13E4D76BF}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.Tests.QueryParser", "src\Lucene.Net.Tests.QueryParser\Lucene.Net.Tests.QueryParser.csproj", "{5719FB4F-BF80-40E5-BACC-37E8E18FCA2E}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.Memory", "src\Lucene.Net.Memory\Lucene.Net.Memory.csproj", "{42ECF239-AFC1-427D-921E-B5A277809CF0}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.Tests.Memory", "src\Lucene.Net.Tests.Memory\Lucene.Net.Tests.Memory.csproj", "{7F9378BF-C88D-46FF-9AE8-5E7D8C0225D3}" @@ -334,26 +331,6 @@ Global {A6511598-3008-4A3B-AE68-2D1DA792CA8A}.Release|Mixed Platforms.Build.0 = Release|Any CPU {A6511598-3008-4A3B-AE68-2D1DA792CA8A}.Release|x86.ActiveCfg = Release|Any CPU {A6511598-3008-4A3B-AE68-2D1DA792CA8A}.Release|x86.Build.0 = Release|Any CPU - {949BA34B-6AE6-4CE3-B578-61E13E4D76BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {949BA34B-6AE6-4CE3-B578-61E13E4D76BF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {949BA34B-6AE6-4CE3-B578-61E13E4D76BF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {949BA34B-6AE6-4CE3-B578-61E13E4D76BF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {949BA34B-6AE6-4CE3-B578-61E13E4D76BF}.Debug|x86.ActiveCfg = Debug|Any CPU - {949BA34B-6AE6-4CE3-B578-61E13E4D76BF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {949BA34B-6AE6-4CE3-B578-61E13E4D76BF}.Release|Any CPU.Build.0 = Release|Any CPU - {949BA34B-6AE6-4CE3-B578-61E13E4D76BF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {949BA34B-6AE6-4CE3-B578-61E13E4D76BF}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {949BA34B-6AE6-4CE3-B578-61E13E4D76BF}.Release|x86.ActiveCfg = Release|Any CPU - {5719FB4F-BF80-40E5-BACC-37E8E18FCA2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5719FB4F-BF80-40E5-BACC-37E8E18FCA2E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5719FB4F-BF80-40E5-BACC-37E8E18FCA2E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {5719FB4F-BF80-40E5-BACC-37E8E18FCA2E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {5719FB4F-BF80-40E5-BACC-37E8E18FCA2E}.Debug|x86.ActiveCfg = Debug|Any CPU - {5719FB4F-BF80-40E5-BACC-37E8E18FCA2E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5719FB4F-BF80-40E5-BACC-37E8E18FCA2E}.Release|Any CPU.Build.0 = Release|Any CPU - {5719FB4F-BF80-40E5-BACC-37E8E18FCA2E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {5719FB4F-BF80-40E5-BACC-37E8E18FCA2E}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {5719FB4F-BF80-40E5-BACC-37E8E18FCA2E}.Release|x86.ActiveCfg = Release|Any CPU {42ECF239-AFC1-427D-921E-B5A277809CF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {42ECF239-AFC1-427D-921E-B5A277809CF0}.Debug|Any CPU.Build.0 = Debug|Any CPU {42ECF239-AFC1-427D-921E-B5A277809CF0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU