lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r905372 - /lucene/lucene.net/trunk/C#/src/Test/TestSupportClass.cs
Date Mon, 01 Feb 2010 19:00:11 GMT
Author: digy
Date: Mon Feb  1 19:00:11 2010
New Revision: 905372

URL: http://svn.apache.org/viewvc?rev=905372&view=rev
Log:
LUCENENET-338 Serialized queries function unreliably

Modified:
    lucene/lucene.net/trunk/C#/src/Test/TestSupportClass.cs

Modified: lucene/lucene.net/trunk/C#/src/Test/TestSupportClass.cs
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/src/Test/TestSupportClass.cs?rev=905372&r1=905371&r2=905372&view=diff
==============================================================================
--- lucene/lucene.net/trunk/C#/src/Test/TestSupportClass.cs (original)
+++ lucene/lucene.net/trunk/C#/src/Test/TestSupportClass.cs Mon Feb  1 19:00:11 2010
@@ -1017,6 +1017,79 @@
         //-------------------------------------------
     }
 
+    [TestFixture]
+    public class TestSerialization
+    {
+        Lucene.Net.Store.RAMDirectory dir = null;
+
+        [SetUp]
+        public void Setup()
+        {
+            dir = new Lucene.Net.Store.RAMDirectory();
+            Index();
+        }
+
+        void Index()
+        {
+            Lucene.Net.Index.IndexWriter wr = new Lucene.Net.Index.IndexWriter(dir, new Lucene.Net.Analysis.WhitespaceAnalyzer(),
Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED);
+
+            Lucene.Net.Documents.Document doc = null;
+            Lucene.Net.Documents.Field f = null;
+
+            doc = new Lucene.Net.Documents.Document();
+            f = new Lucene.Net.Documents.Field("field", "a b c d", Lucene.Net.Documents.Field.Store.NO,
Lucene.Net.Documents.Field.Index.ANALYZED);
+            doc.Add(f);
+            wr.AddDocument(doc);
+
+            doc = new Lucene.Net.Documents.Document();
+            f = new Lucene.Net.Documents.Field("field", "a b a d", Lucene.Net.Documents.Field.Store.NO,
Lucene.Net.Documents.Field.Index.ANALYZED);
+            doc.Add(f);
+            wr.AddDocument(doc);
+
+            doc = new Lucene.Net.Documents.Document();
+            f = new Lucene.Net.Documents.Field("field", "a b e f", Lucene.Net.Documents.Field.Store.NO,
Lucene.Net.Documents.Field.Index.ANALYZED);
+            doc.Add(f);
+            wr.AddDocument(doc);
+            
+            doc = new Lucene.Net.Documents.Document();
+            f = new Lucene.Net.Documents.Field("field", "x y z", Lucene.Net.Documents.Field.Store.NO,
Lucene.Net.Documents.Field.Index.ANALYZED);
+            doc.Add(f);
+            wr.AddDocument(doc);
+            
+            wr.Close();
+        }
+
+
+        [Test]
+        [Description("LUCENENET-338  (also see LUCENENET-170)")]
+        public void TestBooleanQuerySerialization()
+        {
+            Lucene.Net.Search.BooleanQuery lucQuery = new Lucene.Net.Search.BooleanQuery();
+
+            lucQuery.Add(new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("field",
"x")), Lucene.Net.Search.BooleanClause.Occur.MUST);
+            
+            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
+            System.IO.MemoryStream ms = new System.IO.MemoryStream();
+            bf.Serialize(ms, lucQuery);
+            ms.Seek(0, System.IO.SeekOrigin.Begin);
+            Lucene.Net.Search.BooleanQuery lucQuery2 = (Lucene.Net.Search.BooleanQuery)bf.Deserialize(ms);
+            ms.Close();
+
+            Assert.AreEqual(lucQuery, lucQuery2, "Error in serialization");
+
+            Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(dir,
true);
+
+            int hitCount = searcher.Search(lucQuery, 20).totalHits;
+            
+            searcher.Close();
+            searcher = new Lucene.Net.Search.IndexSearcher(dir, true);
+
+            int hitCount2 = searcher.Search(lucQuery2, 20).totalHits;
+
+            Assert.AreEqual(hitCount, hitCount2,"Error in serialization - different hit counts");
+        }
+    }
+
 }
 
 



Mime
View raw message