lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [27/49] lucenenet git commit: Ported Core.TestSearchForDuplicates
Date Sun, 02 Oct 2016 10:16:58 GMT
Ported Core.TestSearchForDuplicates


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

Branch: refs/heads/master
Commit: 0e77936c82232bbcea94dcc1f59e98fc7961fa6a
Parents: 2c3dbc6
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sun Sep 11 03:19:31 2016 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Sun Sep 11 04:19:43 2016 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Tests/Lucene.Net.Tests.csproj    |   1 +
 .../core/TestSearchForDuplicates.cs             | 275 +++++++++----------
 2 files changed, 138 insertions(+), 138 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/0e77936c/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 289905b..a20ba5c 100644
--- a/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj
+++ b/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj
@@ -433,6 +433,7 @@
       <SubType>Code</SubType>
     </Compile>
     <Compile Include="core\TestSearch.cs" />
+    <Compile Include="core\TestSearchForDuplicates.cs" />
     <Compile Include="core\Util\Automaton\TestBasicOperations.cs">
       <SubType>Code</SubType>
     </Compile>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/0e77936c/src/Lucene.Net.Tests/core/TestSearchForDuplicates.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/TestSearchForDuplicates.cs b/src/Lucene.Net.Tests/core/TestSearchForDuplicates.cs
index 7b4f114..ec97868 100644
--- a/src/Lucene.Net.Tests/core/TestSearchForDuplicates.cs
+++ b/src/Lucene.Net.Tests/core/TestSearchForDuplicates.cs
@@ -1,9 +1,15 @@
+using Lucene.Net.Analysis;
+using Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
+using NUnit.Framework;
 using System;
+using System.IO;
 
-namespace org.apache.lucene
+namespace Lucene.Net
 {
-
-	/*
+    /*
 	 * 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.
@@ -20,139 +26,132 @@ namespace org.apache.lucene
 	 * limitations under the License.
 	 */
 
-
-	using Lucene.Net.Store;
-	using Lucene.Net.Document;
-	using Lucene.Net.Analysis;
-	using Lucene.Net.Index;
-	using Lucene.Net.Search;
-	using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
-    using NUnit.Framework;
-
-	public class TestSearchForDuplicates : LuceneTestCase
-	{
-
-	  internal const string PRIORITY_FIELD = "priority";
-	  internal const string ID_FIELD = "id";
-	  internal const string HIGH_PRIORITY = "high";
-	  internal const string MED_PRIORITY = "medium";
-	  internal const string LOW_PRIORITY = "low";
-
-
-	  /// <summary>
-	  /// this test compares search results when using and not using compound
-	  ///  files.
-	  /// 
-	  ///  TODO: There is rudimentary search result validation as well, but it is
-	  ///        simply based on asserting the output observed in the old test case,
-	  ///        without really knowing if the output is correct. Someone needs to
-	  ///        validate this output and make any changes to the checkHits method.
-	  /// </summary>
-	  public virtual void TestRun()
-	  {
-		  StringWriter sw = new StringWriter();
-		  PrintWriter pw = new PrintWriter(sw, true);
-		  int MAX_DOCS = atLeast(225);
-		  DoTest(random(), pw, false, MAX_DOCS);
-		  pw.close();
-		  sw.close();
-		  string multiFileOutput = sw.ToString();
-		  //System.out.println(multiFileOutput);
-
-		  sw = new StringWriter();
-		  pw = new PrintWriter(sw, true);
-		  DoTest(random(), pw, true, MAX_DOCS);
-		  pw.close();
-		  sw.close();
-		  string singleFileOutput = sw.ToString();
-
-		  Assert.AreEqual(multiFileOutput, singleFileOutput);
-	  }
-
-
-	  private void DoTest(Random random, PrintWriter @out, bool useCompoundFiles, int MAX_DOCS)
-	  {
-		  Directory directory = newDirectory();
-		  Analyzer analyzer = new MockAnalyzer(random);
-		  IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
-		  MergePolicy mp = conf.MergePolicy;
-		  mp.NoCFSRatio = useCompoundFiles ? 1.0 : 0.0;
-		  IndexWriter writer = new IndexWriter(directory, conf);
-		  if (VERBOSE)
-		  {
-			Console.WriteLine("TEST: now build index MAX_DOCS=" + MAX_DOCS);
-		  }
-
-		  for (int j = 0; j < MAX_DOCS; j++)
-		  {
-			Document d = new Document();
-			d.Add(newTextField(PRIORITY_FIELD, HIGH_PRIORITY, Field.Store.YES));
-			d.Add(newTextField(ID_FIELD, Convert.ToString(j), Field.Store.YES));
-			writer.addDocument(d);
-		  }
-		  writer.Dispose();
-
-		  // try a search without OR
-		  IndexReader reader = DirectoryReader.Open(directory);
-		  IndexSearcher searcher = newSearcher(reader);
-
-		  Query query = new TermQuery(new Term(PRIORITY_FIELD, HIGH_PRIORITY));
-		  @out.println("Query: " + query.ToString(PRIORITY_FIELD));
-		  if (VERBOSE)
-		  {
-			Console.WriteLine("TEST: search query=" + query);
-		  }
-
-		  Sort sort = new Sort(SortField.FIELD_SCORE, new SortField(ID_FIELD, SortField.Type.INT));
-
-		  ScoreDoc[] hits = searcher.Search(query, null, MAX_DOCS, sort).scoreDocs;
-		  PrintHits(@out, hits, searcher);
-		  CheckHits(hits, MAX_DOCS, searcher);
-
-		  // try a new search with OR
-		  searcher = newSearcher(reader);
-		  hits = null;
-
-		  BooleanQuery booleanQuery = new BooleanQuery();
-		  booleanQuery.Add(new TermQuery(new Term(PRIORITY_FIELD, HIGH_PRIORITY)), BooleanClause.Occur_e.SHOULD);
-		  booleanQuery.Add(new TermQuery(new Term(PRIORITY_FIELD, MED_PRIORITY)), BooleanClause.Occur_e.SHOULD);
-		  @out.println("Query: " + booleanQuery.ToString(PRIORITY_FIELD));
-
-		  hits = searcher.search(booleanQuery, null, MAX_DOCS, sort).scoreDocs;
-		  PrintHits(@out, hits, searcher);
-		  CheckHits(hits, MAX_DOCS, searcher);
-
-		  reader.Close();
-		  directory.Close();
-	  }
-
-
-	  private void PrintHits(PrintWriter @out, ScoreDoc[] hits, IndexSearcher searcher)
-	  {
-		@out.println(hits.Length + " total results\n");
-		for (int i = 0 ; i < hits.Length; i++)
-		{
-		  if (i < 10 || (i > 94 && i < 105))
-		  {
-			Document d = searcher.Doc(hits[i].Doc);
-			@out.println(i + " " + d.Get(ID_FIELD));
-		  }
-		}
-	  }
-
-	  private void CheckHits(ScoreDoc[] hits, int expectedCount, IndexSearcher searcher)
-	  {
-		Assert.AreEqual(expectedCount, hits.Length, "total results");
-		for (int i = 0 ; i < hits.Length; i++)
-		{
-		  if (i < 10 || (i > 94 && i < 105))
-		  {
-			Document d = searcher.Doc(hits[i].Doc);
-			Assert.AreEqual(Convert.ToString(i), d.Get(ID_FIELD), "check " + i);
-		  }
-		}
-	  }
-
-	}
-
+    public class TestSearchForDuplicates : LuceneTestCase
+    {
+
+        internal const string PRIORITY_FIELD = "priority";
+        internal const string ID_FIELD = "id";
+        internal const string HIGH_PRIORITY = "high";
+        internal const string MED_PRIORITY = "medium";
+        internal const string LOW_PRIORITY = "low";
+
+
+        /// <summary>
+        /// this test compares search results when using and not using compound
+        ///  files.
+        /// 
+        ///  TODO: There is rudimentary search result validation as well, but it is
+        ///        simply based on asserting the output observed in the old test case,
+        ///        without really knowing if the output is correct. Someone needs to
+        ///        validate this output and make any changes to the checkHits method.
+        /// </summary>
+        [Test]
+        public void TestRun()
+        {
+            StringWriter sw;
+            string multiFileOutput;
+            string singleFileOutput;
+            int MAX_DOCS = AtLeast(225);
+
+            using (sw = new StringWriter())
+            {
+                DoTest(Random(), sw, false, MAX_DOCS);
+                multiFileOutput = sw.ToString();
+            }
+
+            //System.out.println(multiFileOutput);
+
+            using (sw = new StringWriter())
+            {
+                DoTest(Random(), sw, true, MAX_DOCS);
+                singleFileOutput = sw.ToString();
+            }
+
+            Assert.AreEqual(multiFileOutput, singleFileOutput);
+        }
+
+
+        private void DoTest(Random random, TextWriter @out, bool useCompoundFiles, int MAX_DOCS)
+        {
+            Store.Directory directory = NewDirectory();
+            Analyzer analyzer = new MockAnalyzer(random);
+            IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
+            MergePolicy mp = conf.MergePolicy;
+            mp.NoCFSRatio = useCompoundFiles ? 1.0 : 0.0;
+            IndexWriter writer = new IndexWriter(directory, conf);
+            if (VERBOSE)
+            {
+                Console.WriteLine("TEST: now build index MAX_DOCS=" + MAX_DOCS);
+            }
+
+            for (int j = 0; j < MAX_DOCS; j++)
+            {
+                Documents.Document d = new Documents.Document();
+                d.Add(NewTextField(PRIORITY_FIELD, HIGH_PRIORITY, Field.Store.YES));
+                d.Add(NewTextField(ID_FIELD, Convert.ToString(j), Field.Store.YES));
+                writer.AddDocument(d);
+            }
+            writer.Dispose();
+
+            // try a search without OR
+            IndexReader reader = DirectoryReader.Open(directory);
+            IndexSearcher searcher = NewSearcher(reader);
+
+            Query query = new TermQuery(new Term(PRIORITY_FIELD, HIGH_PRIORITY));
+            @out.WriteLine("Query: " + query.ToString(PRIORITY_FIELD));
+            if (VERBOSE)
+            {
+                Console.WriteLine("TEST: search query=" + query);
+            }
+
+            Sort sort = new Sort(SortField.FIELD_SCORE, new SortField(ID_FIELD, SortField.Type_e.INT));
+
+            ScoreDoc[] hits = searcher.Search(query, null, MAX_DOCS, sort).ScoreDocs;
+            PrintHits(@out, hits, searcher);
+            CheckHits(hits, MAX_DOCS, searcher);
+
+            // try a new search with OR
+            searcher = NewSearcher(reader);
+            hits = null;
+
+            BooleanQuery booleanQuery = new BooleanQuery();
+            booleanQuery.Add(new TermQuery(new Term(PRIORITY_FIELD, HIGH_PRIORITY)), BooleanClause.Occur.SHOULD);
+            booleanQuery.Add(new TermQuery(new Term(PRIORITY_FIELD, MED_PRIORITY)), BooleanClause.Occur.SHOULD);
+            @out.WriteLine("Query: " + booleanQuery.ToString(PRIORITY_FIELD));
+
+            hits = searcher.Search(booleanQuery, null, MAX_DOCS, sort).ScoreDocs;
+            PrintHits(@out, hits, searcher);
+            CheckHits(hits, MAX_DOCS, searcher);
+
+            reader.Dispose();
+            directory.Dispose();
+        }
+
+
+        private void PrintHits(TextWriter @out, ScoreDoc[] hits, IndexSearcher searcher)
+        {
+            @out.WriteLine(hits.Length + " total results\n");
+            for (int i = 0; i < hits.Length; i++)
+            {
+                if (i < 10 || (i > 94 && i < 105))
+                {
+                    Documents.Document d = searcher.Doc(hits[i].Doc);
+                    @out.WriteLine(i + " " + d.Get(ID_FIELD));
+                }
+            }
+        }
+
+        private void CheckHits(ScoreDoc[] hits, int expectedCount, IndexSearcher searcher)
+        {
+            Assert.AreEqual(expectedCount, hits.Length, "total results");
+            for (int i = 0; i < hits.Length; i++)
+            {
+                if (i < 10 || (i > 94 && i < 105))
+                {
+                    Documents.Document d = searcher.Doc(hits[i].Doc);
+                    Assert.AreEqual(Convert.ToString(i), d.Get(ID_FIELD), "check " + i);
+                }
+            }
+        }
+    }
 }
\ No newline at end of file


Mime
View raw message