Return-Path: X-Original-To: apmail-lucenenet-commits-archive@www.apache.org Delivered-To: apmail-lucenenet-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0FAC2C8D8 for ; Fri, 14 Nov 2014 11:59:18 +0000 (UTC) Received: (qmail 58353 invoked by uid 500); 14 Nov 2014 11:59:18 -0000 Delivered-To: apmail-lucenenet-commits-archive@lucenenet.apache.org Received: (qmail 58245 invoked by uid 500); 14 Nov 2014 11:59:17 -0000 Mailing-List: contact commits-help@lucenenet.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@lucenenet.apache.org Delivered-To: mailing list commits@lucenenet.apache.org Received: (qmail 57640 invoked by uid 99); 14 Nov 2014 11:59:17 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Nov 2014 11:59:17 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 577F6940666; Fri, 14 Nov 2014 11:59:17 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: synhershko@apache.org To: commits@lucenenet.apache.org Date: Fri, 14 Nov 2014 11:59:27 -0000 Message-Id: <233e058dad9745efa1d4f073e3bbbb25@git.apache.org> In-Reply-To: <25d3e5ad3026426c84d9af894c5dece8@git.apache.org> References: <25d3e5ad3026426c84d9af894c5dece8@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [12/26] lucenenet git commit: first commit of facet porting, failing tests will be fixed in next commits. http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/Lucene.Net.Facet/TopOrdAndIntQueue.cs ---------------------------------------------------------------------- diff --git a/Lucene.Net.Facet/TopOrdAndIntQueue.cs b/Lucene.Net.Facet/TopOrdAndIntQueue.cs new file mode 100644 index 0000000..63711f2 --- /dev/null +++ b/Lucene.Net.Facet/TopOrdAndIntQueue.cs @@ -0,0 +1,76 @@ +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. + * 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 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; + + /// + /// Value associated with the ordinal. + public int value; + + /// + /// Default constructor. + public OrdAndValue() + { + } + } + + /// + /// Sole constructor. + public TopOrdAndIntQueue(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 http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/Lucene.Net.sln ---------------------------------------------------------------------- diff --git a/Lucene.Net.sln b/Lucene.Net.sln index 5da27b0..afc21f4 100644 --- a/Lucene.Net.sln +++ b/Lucene.Net.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30110.0 +VisualStudioVersion = 12.0.30723.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net", "src\Lucene.Net.Core\Lucene.Net.csproj", "{5D4AD9BE-1FFB-41AB-9943-25737971BF57}" EndProject @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.TestFramework", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.Queries", "src\Lucene.Net.Queries\Lucene.Net.Queries.csproj", "{69D7956C-C2CC-4708-B399-A188FEC384C4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.Facet", "Lucene.Net.Facet\Lucene.Net.Facet.csproj", "{48F7884A-9454-4E88-8413-9D35992CB440}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -62,6 +64,16 @@ Global {69D7956C-C2CC-4708-B399-A188FEC384C4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {69D7956C-C2CC-4708-B399-A188FEC384C4}.Release|Mixed Platforms.Build.0 = Release|Any CPU {69D7956C-C2CC-4708-B399-A188FEC384C4}.Release|x86.ActiveCfg = Release|Any CPU + {48F7884A-9454-4E88-8413-9D35992CB440}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {48F7884A-9454-4E88-8413-9D35992CB440}.Debug|Any CPU.Build.0 = Debug|Any CPU + {48F7884A-9454-4E88-8413-9D35992CB440}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {48F7884A-9454-4E88-8413-9D35992CB440}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {48F7884A-9454-4E88-8413-9D35992CB440}.Debug|x86.ActiveCfg = Debug|Any CPU + {48F7884A-9454-4E88-8413-9D35992CB440}.Release|Any CPU.ActiveCfg = Release|Any CPU + {48F7884A-9454-4E88-8413-9D35992CB440}.Release|Any CPU.Build.0 = Release|Any CPU + {48F7884A-9454-4E88-8413-9D35992CB440}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {48F7884A-9454-4E88-8413-9D35992CB440}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {48F7884A-9454-4E88-8413-9D35992CB440}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Index/BinaryDocValuesFieldUpdates.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Index/BinaryDocValuesFieldUpdates.cs b/src/Lucene.Net.Core/Index/BinaryDocValuesFieldUpdates.cs index 46ef31b..f94da6b 100644 --- a/src/Lucene.Net.Core/Index/BinaryDocValuesFieldUpdates.cs +++ b/src/Lucene.Net.Core/Index/BinaryDocValuesFieldUpdates.cs @@ -200,7 +200,7 @@ namespace Lucene.Net.Index this.DocsWithField = docsWithField; } - protected internal override void Swap(int i, int j) + protected override void Swap(int i, int j) { long tmpDoc = Docs.Get(j); Docs.Set(j, Docs.Get(i)); @@ -233,7 +233,7 @@ namespace Lucene.Net.Index } } - protected internal override int Compare(int i, int j) + protected override int Compare(int i, int j) { int x = (int)Docs.Get(i); int y = (int)Docs.Get(j); http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Index/NumericDocValuesFieldUpdates.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Index/NumericDocValuesFieldUpdates.cs b/src/Lucene.Net.Core/Index/NumericDocValuesFieldUpdates.cs index 684f62a..6878b6f 100644 --- a/src/Lucene.Net.Core/Index/NumericDocValuesFieldUpdates.cs +++ b/src/Lucene.Net.Core/Index/NumericDocValuesFieldUpdates.cs @@ -172,7 +172,7 @@ namespace Lucene.Net.Index this.DocsWithField = docsWithField; } - protected internal override void Swap(int i, int j) + protected override void Swap(int i, int j) { long tmpDoc = Docs.Get(j); Docs.Set(j, Docs.Get(i)); @@ -201,7 +201,7 @@ namespace Lucene.Net.Index } } - protected internal override int Compare(int i, int j) + protected override int Compare(int i, int j) { int x = (int)Docs.Get(i); int y = (int)Docs.Get(j); http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Index/ReaderManager.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Index/ReaderManager.cs b/src/Lucene.Net.Core/Index/ReaderManager.cs index 835ecf1..e56dab7 100644 --- a/src/Lucene.Net.Core/Index/ReaderManager.cs +++ b/src/Lucene.Net.Core/Index/ReaderManager.cs @@ -64,22 +64,22 @@ namespace Lucene.Net.Index Current = DirectoryReader.Open(dir); } - protected internal override void DecRef(DirectoryReader reference) + protected override void DecRef(DirectoryReader reference) { reference.DecRef(); } - protected internal override DirectoryReader RefreshIfNeeded(DirectoryReader referenceToRefresh) + protected override DirectoryReader RefreshIfNeeded(DirectoryReader referenceToRefresh) { return DirectoryReader.OpenIfChanged(referenceToRefresh); } - protected internal override bool TryIncRef(DirectoryReader reference) + protected override bool TryIncRef(DirectoryReader reference) { return reference.TryIncRef(); } - protected internal override int GetRefCount(DirectoryReader reference) + protected override int GetRefCount(DirectoryReader reference) { return reference.RefCount; } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Lucene.Net.csproj ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Lucene.Net.csproj b/src/Lucene.Net.Core/Lucene.Net.csproj index 58a6c8a..84ed61d 100644 --- a/src/Lucene.Net.Core/Lucene.Net.csproj +++ b/src/Lucene.Net.Core/Lucene.Net.csproj @@ -638,6 +638,7 @@ + @@ -675,6 +676,7 @@ + http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Search/CachingWrapperFilter.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Search/CachingWrapperFilter.cs b/src/Lucene.Net.Core/Search/CachingWrapperFilter.cs index 2f2acca..3e2dcef 100644 --- a/src/Lucene.Net.Core/Search/CachingWrapperFilter.cs +++ b/src/Lucene.Net.Core/Search/CachingWrapperFilter.cs @@ -99,7 +99,7 @@ namespace Lucene.Net.Search /// /// Default cache implementation: uses . /// - protected internal virtual DocIdSet CacheImpl(DocIdSetIterator iterator, AtomicReader reader) + protected virtual DocIdSet CacheImpl(DocIdSetIterator iterator, AtomicReader reader) { var builder = new WAH8DocIdSet.Builder(); builder.Add(iterator); http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Search/Query.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Search/Query.cs b/src/Lucene.Net.Core/Search/Query.cs index 5a32b5b..5dbfac1 100644 --- a/src/Lucene.Net.Core/Search/Query.cs +++ b/src/Lucene.Net.Core/Search/Query.cs @@ -138,7 +138,7 @@ namespace Lucene.Net.Search return true; } - if (GetType() != obj.GetType()) + if (obj != null && GetType() != obj.GetType()) return false; var other = obj as Query; http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Search/ReferenceManager.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Search/ReferenceManager.cs b/src/Lucene.Net.Core/Search/ReferenceManager.cs index f693d68..4af85e7 100644 --- a/src/Lucene.Net.Core/Search/ReferenceManager.cs +++ b/src/Lucene.Net.Core/Search/ReferenceManager.cs @@ -71,20 +71,20 @@ namespace Lucene.Net.Search /// Decrement reference counting on the given reference. /// if reference decrement on the given resource failed. /// - protected internal abstract void DecRef(G reference); + protected abstract void DecRef(G reference); /// /// Refresh the given reference if needed. Returns {@code null} if no refresh /// was needed, otherwise a new refreshed reference. /// if the reference manager has been . /// if the refresh operation failed - protected internal abstract G RefreshIfNeeded(G referenceToRefresh); + protected abstract G RefreshIfNeeded(G referenceToRefresh); /// /// Try to increment reference counting on the given reference. Return true if /// the operation was successful. /// if the reference manager has been . - protected internal abstract bool TryIncRef(G reference); + protected abstract bool TryIncRef(G reference); /// /// Obtain the current reference. You must match every call to acquire with one @@ -161,7 +161,7 @@ namespace Lucene.Net.Search /// /// Returns the current reference count of the given reference. /// - protected internal abstract int GetRefCount(G reference); + protected abstract int GetRefCount(G reference); /// /// Called after close(), so subclass can free any resources. http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Search/SearcherManager.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Search/SearcherManager.cs b/src/Lucene.Net.Core/Search/SearcherManager.cs index 8c80a43..cc74646 100644 --- a/src/Lucene.Net.Core/Search/SearcherManager.cs +++ b/src/Lucene.Net.Core/Search/SearcherManager.cs @@ -110,12 +110,12 @@ namespace Lucene.Net.Search Current = GetSearcher(searcherFactory, DirectoryReader.Open(dir)); } - protected internal override void DecRef(IndexSearcher reference) + protected override void DecRef(IndexSearcher reference) { reference.IndexReader.DecRef(); } - protected internal override IndexSearcher RefreshIfNeeded(IndexSearcher referenceToRefresh) + protected override IndexSearcher RefreshIfNeeded(IndexSearcher referenceToRefresh) { IndexReader r = referenceToRefresh.IndexReader; Debug.Assert(r is DirectoryReader, "searcher's IndexReader should be a DirectoryReader, but got " + r); @@ -130,12 +130,12 @@ namespace Lucene.Net.Search } } - protected internal override bool TryIncRef(IndexSearcher reference) + protected override bool TryIncRef(IndexSearcher reference) { return reference.IndexReader.TryIncRef(); } - protected internal override int GetRefCount(IndexSearcher reference) + protected override int GetRefCount(IndexSearcher reference) { return reference.IndexReader.RefCount; } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Search/Spans/NearSpansOrdered.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Search/Spans/NearSpansOrdered.cs b/src/Lucene.Net.Core/Search/Spans/NearSpansOrdered.cs index 76110e5..7b52ebb 100644 --- a/src/Lucene.Net.Core/Search/Spans/NearSpansOrdered.cs +++ b/src/Lucene.Net.Core/Search/Spans/NearSpansOrdered.cs @@ -87,12 +87,12 @@ namespace Lucene.Net.Search.Spans this.OuterInstance = outerInstance; } - protected internal override void Swap(int i, int j) + protected override void Swap(int i, int j) { ArrayUtil.Swap(OuterInstance.SubSpansByDoc, i, j); } - protected internal override int Compare(int i, int j) + protected override int Compare(int i, int j) { return OuterInstance.SubSpansByDoc[i].Doc() - OuterInstance.SubSpansByDoc[j].Doc(); } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Support/StreamUtils.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Support/StreamUtils.cs b/src/Lucene.Net.Core/Support/StreamUtils.cs new file mode 100644 index 0000000..75e7d15 --- /dev/null +++ b/src/Lucene.Net.Core/Support/StreamUtils.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Formatters.Binary; +using System.Text; +using System.Threading.Tasks; + +namespace Lucene.Net.Support +{ + public static class StreamUtils + { + static readonly BinaryFormatter Formatter = new BinaryFormatter(); + + public static MemoryStream SerializeToStream(object o) + { + using (var stream = new MemoryStream()) + { + Formatter.Serialize(stream, o); + return stream; + } + } + + 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); + return o; + } + } +} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Util/Accountable.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Util/Accountable.cs b/src/Lucene.Net.Core/Util/Accountable.cs new file mode 100644 index 0000000..9dfa711 --- /dev/null +++ b/src/Lucene.Net.Core/Util/Accountable.cs @@ -0,0 +1,36 @@ +namespace Lucene.Net.Util +{ + + /* + * 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. + */ + + /// + /// An object whose RAM usage can be computed. + /// + /// @lucene.internal + /// + public interface Accountable + { + + /// + /// Return the memory usage of this object in bytes. Negative values are illegal. + /// + long RamBytesUsed(); + + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Util/ArrayInPlaceMergeSorter.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Util/ArrayInPlaceMergeSorter.cs b/src/Lucene.Net.Core/Util/ArrayInPlaceMergeSorter.cs index 5465e40..8f1ac0c 100644 --- a/src/Lucene.Net.Core/Util/ArrayInPlaceMergeSorter.cs +++ b/src/Lucene.Net.Core/Util/ArrayInPlaceMergeSorter.cs @@ -36,12 +36,12 @@ namespace Lucene.Net.Util this.Comparator = comparator; } - protected internal override int Compare(int i, int j) + protected override int Compare(int i, int j) { return Comparator.Compare(Arr[i], Arr[j]); } - protected internal override void Swap(int i, int j) + protected override void Swap(int i, int j) { ArrayUtil.Swap(Arr, i, j); } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Util/ArrayIntroSorter.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Util/ArrayIntroSorter.cs b/src/Lucene.Net.Core/Util/ArrayIntroSorter.cs index b201943..d647621 100644 --- a/src/Lucene.Net.Core/Util/ArrayIntroSorter.cs +++ b/src/Lucene.Net.Core/Util/ArrayIntroSorter.cs @@ -38,12 +38,12 @@ namespace Lucene.Net.Util Pivot_Renamed = default(T); } - protected internal override int Compare(int i, int j) + protected override int Compare(int i, int j) { return Comparator.Compare(Arr[i], Arr[j]); } - protected internal override void Swap(int i, int j) + protected override void Swap(int i, int j) { ArrayUtil.Swap(Arr, i, j); } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Util/ArrayTimSorter.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Util/ArrayTimSorter.cs b/src/Lucene.Net.Core/Util/ArrayTimSorter.cs index da68492..9364ff0 100644 --- a/src/Lucene.Net.Core/Util/ArrayTimSorter.cs +++ b/src/Lucene.Net.Core/Util/ArrayTimSorter.cs @@ -48,12 +48,12 @@ namespace Lucene.Net.Util } } - protected internal override int Compare(int i, int j) + protected override int Compare(int i, int j) { return Comparator.Compare(Arr[i], Arr[j]); } - protected internal override void Swap(int i, int j) + protected override void Swap(int i, int j) { ArrayUtil.Swap(Arr, i, j); } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Util/BytesRefArray.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Util/BytesRefArray.cs b/src/Lucene.Net.Core/Util/BytesRefArray.cs index 2a5eca1..2554c76 100644 --- a/src/Lucene.Net.Core/Util/BytesRefArray.cs +++ b/src/Lucene.Net.Core/Util/BytesRefArray.cs @@ -135,14 +135,14 @@ namespace Lucene.Net.Util scratch2 = new BytesRef(); } - protected internal override void Swap(int i, int j) + protected override void Swap(int i, int j) { int o = OrderedEntries[i]; OrderedEntries[i] = OrderedEntries[j]; OrderedEntries[j] = o; } - protected internal override int Compare(int i, int j) + protected override int Compare(int i, int j) { int idx1 = OrderedEntries[i], idx2 = OrderedEntries[j]; return Comp.Compare(OuterInstance.Get(scratch1, idx1), OuterInstance.Get(scratch2, idx2)); http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Util/BytesRefHash.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Util/BytesRefHash.cs b/src/Lucene.Net.Core/Util/BytesRefHash.cs index f1e3ef6..4b762ed 100644 --- a/src/Lucene.Net.Core/Util/BytesRefHash.cs +++ b/src/Lucene.Net.Core/Util/BytesRefHash.cs @@ -187,14 +187,14 @@ namespace Lucene.Net.Util this.Compact = compact; } - protected internal override void Swap(int i, int j) + protected override void Swap(int i, int j) { int o = Compact[i]; Compact[i] = Compact[j]; Compact[j] = o; } - protected internal override int Compare(int i, int j) + protected override int Compare(int i, int j) { int id1 = Compact[i], id2 = Compact[j]; Debug.Assert(OuterInstance.BytesStart.Length > id1 && OuterInstance.BytesStart.Length > id2); http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Util/CollectionUtil.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Util/CollectionUtil.cs b/src/Lucene.Net.Core/Util/CollectionUtil.cs index fc692fa..3de4d33 100644 --- a/src/Lucene.Net.Core/Util/CollectionUtil.cs +++ b/src/Lucene.Net.Core/Util/CollectionUtil.cs @@ -62,12 +62,12 @@ namespace Lucene.Net.Util } } - protected internal override void Swap(int i, int j) + protected override void Swap(int i, int j) { list = list.Swap(i, j); } - protected internal override int Compare(int i, int j) + protected override int Compare(int i, int j) { return Comp.Compare(list[i], list[j]); } @@ -104,7 +104,7 @@ namespace Lucene.Net.Util } } - protected internal override void Swap(int i, int j) + protected override void Swap(int i, int j) { List = List.Swap(i, j); } @@ -127,7 +127,7 @@ namespace Lucene.Net.Util List[j] = Tmp[i]; } - protected internal override int Compare(int i, int j) + protected override int Compare(int i, int j) { return Comp.Compare(List[i], List[j]); } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Util/IOUtils.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Util/IOUtils.cs b/src/Lucene.Net.Core/Util/IOUtils.cs index 78236e4..e23d3cd 100644 --- a/src/Lucene.Net.Core/Util/IOUtils.cs +++ b/src/Lucene.Net.Core/Util/IOUtils.cs @@ -268,7 +268,7 @@ namespace Lucene.Net.Util } else { - suppressedExceptions = (List) exception.Data["SuppressedExceptions"]; + suppressedExceptions = (List)exception.Data["SuppressedExceptions"]; } suppressedExceptions.Add(suppressed); } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Core/Util/Sorter.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Util/Sorter.cs b/src/Lucene.Net.Core/Util/Sorter.cs index 979dfce..2176a7b 100644 --- a/src/Lucene.Net.Core/Util/Sorter.cs +++ b/src/Lucene.Net.Core/Util/Sorter.cs @@ -38,11 +38,11 @@ namespace Lucene.Net.Util /// The contract for the returned value is the same as /// . /// - protected internal abstract int Compare(int i, int j); + protected abstract int Compare(int i, int j); /// /// Swap values at slots i and j. - protected internal abstract void Swap(int i, int j); + protected abstract void Swap(int i, int j); /// /// Sort the slice which starts at from (inclusive) and ends at http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj b/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj index 5b57114..ad426d0 100644 --- a/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj +++ b/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj @@ -65,10 +65,18 @@ + + {48f7884a-9454-4e88-8413-9d35992cb440} + Lucene.Net.Facet + {5d4ad9be-1ffb-41ab-9943-25737971bf57} Lucene.Net + + {69d7956c-c2cc-4708-b399-a188fec384c4} + Lucene.Net.Queries + {b2c0d749-ce34-4f62-a15e-00cb2ff5ddb3} Lucene.Net.TestFramework @@ -149,6 +157,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Tests/core/Facet/AssertingSubDocsAtOnceCollector.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests/core/Facet/AssertingSubDocsAtOnceCollector.cs b/src/Lucene.Net.Tests/core/Facet/AssertingSubDocsAtOnceCollector.cs new file mode 100644 index 0000000..c3730df --- /dev/null +++ b/src/Lucene.Net.Tests/core/Facet/AssertingSubDocsAtOnceCollector.cs @@ -0,0 +1,85 @@ +using System.Collections.Generic; +using Apache.NMS; + +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. + */ + + + using AtomicReaderContext = Lucene.Net.Index.AtomicReaderContext; + using Collector = Lucene.Net.Search.Collector; + using ChildScorer = Lucene.Net.Search.Scorer.ChildScorer; + using Scorer = Lucene.Net.Search.Scorer; + + /// + /// Verifies in collect() that all child subScorers are on + /// the collected doc. + /// + internal class AssertingSubDocsAtOnceCollector : Collector + { + + // TODO: allow wrapping another Collector + + internal IList allScorers; + + public override Scorer Scorer + { + set + { + // Gathers all scorers, including value and "under": + allScorers = new List(); + allScorers.Add(value); + int upto = 0; + while (upto < allScorers.Count) + { + value = allScorers[upto++]; + foreach (ChildScorer sub in value.Children) + { + allScorers.Add(sub.Child); + } + } + } + } + + public override void Collect(int docID) + { + foreach (Scorer s in allScorers) + { + if (docID != s.DocID()) + { + throw new IllegalStateException("subScorer=" + s + " has docID=" + s.DocID() + " != collected docID=" + docID); + } + } + } + + public override AtomicReaderContext NextReader + { + set + { + } + } + + public override bool AcceptsDocsOutOfOrder() + { + return false; + } + + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/lucenenet/blob/982eaf60/src/Lucene.Net.Tests/core/Facet/FacetTestCase.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests/core/Facet/FacetTestCase.cs b/src/Lucene.Net.Tests/core/Facet/FacetTestCase.cs new file mode 100644 index 0000000..49d5f0f --- /dev/null +++ b/src/Lucene.Net.Tests/core/Facet/FacetTestCase.cs @@ -0,0 +1,293 @@ +using System; +using System.Diagnostics; +using System.Collections.Generic; +using System.Linq; +using Lucene.Net.Facet; +using Lucene.Net.Randomized.Generators; +using Lucene.Net.Support; +using NUnit.Framework; + +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. + */ + + + using CachedOrdinalsReader = Lucene.Net.Facet.Taxonomy.CachedOrdinalsReader; + using DocValuesOrdinalsReader = Lucene.Net.Facet.Taxonomy.DocValuesOrdinalsReader; + using FastTaxonomyFacetCounts = Lucene.Net.Facet.Taxonomy.FastTaxonomyFacetCounts; + using OrdinalsReader = Lucene.Net.Facet.Taxonomy.OrdinalsReader; + using TaxonomyFacetCounts = Lucene.Net.Facet.Taxonomy.TaxonomyFacetCounts; + using TaxonomyReader = Lucene.Net.Facet.Taxonomy.TaxonomyReader; + using BytesRef = Lucene.Net.Util.BytesRef; + using SuppressCodecs = Lucene.Net.Util.LuceneTestCase.SuppressCodecs; + using LuceneTestCase = Lucene.Net.Util.LuceneTestCase; + using TestUtil = Lucene.Net.Util.TestUtil; + + [TestFixture] + public abstract class FacetTestCase : LuceneTestCase + { + public virtual Facets GetTaxonomyFacetCounts(TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector c) + { + return GetTaxonomyFacetCounts(taxoReader, config, c, FacetsConfig.DEFAULT_INDEX_FIELD_NAME); + } + public virtual Facets GetTaxonomyFacetCounts(TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector c, string indexFieldName) + { + Facets facets; + if (Random().NextBoolean()) + { + facets = new FastTaxonomyFacetCounts(indexFieldName, taxoReader, config, c); + } + else + { + OrdinalsReader ordsReader = new DocValuesOrdinalsReader(indexFieldName); + if (Random().NextBoolean()) + { + ordsReader = new CachedOrdinalsReader(ordsReader); + } + facets = new TaxonomyFacetCounts(ordsReader, taxoReader, config, c); + } + + return facets; + } + + protected internal virtual string[] GetRandomTokens(int count) + { + string[] tokens = new string[count]; + for (int i = 0; i < tokens.Length; i++) + { + tokens[i] = TestUtil.RandomRealisticUnicodeString(Random(), 1, 10); + //tokens[i] = TestUtil.RandomSimpleString(Random(), 1, 10); + } + return tokens; + } + + protected internal virtual string PickToken(string[] tokens) + { + for (int i = 0; i < tokens.Length; i++) + { + if (Random().NextBoolean()) + { + return tokens[i]; + } + } + + // Move long tail onto first token: + return tokens[0]; + } + + protected internal class TestDoc + { + public string content; + public string[] dims; + public float value; + } + + protected internal virtual IList GetRandomDocs(string[] tokens, int count, int numDims) + { + IList docs = new List(); + for (int i = 0; i < count; i++) + { + TestDoc doc = new TestDoc(); + docs.Add(doc); + doc.content = PickToken(tokens); + doc.dims = new string[numDims]; + for (int j = 0; j < numDims; j++) + { + doc.dims[j] = PickToken(tokens); + if (Random().Next(10) < 3) + { + break; + } + } + if (VERBOSE) + { + Console.WriteLine(" doc " + i + ": content=" + doc.content); + for (int j = 0; j < numDims; j++) + { + if (doc.dims[j] != null) + { + Console.WriteLine(" dim[" + j + "]=" + doc.dims[j]); + } + } + } + } + + return docs; + } + + protected internal virtual void SortTies(IList results) + { + foreach (FacetResult result in results) + { + SortTies(result.labelValues); + } + } + + protected internal virtual void SortTies(LabelAndValue[] labelValues) + { + double lastValue = -1; + int numInRow = 0; + int i = 0; + while (i <= labelValues.Length) + { + if (i < labelValues.Length && (double)labelValues[i].value == lastValue) + { + numInRow++; + } + else + { + if (numInRow > 1) + { + Array.Sort(labelValues, i - numInRow, i, new ComparatorAnonymousInnerClassHelper(this)); + } + numInRow = 1; + if (i < labelValues.Length) + { + lastValue = (double)labelValues[i].value; + } + } + i++; + } + } + + private class ComparatorAnonymousInnerClassHelper : IComparer + { + private readonly FacetTestCase outerInstance; + + public ComparatorAnonymousInnerClassHelper(FacetTestCase outerInstance) + { + this.outerInstance = 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)); + } + } + + protected internal virtual void SortLabelValues(IList labelValues) + { + var resArray = labelValues.ToArray(); + Array.Sort(resArray,new ComparatorAnonymousInnerClassHelper2(this)); + labelValues = resArray.ToList(); + } + + private class ComparatorAnonymousInnerClassHelper2 : IComparer + { + private readonly FacetTestCase outerInstance; + + public ComparatorAnonymousInnerClassHelper2(FacetTestCase outerInstance) + { + this.outerInstance = outerInstance; + } + + public virtual int Compare(LabelAndValue a, LabelAndValue b) + { + if ((double)a.value > (double)b.value) + { + return -1; + } + else if ((double)a.value < (double)b.value) + { + return 1; + } + else + { + return (new BytesRef(a.label)).CompareTo(new BytesRef(b.label)); + } + } + } + + protected internal virtual void SortFacetResults(IList results) + { + var resArray = results.ToArray(); + Array.Sort(resArray, new ComparatorAnonymousInnerClassHelper3(this)); + results = resArray.ToList(); + } + + private class ComparatorAnonymousInnerClassHelper3 : IComparer + { + private readonly FacetTestCase outerInstance; + + public ComparatorAnonymousInnerClassHelper3(FacetTestCase outerInstance) + { + this.outerInstance = outerInstance; + } + + public virtual int Compare(FacetResult a, FacetResult b) + { + if ((double)a.value > (double)b.value) + { + return -1; + } + else if ((double)b.value > (double)a.value) + { + return 1; + } + else + { + return 0; + } + } + } + + [Test] + protected internal virtual void AssertFloatValuesEquals(IList a, IList b) + { + Assert.AreEqual(a.Count, b.Count); + float lastValue = float.PositiveInfinity; + IDictionary aByDim = new Dictionary(); + for (int i = 0; i < a.Count; i++) + { + Assert.True((float)a[i].value <= lastValue); + lastValue = (float)a[i].value; + aByDim[a[i].dim] = a[i]; + } + lastValue = float.PositiveInfinity; + IDictionary bByDim = new Dictionary(); + for (int i = 0; i < b.Count; i++) + { + bByDim[b[i].dim] = b[i]; + Assert.True((float)b[i].value <= lastValue); + lastValue = (float)b[i].value; + } + foreach (string dim in aByDim.Keys) + { + AssertFloatValuesEquals(aByDim[dim], bByDim[dim]); + } + } + + [Test] + protected internal virtual void AssertFloatValuesEquals(FacetResult a, FacetResult b) + { + Assert.AreEqual(a.dim, b.dim); + Assert.True(Arrays.Equals(a.path, b.path)); + Assert.AreEqual(a.childCount, b.childCount); + Assert.AreEqual((float)a.value, (float)b.value, (float)a.value / 1e5); + 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); + } + } + } + +} \ No newline at end of file