Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C24F1200C28 for ; Mon, 27 Feb 2017 00:36:53 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id C1284160B81; Sun, 26 Feb 2017 23:36:53 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 66331160B85 for ; Mon, 27 Feb 2017 00:36:51 +0100 (CET) Received: (qmail 38235 invoked by uid 500); 26 Feb 2017 23:36:50 -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 37593 invoked by uid 99); 26 Feb 2017 23:36:50 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Feb 2017 23:36:50 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CA2CCE009E; Sun, 26 Feb 2017 23:36:49 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: nightowl888@apache.org To: commits@lucenenet.apache.org Date: Sun, 26 Feb 2017 23:37:02 -0000 Message-Id: <15e79e12a8b84a1a91eb92d6544fe8de@git.apache.org> In-Reply-To: <1e7e127cca214d5a80ee73510374469b@git.apache.org> References: <1e7e127cca214d5a80ee73510374469b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [14/72] [abbrv] [partial] lucenenet git commit: Lucene.Net.Tests: Removed \core directory and put its contents in root directory archived-at: Sun, 26 Feb 2017 23:36:53 -0000 http://git-wip-us.apache.org/repos/asf/lucenenet/blob/96822396/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 8509774..b8f5fc2 100644 --- a/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj +++ b/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj @@ -52,47 +52,47 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -118,584 +118,584 @@ - + Code - + Code - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + + Code - - - + + + Code - - - - + + + + Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code - - - + + + Code - + Code - - - + + + Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code - - + + Code - + Code - + Code - + Code - + Code - - + + Code - + Code - + Code - + Code - + Code - + Code - - + + Code - + Code - + Code - - + + Code - + Code - + Code - + Code - + Code - - + + Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code - + Code - - + + Code - + Code - + Code - - + + Code - + - - + + - + http://git-wip-us.apache.org/repos/asf/lucenenet/blob/96822396/src/Lucene.Net.Tests/Lucene.Net.snk ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests/Lucene.Net.snk b/src/Lucene.Net.Tests/Lucene.Net.snk new file mode 100644 index 0000000..f7f9ee5 Binary files /dev/null and b/src/Lucene.Net.Tests/Lucene.Net.snk differ http://git-wip-us.apache.org/repos/asf/lucenenet/blob/96822396/src/Lucene.Net.Tests/RectangularArrays.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests/RectangularArrays.cs b/src/Lucene.Net.Tests/RectangularArrays.cs new file mode 100644 index 0000000..6375f45 --- /dev/null +++ b/src/Lucene.Net.Tests/RectangularArrays.cs @@ -0,0 +1,52 @@ +//---------------------------------------------------------------------------------------- +// Copyright � 2007 - 2013 Tangible Software Solutions Inc. +// this class can be used by anyone provided that the copyright notice remains intact. +// +// this class provides the logic to simulate Java rectangular arrays, which are jagged +// arrays with inner arrays of the same length. A size of -1 indicates unknown length. +//---------------------------------------------------------------------------------------- + +using Lucene.Net.Util; + +internal static partial class RectangularArrays +{ + internal static int[][] ReturnRectangularIntArray(int Size1, int Size2) + { + int[][] Array; + if (Size1 > -1) + { + Array = new int[Size1][]; + if (Size2 > -1) + { + for (int Array1 = 0; Array1 < Size1; Array1++) + { + Array[Array1] = new int[Size2]; + } + } + } + else + Array = null; + + return Array; + } + + internal static BytesRef[][] ReturnRectangularBytesRefArray(int Size1, int Size2) + { + BytesRef[][] Array; + if (Size1 > -1) + { + Array = new BytesRef[Size1][]; + if (Size2 > -1) + { + for (int Array1 = 0; Array1 < Size1; Array1++) + { + Array[Array1] = new BytesRef[Size2]; + } + } + } + else + Array = null; + + return Array; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/lucenenet/blob/96822396/src/Lucene.Net.Tests/Search/BaseTestRangeFilter.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests/Search/BaseTestRangeFilter.cs b/src/Lucene.Net.Tests/Search/BaseTestRangeFilter.cs new file mode 100644 index 0000000..3bd412e --- /dev/null +++ b/src/Lucene.Net.Tests/Search/BaseTestRangeFilter.cs @@ -0,0 +1,211 @@ +using System; +using System.Text; +using Lucene.Net.Documents; + +namespace Lucene.Net.Search +{ + using NUnit.Framework; + using Directory = Lucene.Net.Store.Directory; + using Document = Documents.Document; + using Field = Field; + using IndexReader = Lucene.Net.Index.IndexReader; + using LuceneTestCase = Lucene.Net.Util.LuceneTestCase; + + /* + * 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 MockAnalyzer = Lucene.Net.Analysis.MockAnalyzer; + using OpenMode = Lucene.Net.Index.OpenMode; + using RandomIndexWriter = Lucene.Net.Index.RandomIndexWriter; + using TestUtil = Lucene.Net.Util.TestUtil; + + [TestFixture] + public class BaseTestRangeFilter : LuceneTestCase + { + public const bool F = false; + public const bool T = true; + + /// + /// Collation interacts badly with hyphens -- collation produces different + /// ordering than Unicode code-point ordering -- so two indexes are created: + /// one which can't have negative random integers, for testing collated ranges, + /// and the other which can have negative random integers, for all other tests. + /// + internal class TestIndex + { + internal int MaxR; + internal int MinR; + internal bool AllowNegativeRandomInts; + internal Directory Index; + + internal TestIndex(Random random, int minR, int maxR, bool allowNegativeRandomInts) + { + this.MinR = minR; + this.MaxR = maxR; + this.AllowNegativeRandomInts = allowNegativeRandomInts; + Index = NewDirectory(random); + } + } + + internal static IndexReader SignedIndexReader; + internal static IndexReader UnsignedIndexReader; + + internal static TestIndex SignedIndexDir; + internal static TestIndex UnsignedIndexDir; + + internal static int MinId = 0; + internal static int MaxId; + + internal static readonly int IntLength = Convert.ToString(int.MaxValue).Length; + + /// + /// a simple padding function that should work with any int + /// + public static string Pad(int n) + { + StringBuilder b = new StringBuilder(40); + string p = "0"; + if (n < 0) + { + p = "-"; + n = int.MaxValue + n + 1; + } + b.Append(p); + string s = Convert.ToString(n); + for (int i = s.Length; i <= IntLength; i++) + { + b.Append("0"); + } + b.Append(s); + + return b.ToString(); + } + + /// + /// LUCENENET specific + /// Is non-static because is no + /// longer static. + /// + [OneTimeSetUp] + public void BeforeClassBaseTestRangeFilter() + { + MaxId = AtLeast(500); + SignedIndexDir = new TestIndex(Random(), int.MaxValue, int.MinValue, true); + UnsignedIndexDir = new TestIndex(Random(), int.MaxValue, 0, false); + SignedIndexReader = Build(Random(), SignedIndexDir); + UnsignedIndexReader = Build(Random(), UnsignedIndexDir); + } + + [OneTimeTearDown] + public static void AfterClassBaseTestRangeFilter() + { + SignedIndexReader.Dispose(); + UnsignedIndexReader.Dispose(); + SignedIndexDir.Index.Dispose(); + UnsignedIndexDir.Index.Dispose(); + SignedIndexReader = null; + UnsignedIndexReader = null; + SignedIndexDir = null; + UnsignedIndexDir = null; + } + + /// + /// LUCENENET specific + /// Passed in because NewStringField and NewIndexWriterConfig are no + /// longer static. + /// + private IndexReader Build(Random random, TestIndex index) + { + /* build an index */ + + Document doc = new Document(); + Field idField = NewStringField(random, "id", "", Field.Store.YES); + Field randField = NewStringField(random, "rand", "", Field.Store.YES); + Field bodyField = NewStringField(random, "body", "", Field.Store.NO); + doc.Add(idField); + doc.Add(randField); + doc.Add(bodyField); + + RandomIndexWriter writer = new RandomIndexWriter(random, index.Index, NewIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(random)).SetOpenMode(OpenMode.CREATE).SetMaxBufferedDocs(TestUtil.NextInt(random, 50, 1000)).SetMergePolicy(NewLogMergePolicy())); + TestUtil.ReduceOpenFiles(writer.w); + + while (true) + { + int minCount = 0; + int maxCount = 0; + + for (int d = MinId; d <= MaxId; d++) + { + idField.SetStringValue(Pad(d)); + int r = index.AllowNegativeRandomInts ? random.Next() : random.Next(int.MaxValue); + if (index.MaxR < r) + { + index.MaxR = r; + maxCount = 1; + } + else if (index.MaxR == r) + { + maxCount++; + } + + if (r < index.MinR) + { + index.MinR = r; + minCount = 1; + } + else if (r == index.MinR) + { + minCount++; + } + randField.SetStringValue(Pad(r)); + bodyField.SetStringValue("body"); + writer.AddDocument(doc); + } + + if (minCount == 1 && maxCount == 1) + { + // our subclasses rely on only 1 doc having the min or + // max, so, we loop until we satisfy that. it should be + // exceedingly rare (Yonik calculates 1 in ~429,000) + // times) that this loop requires more than one try: + IndexReader ir = writer.Reader; + writer.Dispose(); + return ir; + } + + // try again + writer.DeleteAll(); + } + } + + // [Test] // LUCENENET NOTE: For now, we are overriding this test in every subclass to pull it into the right context for the subclass + public virtual void TestPad() + { + int[] tests = new int[] { -9999999, -99560, -100, -3, -1, 0, 3, 9, 10, 1000, 999999999 }; + for (int i = 0; i < tests.Length - 1; i++) + { + int a = tests[i]; + int b = tests[i + 1]; + string aa = Pad(a); + string bb = Pad(b); + string label = a + ":" + aa + " vs " + b + ":" + bb; + Assert.AreEqual(aa.Length, bb.Length, "i=" + i + ": length of " + label); + Assert.IsTrue(System.String.Compare(aa, bb, System.StringComparison.Ordinal) < 0, "i=" + i + ": compare less than " + label); + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/lucenenet/blob/96822396/src/Lucene.Net.Tests/Search/FuzzyTermOnShortTermsTest.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests/Search/FuzzyTermOnShortTermsTest.cs b/src/Lucene.Net.Tests/Search/FuzzyTermOnShortTermsTest.cs new file mode 100644 index 0000000..5638f8a --- /dev/null +++ b/src/Lucene.Net.Tests/Search/FuzzyTermOnShortTermsTest.cs @@ -0,0 +1,118 @@ +/* + * 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.Documents; + +namespace Lucene.Net.Search +{ + using NUnit.Framework; + using System.IO; + using Analyzer = Lucene.Net.Analysis.Analyzer; + using Directory = Lucene.Net.Store.Directory; + using DirectoryReader = Lucene.Net.Index.DirectoryReader; + using Document = Documents.Document; + using Field = Field; + using IndexReader = Lucene.Net.Index.IndexReader; + using LuceneTestCase = Lucene.Net.Util.LuceneTestCase; + using MockTokenizer = Lucene.Net.Analysis.MockTokenizer; + using RandomIndexWriter = Lucene.Net.Index.RandomIndexWriter; + using Term = Lucene.Net.Index.Term; + using TestUtil = Lucene.Net.Util.TestUtil; + using Tokenizer = Lucene.Net.Analysis.Tokenizer; + + [TestFixture] + public class FuzzyTermOnShortTermsTest : LuceneTestCase + { + private const string FIELD = "field"; + + [Test] + public virtual void Test() + { + // proves rule that edit distance between the two terms + // must be > smaller term for there to be a match + Analyzer a = Analyzer; + //these work + CountHits(a, new string[] { "abc" }, new FuzzyQuery(new Term(FIELD, "ab"), 1), 1); + CountHits(a, new string[] { "ab" }, new FuzzyQuery(new Term(FIELD, "abc"), 1), 1); + + CountHits(a, new string[] { "abcde" }, new FuzzyQuery(new Term(FIELD, "abc"), 2), 1); + CountHits(a, new string[] { "abc" }, new FuzzyQuery(new Term(FIELD, "abcde"), 2), 1); + + //these don't + CountHits(a, new string[] { "ab" }, new FuzzyQuery(new Term(FIELD, "a"), 1), 0); + CountHits(a, new string[] { "a" }, new FuzzyQuery(new Term(FIELD, "ab"), 1), 0); + + CountHits(a, new string[] { "abc" }, new FuzzyQuery(new Term(FIELD, "a"), 2), 0); + CountHits(a, new string[] { "a" }, new FuzzyQuery(new Term(FIELD, "abc"), 2), 0); + + CountHits(a, new string[] { "abcd" }, new FuzzyQuery(new Term(FIELD, "ab"), 2), 0); + CountHits(a, new string[] { "ab" }, new FuzzyQuery(new Term(FIELD, "abcd"), 2), 0); + } + + private void CountHits(Analyzer analyzer, string[] docs, Query q, int expected) + { + Directory d = GetDirectory(analyzer, docs); + IndexReader r = DirectoryReader.Open(d); + IndexSearcher s = new IndexSearcher(r); + TotalHitCountCollector c = new TotalHitCountCollector(); + s.Search(q, c); + Assert.AreEqual(expected, c.TotalHits, q.ToString()); + r.Dispose(); + d.Dispose(); + } + + public static Analyzer Analyzer + { + get + { + return new AnalyzerAnonymousInnerClassHelper(); + } + } + + private class AnalyzerAnonymousInnerClassHelper : Analyzer + { + public AnalyzerAnonymousInnerClassHelper() + { + } + + protected internal override TokenStreamComponents CreateComponents(string fieldName, TextReader reader) + { + Tokenizer tokenizer = new MockTokenizer(reader, MockTokenizer.SIMPLE, true); + return new TokenStreamComponents(tokenizer, tokenizer); + } + } + + /// + /// LUCENENET specific + /// Is non-static because NewIndexWriterConfig is no longer static. + /// + public Directory GetDirectory(Analyzer analyzer, string[] vals) + { + Directory directory = NewDirectory(); + RandomIndexWriter writer = new RandomIndexWriter(Random(), directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer).SetMaxBufferedDocs(TestUtil.NextInt(Random(), 100, 1000)).SetMergePolicy(NewLogMergePolicy())); + + foreach (string s in vals) + { + Document d = new Document(); + d.Add(NewTextField(FIELD, s, Field.Store.YES)); + writer.AddDocument(d); + } + writer.Dispose(); + return directory; + } + } +} \ No newline at end of file