You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by cc...@apache.org on 2012/02/28 23:43:28 UTC
[Lucene.Net] svn commit: r1294875 [44/45] - in /incubator/lucene.net/trunk: ./ build/
build/vs2010/contrib/ build/vs2010/test/ doc/ src/ src/contrib/Analyzers/
src/contrib/Analyzers/AR/ src/contrib/Analyzers/BR/
src/contrib/Analyzers/CJK/ src/contrib/Analyzers/Cn/ ...
Modified: incubator/lucene.net/trunk/test/core/Search/TestTermScorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Search/TestTermScorer.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Search/TestTermScorer.cs (original)
+++ incubator/lucene.net/trunk/test/core/Search/TestTermScorer.cs Tue Feb 28 22:43:08 2012
@@ -102,7 +102,7 @@ namespace Lucene.Net.Search
writer.AddDocument(doc);
}
writer.Close();
- indexSearcher = new IndexSearcher(directory);
+ indexSearcher = new IndexSearcher(directory, false);
indexReader = indexSearcher.GetIndexReader();
}
@@ -179,46 +179,6 @@ namespace Lucene.Net.Search
Assert.IsTrue(ts.DocID() == 5, "doc should be number 5");
}
- [Test]
- public virtual void TestExplain()
- {
- Term allTerm = new Term(FIELD, "all");
- TermQuery termQuery = new TermQuery(allTerm);
-
- Weight weight = termQuery.Weight(indexSearcher);
-
- TermScorer ts = new TermScorer(weight, indexReader.TermDocs(allTerm), indexSearcher.GetSimilarity(), indexReader.Norms(FIELD));
- Explanation explanation = ts.Explain(0);
- Assert.IsTrue(explanation != null, "explanation is null and it shouldn't be");
- //System.out.println("Explanation: " + explanation.toString());
- //All this Explain does is return the term frequency
- Assert.IsTrue(explanation.GetValue() == 1, "term frq is not 1");
- explanation = ts.Explain(1);
- Assert.IsTrue(explanation != null, "explanation is null and it shouldn't be");
- //System.out.println("Explanation: " + explanation.toString());
- //All this Explain does is return the term frequency
- Assert.IsTrue(explanation.GetValue() == 0, "term frq is not 0");
-
- Term dogsTerm = new Term(FIELD, "dogs");
- termQuery = new TermQuery(dogsTerm);
- weight = termQuery.Weight(indexSearcher);
-
- ts = new TermScorer(weight, indexReader.TermDocs(dogsTerm), indexSearcher.GetSimilarity(), indexReader.Norms(FIELD));
- explanation = ts.Explain(1);
- Assert.IsTrue(explanation != null, "explanation is null and it shouldn't be");
- //System.out.println("Explanation: " + explanation.toString());
- //All this Explain does is return the term frequency
- float sqrtTwo = (float) System.Math.Sqrt(2.0f);
- Assert.IsTrue(explanation.GetValue() == sqrtTwo, "term frq: " + explanation.GetValue() + " is not the square root of 2");
-
- explanation = ts.Explain(10); //try a doc out of range
- Assert.IsTrue(explanation != null, "explanation is null and it shouldn't be");
- //System.out.println("Explanation: " + explanation.toString());
- //All this Explain does is return the term frequency
-
- Assert.IsTrue(explanation.GetValue() == 0, "term frq: " + explanation.GetValue() + " is not 0");
- }
-
private class TestHit
{
private void InitBlock(TestTermScorer enclosingInstance)
Modified: incubator/lucene.net/trunk/test/core/Search/TestTermVectors.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Search/TestTermVectors.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Search/TestTermVectors.cs (original)
+++ incubator/lucene.net/trunk/test/core/Search/TestTermVectors.cs Tue Feb 28 22:43:08 2012
@@ -70,7 +70,7 @@ namespace Lucene.Net.Search
writer.AddDocument(doc);
}
writer.Close();
- searcher = new IndexSearcher(directory);
+ searcher = new IndexSearcher(directory, true);
}
[Test]
@@ -113,7 +113,7 @@ namespace Lucene.Net.Search
doc.Add(new Field("x", "some content here", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
writer.AddDocument(doc);
writer.Close();
- IndexReader reader = IndexReader.Open(dir);
+ IndexReader reader = IndexReader.Open(dir, true);
TermFreqVector[] v = reader.GetTermFreqVectors(0);
Assert.AreEqual(4, v.Length);
System.String[] expectedFields = new System.String[]{"a", "b", "c", "x"};
@@ -271,7 +271,7 @@ namespace Lucene.Net.Search
writer.AddDocument(testDoc3);
writer.AddDocument(testDoc4);
writer.Close();
- IndexSearcher knownSearcher = new IndexSearcher(dir);
+ IndexSearcher knownSearcher = new IndexSearcher(dir, true);
TermEnum termEnum = knownSearcher.reader_ForNUnit.Terms();
TermDocs termDocs = knownSearcher.reader_ForNUnit.TermDocs();
//System.out.println("Terms: " + termEnum.size() + " Orig Len: " + termArray.length);
@@ -289,7 +289,7 @@ namespace Lucene.Net.Search
//System.out.println("Doc Id: " + docId + " freq " + freq);
TermFreqVector vector = knownSearcher.reader_ForNUnit.GetTermFreqVector(docId, "field");
float tf = sim.Tf(freq);
- float idf = sim.Idf(term, knownSearcher);
+ float idf = sim.Idf(knownSearcher.DocFreq(term), knownSearcher.MaxDoc());
//float qNorm = sim.queryNorm()
//This is fine since we don't have stop words
float lNorm = sim.LengthNorm("field", vector.GetTerms().Length);
@@ -347,10 +347,10 @@ namespace Lucene.Net.Search
}
SortedTermVectorMapper mapper = new SortedTermVectorMapper(new TermVectorEntryFreqSortedComparator());
knownSearcher.reader_ForNUnit.GetTermFreqVector(hits[1].doc, mapper);
- System.Collections.Generic.SortedDictionary<object, object> vectorEntrySet = mapper.GetTermVectorEntrySet();
+ var vectorEntrySet = mapper.GetTermVectorEntrySet();
Assert.IsTrue(vectorEntrySet.Count == 10, "mapper.getTermVectorEntrySet() Size: " + vectorEntrySet.Count + " is not: " + 10);
TermVectorEntry last = null;
- foreach(TermVectorEntry tve in vectorEntrySet.Keys)
+ foreach(TermVectorEntry tve in vectorEntrySet)
{
if (tve != null && last != null)
{
@@ -364,9 +364,9 @@ namespace Lucene.Net.Search
FieldSortedTermVectorMapper fieldMapper = new FieldSortedTermVectorMapper(new TermVectorEntryFreqSortedComparator());
knownSearcher.reader_ForNUnit.GetTermFreqVector(hits[1].doc, fieldMapper);
- System.Collections.IDictionary map = fieldMapper.GetFieldToTerms();
+ var map = fieldMapper.GetFieldToTerms();
Assert.IsTrue(map.Count == 2, "map Size: " + map.Count + " is not: " + 2);
- vectorEntrySet = (System.Collections.Generic.SortedDictionary<Object,Object>) map["field"];
+ vectorEntrySet = map["field"];
Assert.IsTrue(vectorEntrySet != null, "vectorEntrySet is null and it shouldn't be");
Assert.IsTrue(vectorEntrySet.Count == 10, "vectorEntrySet Size: " + vectorEntrySet.Count + " is not: " + 10);
knownSearcher.Close();
@@ -404,7 +404,7 @@ namespace Lucene.Net.Search
}
writer.Close();
- searcher = new IndexSearcher(directory);
+ searcher = new IndexSearcher(directory, true);
Query query = new TermQuery(new Term("field", "hundred"));
ScoreDoc[] hits = searcher.Search(query, null, 1000).ScoreDocs;
@@ -432,8 +432,8 @@ namespace Lucene.Net.Search
doc.Add(new Field("field", "one", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
writer.AddDocument(doc);
writer.Close();
-
- searcher = new IndexSearcher(directory);
+
+ searcher = new IndexSearcher(directory, true);
Query query = new TermQuery(new Term("field", "one"));
ScoreDoc[] hits = searcher.Search(query, null, 1000).ScoreDocs;
Modified: incubator/lucene.net/trunk/test/core/Search/TestThreadSafe.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Search/TestThreadSafe.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Search/TestThreadSafe.cs (original)
+++ incubator/lucene.net/trunk/test/core/Search/TestThreadSafe.cs Tue Feb 28 22:43:08 2012
@@ -16,7 +16,7 @@
*/
using System;
-
+using Lucene.Net.Support;
using NUnit.Framework;
using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
@@ -29,10 +29,6 @@ using LuceneTestCase = Lucene.Net.Util.L
namespace Lucene.Net.Search
{
-
- /// <summary> </summary>
- /// <version> $Id: TestThreadSafe.java 741311 2009-02-05 21:53:40Z mikemccand $
- /// </version>
[TestFixture]
public class TestThreadSafe:LuceneTestCase
{
@@ -46,7 +42,7 @@ namespace Lucene.Net.Search
internal System.String failure = null;
- internal class Thr:SupportClass.ThreadClass
+ internal class Thr:ThreadClass
{
[Serializable]
private class AnonymousClassFieldSelector : FieldSelector
@@ -137,10 +133,10 @@ namespace Lucene.Net.Search
// beware of deleted docs in the future
Document doc = ir.Document(rand.Next(ir.MaxDoc()), new AnonymousClassFieldSelector(this));
- System.Collections.IList fields = doc.GetFields();
+ var fields = doc.GetFields();
for (int i = 0; i < fields.Count; i++)
{
- Fieldable f = (Fieldable) fields[i];
+ Fieldable f = fields[i];
Enclosing_Instance.ValidateField(f);
}
}
@@ -212,7 +208,7 @@ namespace Lucene.Net.Search
// do many small tests so the thread locals go away inbetween
for (int i = 0; i < 100; i++)
{
- ir1 = IndexReader.Open(dir1);
+ ir1 = IndexReader.Open(dir1, false);
DoTest(10, 100);
}
}
Modified: incubator/lucene.net/trunk/test/core/Search/TestTimeLimitingCollector.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Search/TestTimeLimitingCollector.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Search/TestTimeLimitingCollector.cs (original)
+++ incubator/lucene.net/trunk/test/core/Search/TestTimeLimitingCollector.cs Tue Feb 28 22:43:08 2012
@@ -16,7 +16,7 @@
*/
using System;
-
+using Lucene.Net.Support;
using NUnit.Framework;
using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
@@ -41,7 +41,7 @@ namespace Lucene.Net.Search
[TestFixture]
public class TestTimeLimitingCollector:LuceneTestCase
{
- private class AnonymousClassThread:SupportClass.ThreadClass
+ private class AnonymousClassThread:ThreadClass
{
public AnonymousClassThread(bool withTimeout, System.Collections.BitArray success, int num, TestTimeLimitingCollector enclosingInstance)
{
@@ -115,14 +115,15 @@ namespace Lucene.Net.Search
Add(docText[i % docText.Length], iw);
}
iw.Close();
- searcher = new IndexSearcher(directory);
+ searcher = new IndexSearcher(directory, true);
System.String qtxt = "one";
+ // start from 1, so that the 0th doc never matches
for (int i = 0; i < docText.Length; i++)
{
qtxt += (' ' + docText[i]); // large query so that search will be longer
}
- QueryParser queryParser = new QueryParser(FIELD_NAME, new WhitespaceAnalyzer());
+ QueryParser queryParser = new QueryParser(Util.Version.LUCENE_CURRENT, FIELD_NAME, new WhitespaceAnalyzer());
query = queryParser.Parse(qtxt);
// warm the searcher
@@ -316,7 +317,7 @@ namespace Lucene.Net.Search
private void DoTestMultiThreads(bool withTimeout)
{
- SupportClass.ThreadClass[] threadArray = new SupportClass.ThreadClass[N_THREADS];
+ ThreadClass[] threadArray = new ThreadClass[N_THREADS];
System.Collections.BitArray success = new System.Collections.BitArray((N_THREADS % 64 == 0?N_THREADS / 64:N_THREADS / 64 + 1) * 64);
for (int i = 0; i < threadArray.Length; ++i)
{
@@ -331,7 +332,7 @@ namespace Lucene.Net.Search
{
threadArray[i].Join();
}
- Assert.AreEqual(N_THREADS, SupportClass.BitSetSupport.Cardinality(success), "some threads failed!");
+ Assert.AreEqual(N_THREADS, BitSetSupport.Cardinality(success), "some threads failed!");
}
// counting collector that can slow down at collect().
@@ -367,7 +368,7 @@ namespace Lucene.Net.Search
public virtual int HitCount()
{
- return SupportClass.BitSetSupport.Cardinality(bits);
+ return BitSetSupport.Cardinality(bits);
}
public virtual int GetLastDocCollected()
@@ -391,8 +392,7 @@ namespace Lucene.Net.Search
}
catch (System.Threading.ThreadInterruptedException ie)
{
- SupportClass.ThreadClass.Current().Interrupt();
- throw new System.SystemException("", ie);
+ throw;
}
}
System.Diagnostics.Debug.Assert(docId >= 0, "base=" + docBase + " doc=" + doc);
Modified: incubator/lucene.net/trunk/test/core/Search/TestTopDocsCollector.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Search/TestTopDocsCollector.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Search/TestTopDocsCollector.cs (original)
+++ incubator/lucene.net/trunk/test/core/Search/TestTopDocsCollector.cs Tue Feb 28 22:43:08 2012
@@ -34,8 +34,8 @@ namespace Lucene.Net.Search
[TestFixture]
public class TestTopDocsCollector:LuceneTestCase
{
-
- private sealed class MyTopsDocCollector:TopDocsCollector
+
+ private sealed class MyTopsDocCollector : TopDocsCollector<ScoreDoc>
{
private int idx = 0;
@@ -63,7 +63,7 @@ namespace Lucene.Net.Search
{
pq.Pop();
}
- maxScore = ((ScoreDoc) pq.Pop()).score;
+ maxScore = pq.Pop().score;
}
return new TopDocs(totalHits, results, maxScore);
@@ -99,11 +99,11 @@ namespace Lucene.Net.Search
private Directory dir = new RAMDirectory();
- private TopDocsCollector doSearch(int numResults)
+ private TopDocsCollector<ScoreDoc> doSearch(int numResults)
{
Query q = new MatchAllDocsQuery();
- IndexSearcher searcher = new IndexSearcher(dir);
- TopDocsCollector tdc = new MyTopsDocCollector(numResults);
+ IndexSearcher searcher = new IndexSearcher(dir, true);
+ TopDocsCollector<ScoreDoc> tdc = new MyTopsDocCollector(numResults);
searcher.Search(q, tdc);
searcher.Close();
return tdc;
@@ -137,7 +137,7 @@ namespace Lucene.Net.Search
public virtual void TestInvalidArguments()
{
int numResults = 5;
- TopDocsCollector tdc = doSearch(numResults);
+ TopDocsCollector<ScoreDoc> tdc = doSearch(numResults);
// start < 0
Assert.AreEqual(0, tdc.TopDocs(- 1).ScoreDocs.Length);
@@ -158,21 +158,21 @@ namespace Lucene.Net.Search
[Test]
public virtual void TestZeroResults()
{
- TopDocsCollector tdc = new MyTopsDocCollector(5);
+ TopDocsCollector<ScoreDoc> tdc = new MyTopsDocCollector(5);
Assert.AreEqual(0, tdc.TopDocs(0, 1).ScoreDocs.Length);
}
[Test]
public virtual void TestFirstResultsPage()
{
- TopDocsCollector tdc = doSearch(15);
+ TopDocsCollector<ScoreDoc> tdc = doSearch(15);
Assert.AreEqual(10, tdc.TopDocs(0, 10).ScoreDocs.Length);
}
[Test]
public virtual void TestSecondResultsPages()
{
- TopDocsCollector tdc = doSearch(15);
+ TopDocsCollector<ScoreDoc> tdc = doSearch(15);
// ask for more results than are available
Assert.AreEqual(5, tdc.TopDocs(10, 10).ScoreDocs.Length);
@@ -188,14 +188,14 @@ namespace Lucene.Net.Search
[Test]
public virtual void TestGetAllResults()
{
- TopDocsCollector tdc = doSearch(15);
+ TopDocsCollector<ScoreDoc> tdc = doSearch(15);
Assert.AreEqual(15, tdc.TopDocs().ScoreDocs.Length);
}
[Test]
public virtual void TestGetResultsFromStart()
{
- TopDocsCollector tdc = doSearch(15);
+ TopDocsCollector<ScoreDoc> tdc = doSearch(15);
// should bring all results
Assert.AreEqual(15, tdc.TopDocs(0).ScoreDocs.Length);
@@ -208,7 +208,7 @@ namespace Lucene.Net.Search
public virtual void TestMaxScore()
{
// ask for all results
- TopDocsCollector tdc = doSearch(15);
+ TopDocsCollector<ScoreDoc> tdc = doSearch(15);
TopDocs td = tdc.TopDocs();
Assert.AreEqual(MAX_SCORE, td.GetMaxScore(), 0f);
@@ -223,7 +223,7 @@ namespace Lucene.Net.Search
[Test]
public virtual void TestResultsOrder()
{
- TopDocsCollector tdc = doSearch(15);
+ TopDocsCollector<ScoreDoc> tdc = doSearch(15);
ScoreDoc[] sd = tdc.TopDocs().ScoreDocs;
Assert.AreEqual(MAX_SCORE, sd[0].score, 0f);
Modified: incubator/lucene.net/trunk/test/core/Search/TestTopScoreDocCollector.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Search/TestTopScoreDocCollector.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Search/TestTopScoreDocCollector.cs (original)
+++ incubator/lucene.net/trunk/test/core/Search/TestTopScoreDocCollector.cs Tue Feb 28 22:43:08 2012
@@ -41,61 +41,46 @@ namespace Lucene.Net.Search
public TestTopScoreDocCollector(System.String name):base(name)
{
}
-
+
[Test]
- public virtual void TestOutOfOrderCollection()
- {
-
- Directory dir = new RAMDirectory();
- IndexWriter writer = new IndexWriter(dir, null, MaxFieldLength.UNLIMITED);
- for (int i = 0; i < 10; i++)
- {
- writer.AddDocument(new Document());
- }
- writer.Commit();
- writer.Close();
-
- bool[] inOrder = new bool[]{false, true};
- System.String[] actualTSDCClass = new System.String[]{"OutOfOrderTopScoreDocCollector", "InOrderTopScoreDocCollector"};
-
- // Save the original value to set later.
- bool origVal = BooleanQuery.GetAllowDocsOutOfOrder();
-
- BooleanQuery.SetAllowDocsOutOfOrder(true);
-
- BooleanQuery bq = new BooleanQuery();
- // Add a Query with SHOULD, since bw.scorer() returns BooleanScorer2
- // which delegates to BS if there are no mandatory clauses.
- bq.Add(new MatchAllDocsQuery(), Occur.SHOULD);
- // Set minNrShouldMatch to 1 so that BQ will not optimize rewrite to return
- // the clause instead of BQ.
- bq.SetMinimumNumberShouldMatch(1);
- try
- {
-
- IndexSearcher searcher = new IndexSearcher(dir);
- for (int i = 0; i < inOrder.Length; i++)
- {
- TopDocsCollector tdc = TopScoreDocCollector.create(3, inOrder[i]);
- Assert.AreEqual("Lucene.Net.Search.TopScoreDocCollector+" + actualTSDCClass[i], tdc.GetType().FullName);
-
- searcher.Search(new MatchAllDocsQuery(), tdc);
-
- ScoreDoc[] sd = tdc.TopDocs().ScoreDocs;
- Assert.AreEqual(3, sd.Length);
- for (int j = 0; j < sd.Length; j++)
- {
- Assert.AreEqual(j, sd[j].doc, "expected doc Id " + j + " found " + sd[j].doc);
- }
- }
- }
- finally
- {
- // Whatever happens, reset BooleanQuery.allowDocsOutOfOrder to the
- // original value. Don't set it to false in case the implementation in BQ
- // will change some day.
- BooleanQuery.SetAllowDocsOutOfOrder(origVal);
- }
- }
+ public virtual void TestOutOfOrderCollection()
+ {
+
+ Directory dir = new RAMDirectory();
+ IndexWriter writer = new IndexWriter(dir, null, MaxFieldLength.UNLIMITED);
+ for (int i = 0; i < 10; i++)
+ {
+ writer.AddDocument(new Document());
+ }
+ writer.Commit();
+ writer.Close();
+
+ bool[] inOrder = new bool[] {false, true};
+ System.String[] actualTSDCClass = new System.String[]
+ {"OutOfOrderTopScoreDocCollector", "InOrderTopScoreDocCollector"};
+
+ BooleanQuery bq = new BooleanQuery();
+ // Add a Query with SHOULD, since bw.scorer() returns BooleanScorer2
+ // which delegates to BS if there are no mandatory clauses.
+ bq.Add(new MatchAllDocsQuery(), Occur.SHOULD);
+ // Set minNrShouldMatch to 1 so that BQ will not optimize rewrite to return
+ // the clause instead of BQ.
+ bq.SetMinimumNumberShouldMatch(1);
+ IndexSearcher searcher = new IndexSearcher(dir, true);
+ for (int i = 0; i < inOrder.Length; i++)
+ {
+ TopDocsCollector<ScoreDoc> tdc = TopScoreDocCollector.create(3, inOrder[i]);
+ Assert.AreEqual("Lucene.Net.Search.TopScoreDocCollector+" + actualTSDCClass[i], tdc.GetType().FullName);
+
+ searcher.Search(new MatchAllDocsQuery(), tdc);
+
+ ScoreDoc[] sd = tdc.TopDocs().ScoreDocs;
+ Assert.AreEqual(3, sd.Length);
+ for (int j = 0; j < sd.Length; j++)
+ {
+ Assert.AreEqual(j, sd[j].doc, "expected doc Id " + j + " found " + sd[j].doc);
+ }
+ }
+ }
}
}
\ No newline at end of file
Modified: incubator/lucene.net/trunk/test/core/Search/TestWildcard.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Search/TestWildcard.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Search/TestWildcard.cs (original)
+++ incubator/lucene.net/trunk/test/core/Search/TestWildcard.cs Tue Feb 28 22:43:08 2012
@@ -34,12 +34,7 @@ using LuceneTestCase = Lucene.Net.Util.L
namespace Lucene.Net.Search
{
- /// <summary> TestWildcard tests the '*' and '?' wildcard characters.
- ///
- /// </summary>
- /// <version> $Id: TestWildcard.java 694004 2008-09-10 21:38:52Z mikemccand $
- ///
- /// </version>
+ /// <summary>TestWildcard tests the '*' and '?' wildcard characters.</summary>
[TestFixture]
public class TestWildcard:LuceneTestCase
{
@@ -66,27 +61,105 @@ namespace Lucene.Net.Search
}
/// <summary> Tests if a WildcardQuery that has no wildcard in the term is rewritten to a single
- /// TermQuery.
+ /// TermQuery. The boost should be prserved, and the rewrite should return
+ /// a ConstantScoreQuery if the WildcardQuery had a ConstantScore rewriteMethod.
/// </summary>
- [Test]
- public virtual void TestTermWithoutWildcard()
+ [Test]
+ public virtual void TestTermWithoutWildcard()
{
- RAMDirectory indexStore = GetIndexStore("field", new System.String[]{"nowildcard", "nowildcardx"});
- IndexSearcher searcher = new IndexSearcher(indexStore);
-
- Query wq = new WildcardQuery(new Term("field", "nowildcard"));
- AssertMatches(searcher, wq, 1);
-
- wq = searcher.Rewrite(wq);
- Assert.IsTrue(wq is TermQuery);
+ RAMDirectory indexStore = GetIndexStore("field", new System.String[] {"nowildcard", "nowildcardx"});
+ IndexSearcher searcher = new IndexSearcher(indexStore, true);
+
+ MultiTermQuery wq = new WildcardQuery(new Term("field", "nowildcard"));
+ AssertMatches(searcher, wq, 1);
+
+ wq.SetRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
+ wq.SetBoost(0.1f);
+ Query q = searcher.Rewrite(wq);
+ Assert.IsTrue(q is TermQuery);
+ Assert.AreEqual(q.GetBoost(), wq.GetBoost());
+
+ wq.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
+ wq.SetBoost(0.2f);
+ q = searcher.Rewrite(wq);
+ Assert.True(q is ConstantScoreQuery);
+ Assert.AreEqual(q.GetBoost(), wq.GetBoost());
+
+ wq.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT);
+ wq.SetBoost(0.3F);
+ q = searcher.Rewrite(wq);
+ Assert.True(q is ConstantScoreQuery);
+ Assert.AreEqual(q.GetBoost(), wq.GetBoost());
+
+ wq.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE);
+ wq.SetBoost(0.4F);
+ q = searcher.Rewrite(wq);
+ Assert.True(q is ConstantScoreQuery);
+ Assert.AreEqual(q.GetBoost(), wq.GetBoost());
}
-
- /// <summary> Tests Wildcard queries with an asterisk.</summary>
+
+ /// <summary>
+ /// Tests if a WildcardQuery with an empty term is rewritten to an empty BooleanQuery
+ /// </summary>
+ [Test]
+ public void TestEmptyTerm()
+ {
+ RAMDirectory indexStore = GetIndexStore("field", new String[] { "nowildcard", "nowildcardx" });
+ IndexSearcher searcher = new IndexSearcher(indexStore, true);
+
+ MultiTermQuery wq = new WildcardQuery(new Term("field", ""));
+ wq.SetRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
+ AssertMatches(searcher, wq, 0);
+ BooleanQuery expected = new BooleanQuery(true);
+ Assert.AreEqual(searcher.Rewrite(expected), searcher.Rewrite(wq));
+ }
+
+ /// <summary>
+ /// Tests if a WildcardQuery that has only a trailing * in the term is
+ /// rewritten to a single PrefixQuery. The boost and rewriteMethod should be
+ /// preserved.
+ /// </summary>
+ [Test]
+ public void TestPrefixTerm()
+ {
+ RAMDirectory indexStore = GetIndexStore("field", new String[] { "prefix", "prefixx" });
+ IndexSearcher searcher = new IndexSearcher(indexStore, true);
+
+ MultiTermQuery wq = new WildcardQuery(new Term("field", "prefix*"));
+ AssertMatches(searcher, wq, 2);
+
+ MultiTermQuery expected = new PrefixQuery(new Term("field", "prefix"));
+ wq.SetRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
+ wq.SetBoost(0.1F);
+ expected.SetRewriteMethod(wq.GetRewriteMethod());
+ expected.SetBoost(wq.GetBoost());
+ Assert.AreEqual(searcher.Rewrite(expected), searcher.Rewrite(wq));
+
+ wq.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
+ wq.SetBoost(0.2F);
+ expected.SetRewriteMethod(wq.GetRewriteMethod());
+ expected.SetBoost(wq.GetBoost());
+ Assert.AreEqual(searcher.Rewrite(expected), searcher.Rewrite(wq));
+
+ wq.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT);
+ wq.SetBoost(0.3F);
+ expected.SetRewriteMethod(wq.GetRewriteMethod());
+ expected.SetBoost(wq.GetBoost());
+ Assert.AreEqual(searcher.Rewrite(expected), searcher.Rewrite(wq));
+
+ wq.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE);
+ wq.SetBoost(0.4F);
+ expected.SetRewriteMethod(wq.GetRewriteMethod());
+ expected.SetBoost(wq.GetBoost());
+ Assert.AreEqual(searcher.Rewrite(expected), searcher.Rewrite(wq));
+ }
+
+ /// <summary> Tests Wildcard queries with an asterisk.</summary>
[Test]
public virtual void TestAsterisk()
{
RAMDirectory indexStore = GetIndexStore("body", new System.String[]{"metal", "metals"});
- IndexSearcher searcher = new IndexSearcher(indexStore);
+ IndexSearcher searcher = new IndexSearcher(indexStore, true);
Query query1 = new TermQuery(new Term("body", "metal"));
Query query2 = new WildcardQuery(new Term("body", "metal*"));
Query query3 = new WildcardQuery(new Term("body", "m*tal"));
@@ -145,7 +218,7 @@ namespace Lucene.Net.Search
public virtual void TestQuestionmark()
{
RAMDirectory indexStore = GetIndexStore("body", new System.String[]{"metal", "metals", "mXtals", "mXtXls"});
- IndexSearcher searcher = new IndexSearcher(indexStore);
+ IndexSearcher searcher = new IndexSearcher(indexStore, true);
Query query1 = new WildcardQuery(new Term("body", "m?tal"));
Query query2 = new WildcardQuery(new Term("body", "metal?"));
Query query3 = new WildcardQuery(new Term("body", "metals?"));
@@ -194,7 +267,7 @@ namespace Lucene.Net.Search
{
System.String field = "content";
bool dbg = false;
- QueryParser qp = new QueryParser(field, new WhitespaceAnalyzer());
+ QueryParser qp = new QueryParser(Util.Version.LUCENE_CURRENT, field, new WhitespaceAnalyzer());
qp.SetAllowLeadingWildcard(true);
System.String[] docs = new System.String[]{"\\ abcdefg1", "\\79 hijklmn1", "\\\\ opqrstu1"};
// queries that should find all docs
@@ -216,8 +289,8 @@ namespace Lucene.Net.Search
iw.AddDocument(doc);
}
iw.Close();
-
- IndexSearcher searcher = new IndexSearcher(dir);
+
+ IndexSearcher searcher = new IndexSearcher(dir, true);
// test queries that must find all
for (int i = 0; i < matchAll.Length; i++)
Modified: incubator/lucene.net/trunk/test/core/Store/MockRAMDirectory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Store/MockRAMDirectory.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Store/MockRAMDirectory.cs (original)
+++ incubator/lucene.net/trunk/test/core/Store/MockRAMDirectory.cs Tue Feb 28 22:43:08 2012
@@ -16,7 +16,7 @@
*/
using System;
-
+using System.Collections.Generic;
using NUnit.Framework;
namespace Lucene.Net.Store
@@ -25,9 +25,6 @@ namespace Lucene.Net.Store
/// <summary> This is a subclass of RAMDirectory that adds methods
/// intended to be used only by unit tests.
/// </summary>
- /// <version> $Id: RAMDirectory.java 437897 2006-08-29 01:13:10Z yonik $
- /// </version>
-
[Serializable]
public class MockRAMDirectory : RAMDirectory
{
@@ -39,19 +36,19 @@ namespace Lucene.Net.Store
Random randomState;
internal bool noDeleteOpenFile = true;
internal bool preventDoubleWrite = true;
- private System.Collections.Hashtable unSyncedFiles;
- private System.Collections.Hashtable createdFiles;
+ private ISet<string> unSyncedFiles;
+ private ISet<string> createdFiles;
internal volatile bool crashed;
// NOTE: we cannot initialize the Map here due to the
// order in which our constructor actually does this
// member initialization vs when it calls super. It seems
// like super is called, then our members are initialized:
- internal System.Collections.IDictionary openFiles;
+ internal IDictionary<string, int> openFiles;
// Only tracked if noDeleteOpenFile is true: if an attempt
// is made to delete an open file, we enroll it here.
- internal System.Collections.Hashtable openFilesDeleted;
+ internal ISet<string> openFilesDeleted;
private void Init()
{
@@ -59,14 +56,14 @@ namespace Lucene.Net.Store
{
if (openFiles == null)
{
- openFiles = new System.Collections.Hashtable();
- openFilesDeleted = new System.Collections.Hashtable();
+ openFiles = new Dictionary<string, int>();
+ openFilesDeleted = new HashSet<string>();
}
if (createdFiles == null)
- createdFiles = new System.Collections.Hashtable();
+ createdFiles = new HashSet<string>();
if (unSyncedFiles == null)
- unSyncedFiles = new System.Collections.Hashtable();
+ unSyncedFiles = new HashSet<string>();
}
}
@@ -75,21 +72,11 @@ namespace Lucene.Net.Store
{
Init();
}
- public MockRAMDirectory(String dir)
- : base(dir)
- {
- Init();
- }
public MockRAMDirectory(Directory dir)
: base(dir)
{
Init();
}
- public MockRAMDirectory(System.IO.FileInfo dir)
- : base(dir)
- {
- Init();
- }
/** If set to true, we throw an IOException if the same
* file is opened by createOutput, ever. */
@@ -117,16 +104,15 @@ namespace Lucene.Net.Store
lock (this)
{
crashed = true;
- openFiles = new System.Collections.Hashtable();
- openFilesDeleted = new System.Collections.Hashtable();
- System.Collections.IEnumerator it = unSyncedFiles.GetEnumerator();
- unSyncedFiles = new System.Collections.Hashtable();
+ openFiles = new Dictionary<string, int>();
+ openFilesDeleted = new HashSet<string>();
+ var it = unSyncedFiles.GetEnumerator();
+ unSyncedFiles = new HashSet<string>();
int count = 0;
while (it.MoveNext())
{
-
- string name = (string)((System.Collections.DictionaryEntry)it.Current).Key;
- RAMFile file = (RAMFile)fileMap[name];
+ string name = it.Current;
+ RAMFile file = fileMap[name];
if (count % 3 == 0)
{
DeleteFile(name, true);
@@ -244,9 +230,9 @@ namespace Lucene.Net.Store
unSyncedFiles.Remove(name);
if (!forced && noDeleteOpenFile)
{
- if (openFiles.Contains(name))
+ if (openFiles.ContainsKey(name))
{
- openFilesDeleted[name]=name;
+ openFilesDeleted.Add(name);
throw new System.IO.IOException("MockRAMDirectory: file \"" + name + "\" is still open: cannot delete");
}
else
@@ -258,11 +244,11 @@ namespace Lucene.Net.Store
}
}
- public System.Collections.IDictionary GetOpenDeletedFiles()
+ public ISet<string> GetOpenDeletedFiles()
{
lock (this)
{
- return new System.Collections.Hashtable(openFilesDeleted);
+ return new HashSet<string>(openFilesDeleted);
}
}
@@ -275,14 +261,14 @@ namespace Lucene.Net.Store
Init();
if (preventDoubleWrite && createdFiles.Contains(name) && !name.Equals("segments.gen"))
throw new System.IO.IOException("file \"" + name + "\" was already written to");
- if (noDeleteOpenFile && openFiles.Contains(name))
+ if (noDeleteOpenFile && openFiles.ContainsKey(name))
throw new System.IO.IOException("MockRAMDirectory: file \"" + name + "\" is still open: cannot overwrite");
RAMFile file = new RAMFile(this);
if (crashed)
throw new System.IO.IOException("cannot createOutput after crash");
- unSyncedFiles[name]=name;
- createdFiles[name]=name;
- RAMFile existing = (RAMFile)fileMap[name];
+ unSyncedFiles.Add(name);
+ createdFiles.Add(name);
+ RAMFile existing = fileMap[name];
// Enforce write once:
if (existing != null && !name.Equals("segments.gen") && preventDoubleWrite)
throw new System.IO.IOException("file " + name + " already exists");
@@ -290,7 +276,7 @@ namespace Lucene.Net.Store
{
if (existing != null)
{
- sizeInBytes -= existing.sizeInBytes_ForNUnit;
+ _sizeInBytes -= existing.sizeInBytes_ForNUnit;
existing.directory_ForNUnit = null;
}
@@ -305,20 +291,20 @@ namespace Lucene.Net.Store
{
lock (this)
{
- RAMFile file = (RAMFile)fileMap[name];
+ RAMFile file = fileMap[name];
if (file == null)
throw new System.IO.FileNotFoundException(name);
else
{
- if (openFiles.Contains(name))
+ if (openFiles.ContainsKey(name))
{
- int v = (int)openFiles[name];
- v = (System.Int32)(v + 1);
- openFiles[name]= v;
+ int v = openFiles[name];
+ v = v + 1;
+ openFiles[name] = v;
}
else
{
- openFiles[name]=1;
+ openFiles[name] = 1;
}
}
return new MockRAMInputStream(this, name, file);
@@ -331,9 +317,8 @@ namespace Lucene.Net.Store
lock (this)
{
long size = 0;
- System.Collections.IEnumerator it = fileMap.Values.GetEnumerator();
- while (it.MoveNext())
- size += ((RAMFile)it.Current).GetSizeInBytes();
+ foreach(RAMFile file in fileMap.Values)
+ size += file.GetSizeInBytes();
return size;
}
}
@@ -349,21 +334,20 @@ namespace Lucene.Net.Store
lock (this)
{
long size = 0;
- System.Collections.IEnumerator it = fileMap.Values.GetEnumerator();
- while (it.MoveNext())
- size += ((RAMFile)it.Current).length_ForNUnit;
+ foreach(RAMFile file in fileMap.Values)
+ size += file.length;
return size;
}
}
- public override void Close()
+ protected override void Dispose(bool disposing)
{
lock (this)
{
if (openFiles == null)
{
- openFiles = new System.Collections.Hashtable();
- openFilesDeleted = new System.Collections.Hashtable();
+ openFiles = new Dictionary<string, int>();
+ openFilesDeleted = new HashSet<string>();
}
if (noDeleteOpenFile && openFiles.Count > 0)
{
@@ -372,6 +356,8 @@ namespace Lucene.Net.Store
throw new System.SystemException("MockRAMDirectory: cannot close: there are still open files: " + openFiles);
}
}
+
+ base.Dispose(disposing);
}
/**
Modified: incubator/lucene.net/trunk/test/core/Store/MockRAMInputStream.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Store/MockRAMInputStream.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Store/MockRAMInputStream.cs (original)
+++ incubator/lucene.net/trunk/test/core/Store/MockRAMInputStream.cs Tue Feb 28 22:43:08 2012
@@ -31,6 +31,7 @@ namespace Lucene.Net.Store
private MockRAMDirectory dir;
private System.String name;
private bool isClone;
+ private bool isDisposed;
/// <summary>Construct an empty output buffer. </summary>
/// <throws> IOException </throws>
@@ -39,34 +40,38 @@ namespace Lucene.Net.Store
this.name = name;
this.dir = dir;
}
-
- public override void Close()
- {
- base.Close();
- // Pending resolution on LUCENE-686 we may want to
- // remove the conditional check so we also track that
- // all clones get closed:
- if (!isClone)
- {
- lock (dir)
- {
- // Could be null when MockRAMDirectory.crash() was called
- if (dir.openFiles[name] != null)
- {
- System.Int32 v = (System.Int32) dir.openFiles[name];
- if (v == 1)
- {
- dir.openFiles.Remove(name);
- }
- else
- {
- v = (System.Int32) (v - 1);
- dir.openFiles[name] = v;
- }
- }
- }
- }
- }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (isDisposed) return;
+
+ // Pending resolution on LUCENE-686 we may want to
+ // remove the conditional check so we also track that
+ // all clones get closed:
+ if (disposing && !isClone)
+ {
+ lock (dir)
+ {
+ // Could be null when MockRAMDirectory.crash() was called
+ if (dir.openFiles[name] != null)
+ {
+ System.Int32 v = dir.openFiles[name];
+ if (v == 1)
+ {
+ dir.openFiles.Remove(name);
+ }
+ else
+ {
+ v = v - 1;
+ dir.openFiles[name] = v;
+ }
+ }
+ }
+ }
+
+ isDisposed = true;
+ base.Dispose(disposing);
+ }
public override System.Object Clone()
{
Modified: incubator/lucene.net/trunk/test/core/Store/MockRAMOutputStream.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Store/MockRAMOutputStream.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Store/MockRAMOutputStream.cs (original)
+++ incubator/lucene.net/trunk/test/core/Store/MockRAMOutputStream.cs Tue Feb 28 22:43:08 2012
@@ -28,7 +28,7 @@ namespace Lucene.Net.Store
/// IOExceptions.
/// </summary>
- public class MockRAMOutputStream:RAMOutputStream
+ public sealed class MockRAMOutputStream:RAMOutputStream
{
private MockRAMDirectory dir;
private bool first = true;
@@ -42,19 +42,19 @@ namespace Lucene.Net.Store
this.dir = dir;
this.name = name;
}
-
- public override void Close()
- {
- base.Close();
-
- // Now compute actual disk usage & track the maxUsedSize
- // in the MockRAMDirectory:
- long size = dir.GetRecomputedActualSizeInBytes();
- if (size > dir.maxUsedSize)
- {
- dir.maxUsedSize = size;
- }
- }
+
+ protected override void Dispose(bool disposing)
+ {
+ base.Dispose(disposing);
+
+ // Now compute actual disk usage & track the maxUsedSize
+ // in the MockRAMDirectory:
+ long size = dir.GetRecomputedActualSizeInBytes();
+ if (size > dir.maxUsedSize)
+ {
+ dir.maxUsedSize = size;
+ }
+ }
public override void Flush()
{
Modified: incubator/lucene.net/trunk/test/core/Store/TestBufferedIndexInput.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Store/TestBufferedIndexInput.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Store/TestBufferedIndexInput.cs (original)
+++ incubator/lucene.net/trunk/test/core/Store/TestBufferedIndexInput.cs Tue Feb 28 22:43:08 2012
@@ -16,7 +16,7 @@
*/
using System;
-
+using Lucene.Net.Support;
using NUnit.Framework;
using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
@@ -106,7 +106,8 @@ namespace Lucene.Net.Store
// run test with chunk size of 10 bytes
RunReadBytesAndClose(new SimpleFSIndexInput(tmpInputFile, inputBufferSize, 10), inputBufferSize, r);
// run test with chunk size of 100 MB - default
- RunReadBytesAndClose(new SimpleFSIndexInput(tmpInputFile, inputBufferSize), inputBufferSize, r);
+ RunReadBytesAndClose(new SimpleFSIndexInput(tmpInputFile, inputBufferSize, FSDirectory.DEFAULT_READ_CHUNK_SIZE), inputBufferSize, r);
+ Assert.Pass("Supressing Sub-Tests on NIOFSIndexInput classes");
// run test with chunk size of 10 bytes
//RunReadBytesAndClose(new NIOFSIndexInput(tmpInputFile, inputBufferSize, 10), inputBufferSize, r); // {{Aroush-2.9}} suppressing this test since NIOFSIndexInput isn't ported
System.Console.Out.WriteLine("Suppressing sub-test: 'RunReadBytesAndClose(new NIOFSIndexInput(tmpInputFile, inputBufferSize, 10), inputBufferSize, r);' since NIOFSIndexInput isn't ported");
@@ -270,10 +271,11 @@ namespace Lucene.Net.Store
{
this.pos = pos;
}
-
- public override void Close()
- {
- }
+
+ protected override void Dispose(bool disposing)
+ {
+ // Do nothing
+ }
public override long Length()
{
@@ -284,7 +286,7 @@ namespace Lucene.Net.Store
[Test]
public virtual void TestSetBufferSize()
{
- System.IO.FileInfo indexDir = new System.IO.FileInfo(System.IO.Path.Combine(SupportClass.AppSettings.Get("tempDir", ""), "testSetBufferSize"));
+ System.IO.DirectoryInfo indexDir = new System.IO.DirectoryInfo(System.IO.Path.Combine(AppSettings.Get("tempDir", ""), "testSetBufferSize"));
MockFSDirectory dir = new MockFSDirectory(indexDir, NewRandom());
try
{
@@ -301,7 +303,7 @@ namespace Lucene.Net.Store
dir.allIndexInputs.Clear();
- IndexReader reader = IndexReader.Open(dir);
+ IndexReader reader = IndexReader.Open(dir, false);
Term aaa = new Term("content", "aaa");
Term bbb = new Term("content", "bbb");
Term ccc = new Term("content", "ccc");
@@ -341,8 +343,9 @@ namespace Lucene.Net.Store
internal System.Random rand;
private Directory dir;
+ private bool isDisposed;
- public MockFSDirectory(System.IO.FileInfo path, System.Random rand)
+ public MockFSDirectory(System.IO.DirectoryInfo path, System.Random rand)
{
this.rand = rand;
lockFactory = new NoLockFactory();
@@ -381,18 +384,21 @@ namespace Lucene.Net.Store
{
return dir.CreateOutput(name);
}
-
- public override void Close()
- {
- dir.Close();
- }
- /// <summary>
- /// .NET
- /// </summary>
- public override void Dispose()
+ protected override void Dispose(bool disposing)
{
- Close();
+ if (isDisposed) return;
+
+ if (disposing)
+ {
+ if (dir != null)
+ {
+ dir.Close();
+ }
+ }
+
+ dir = null;
+ isDisposed = true;
}
public override void DeleteFile(System.String name)
@@ -411,10 +417,6 @@ namespace Lucene.Net.Store
{
return dir.FileExists(name);
}
- public override System.String[] List()
- {
- return dir.List();
- }
public override System.String[] ListAll()
{
return dir.ListAll();
@@ -424,10 +426,6 @@ namespace Lucene.Net.Store
{
return dir.FileLength(name);
}
- public override void RenameFile(System.String from, System.String to)
- {
- dir.RenameFile(from, to);
- }
}
}
}
\ No newline at end of file
Modified: incubator/lucene.net/trunk/test/core/Store/TestDirectory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Store/TestDirectory.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Store/TestDirectory.cs (original)
+++ incubator/lucene.net/trunk/test/core/Store/TestDirectory.cs Tue Feb 28 22:43:08 2012
@@ -16,7 +16,7 @@
*/
using System;
-
+using Lucene.Net.Support;
using NUnit.Framework;
using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
@@ -43,7 +43,7 @@ namespace Lucene.Net.Store
{
}
- dir = FSDirectory.Open(new System.IO.FileInfo(SupportClass.AppSettings.Get("tempDir", System.IO.Path.GetTempPath())));
+ dir = FSDirectory.Open(new System.IO.DirectoryInfo(AppSettings.Get("tempDir", System.IO.Path.GetTempPath())));
dir.Close();
try
{
@@ -61,7 +61,7 @@ namespace Lucene.Net.Store
[Test]
public virtual void TestDirectInstantiation()
{
- System.IO.FileInfo path = new System.IO.FileInfo(SupportClass.AppSettings.Get("tempDir", System.IO.Path.GetTempPath()));
+ System.IO.DirectoryInfo path = new System.IO.DirectoryInfo(AppSettings.Get("tempDir", System.IO.Path.GetTempPath()));
int sz = 2;
Directory[] dirs = new Directory[sz];
@@ -145,7 +145,7 @@ namespace Lucene.Net.Store
[Test]
public virtual void TestDontCreate()
{
- System.IO.FileInfo path = new System.IO.FileInfo(System.IO.Path.Combine(SupportClass.AppSettings.Get("tempDir", ""), "doesnotexist"));
+ System.IO.DirectoryInfo path = new System.IO.DirectoryInfo(System.IO.Path.Combine(AppSettings.Get("tempDir", ""), "doesnotexist"));
try
{
bool tmpBool;
@@ -180,7 +180,7 @@ namespace Lucene.Net.Store
[Test]
public virtual void TestFSDirectoryFilter()
{
- CheckDirectoryFilter(FSDirectory.Open(new System.IO.FileInfo("test")));
+ CheckDirectoryFilter(FSDirectory.Open(new System.IO.DirectoryInfo("test")));
}
// LUCENE-1468
@@ -203,11 +203,11 @@ namespace Lucene.Net.Store
[Test]
public virtual void TestCopySubdir()
{
- System.IO.FileInfo path = new System.IO.FileInfo(System.IO.Path.Combine(SupportClass.AppSettings.Get("tempDir", ""), "testsubdir"));
+ System.IO.DirectoryInfo path = new System.IO.DirectoryInfo(System.IO.Path.Combine(AppSettings.Get("tempDir", ""), "testsubdir"));
try
{
System.IO.Directory.CreateDirectory(path.FullName);
- System.IO.Directory.CreateDirectory(new System.IO.FileInfo(System.IO.Path.Combine(path.FullName, "subdir")).FullName);
+ System.IO.Directory.CreateDirectory(new System.IO.DirectoryInfo(System.IO.Path.Combine(path.FullName, "subdir")).FullName);
Directory fsDir = new SimpleFSDirectory(path, null);
Assert.AreEqual(0, new RAMDirectory(fsDir).ListAll().Length);
}
@@ -221,7 +221,7 @@ namespace Lucene.Net.Store
[Test]
public virtual void TestNotDirectory()
{
- System.IO.FileInfo path = new System.IO.FileInfo(System.IO.Path.Combine(SupportClass.AppSettings.Get("tempDir", ""), "testnotdir"));
+ System.IO.DirectoryInfo path = new System.IO.DirectoryInfo(System.IO.Path.Combine(AppSettings.Get("tempDir", ""), "testnotdir"));
Directory fsDir = new SimpleFSDirectory(path, null);
try
{
@@ -230,7 +230,7 @@ namespace Lucene.Net.Store
Assert.IsTrue(fsDir.FileExists("afile"));
try
{
- new SimpleFSDirectory(new System.IO.FileInfo(System.IO.Path.Combine(path.FullName, "afile")), null);
+ new SimpleFSDirectory(new System.IO.DirectoryInfo(System.IO.Path.Combine(path.FullName, "afile")), null);
Assert.Fail("did not hit expected exception");
}
catch (NoSuchDirectoryException nsde)
Modified: incubator/lucene.net/trunk/test/core/Store/TestFileSwitchDirectory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Store/TestFileSwitchDirectory.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Store/TestFileSwitchDirectory.cs (original)
+++ incubator/lucene.net/trunk/test/core/Store/TestFileSwitchDirectory.cs Tue Feb 28 22:43:08 2012
@@ -16,7 +16,8 @@
*/
using System;
-
+using System.Collections.Generic;
+using Lucene.Net.Support;
using NUnit.Framework;
using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
@@ -36,9 +37,9 @@ namespace Lucene.Net.Store
[Test]
public virtual void TestBasic()
{
- System.Collections.Hashtable fileExtensions = new System.Collections.Hashtable();
- SupportClass.CollectionsHelper.AddIfNotContains(fileExtensions, "fdt");
- SupportClass.CollectionsHelper.AddIfNotContains(fileExtensions, "fdx");
+ HashSet<string> fileExtensions = new HashSet<string>();
+ fileExtensions.Add("fdt");
+ fileExtensions.Add("fdx");
Directory primaryDir = new MockRAMDirectory();
RAMDirectory secondaryDir = new MockRAMDirectory();
Modified: incubator/lucene.net/trunk/test/core/Store/TestHugeRamFile.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Store/TestHugeRamFile.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Store/TestHugeRamFile.cs (original)
+++ incubator/lucene.net/trunk/test/core/Store/TestHugeRamFile.cs Tue Feb 28 22:43:08 2012
@@ -42,15 +42,15 @@ namespace Lucene.Net.Store
public /*internal*/ override byte[] NewBuffer(int size)
{
capacity += size;
- if (capacity <= Lucene.Net.Store.TestHugeRamFile.MAX_VALUE)
+ if (capacity <= MAX_VALUE)
{
// below maxint we reuse buffers
- byte[] buf = (byte[]) singleBuffers[(System.Int32) size];
+ byte[] buf = (byte[]) singleBuffers[size];
if (buf == null)
{
buf = new byte[size];
//System.out.println("allocate: "+size);
- singleBuffers[(System.Int32) size] = buf;
+ singleBuffers[size] = buf;
}
return buf;
}
Modified: incubator/lucene.net/trunk/test/core/Store/TestLockFactory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Store/TestLockFactory.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Store/TestLockFactory.cs (original)
+++ incubator/lucene.net/trunk/test/core/Store/TestLockFactory.cs Tue Feb 28 22:43:08 2012
@@ -16,7 +16,7 @@
*/
using System;
-
+using Lucene.Net.Support;
using NUnit.Framework;
using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
@@ -134,217 +134,13 @@ namespace Lucene.Net.Store
writer2.Close();
}
}
-
- // Verify: SimpleFSLockFactory is the default for FSDirectory
- // Verify: FSDirectory does basic locking correctly
- [Test]
- public virtual void TestDefaultFSDirectory()
- {
- System.IO.FileInfo indexDirName = _TestUtil.GetTempDir("index.TestLockFactory1");
-
- IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
-
- Assert.IsTrue(typeof(SimpleFSLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()) || typeof(NativeFSLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()), "FSDirectory did not use correct LockFactory: got " + writer.GetDirectory().GetLockFactory());
-
- IndexWriter writer2 = null;
-
- // Create a 2nd IndexWriter. This should fail:
- try
- {
- writer2 = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
- Assert.Fail("Should have hit an IOException with two IndexWriters on default SimpleFSLockFactory");
- }
- catch (System.IO.IOException e)
- {
- }
-
- writer.Close();
- if (writer2 != null)
- {
- writer2.Close();
- }
-
- // Cleanup
- _TestUtil.RmDir(indexDirName);
- }
-
- // Verify: FSDirectory's default lockFactory clears all locks correctly
- [Test]
- public virtual void TestFSDirectoryTwoCreates()
- {
- System.IO.FileInfo indexDirName = _TestUtil.GetTempDir("index.TestLockFactory2");
-
- IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
-
- Assert.IsTrue(typeof(SimpleFSLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()) || typeof(NativeFSLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()), "FSDirectory did not use correct LockFactory: got " + writer.GetDirectory().GetLockFactory());
-
- // Intentionally do not close the first writer here.
- // The goal is to "simulate" a crashed writer and
- // ensure the second writer, with create=true, is
- // able to remove the lock files. This works OK
- // with SimpleFSLockFactory as the locking
- // implementation. Note, however, that this test
- // will not work on WIN32 when we switch to
- // NativeFSLockFactory as the default locking for
- // FSDirectory because the second IndexWriter cannot
- // remove those lock files since they are held open
- // by the first writer. This is because leaving the
- // first IndexWriter open is not really a good way
- // to simulate a crashed writer.
-
- // Create a 2nd IndexWriter. This should not fail:
- IndexWriter writer2 = null;
- try
- {
- writer2 = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
- }
- catch (System.IO.IOException e)
- {
- System.Console.Out.WriteLine(e.StackTrace);
- Assert.Fail("Should not have hit an IOException with two IndexWriters with create=true, on default SimpleFSLockFactory");
- }
-
- writer.Close();
- if (writer2 != null)
- {
- try
- {
- writer2.Close();
- // expected
- }
- catch (LockReleaseFailedException e)
- {
- Assert.Fail("writer2.close() should not have hit LockReleaseFailedException");
- }
- }
-
- // Cleanup
- _TestUtil.RmDir(indexDirName);
- }
-
-
- // Verify: setting custom lock factory class (as system property) works:
- // Verify: all 4 builtin LockFactory implementations are
- // settable this way
- // Verify: FSDirectory does basic locking correctly
- [Test]
- public virtual void TestLockClassProperty()
- {
- System.IO.FileInfo indexDirName = _TestUtil.GetTempDir("index.TestLockFactory3");
- System.String prpName = "Lucene.Net.Store.FSDirectoryLockFactoryClass";
-
- try
- {
-
- // NoLockFactory:
- SupportClass.AppSettings.Set(prpName, "Lucene.Net.Store.NoLockFactory");
- IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
- Assert.IsTrue(typeof(NoLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()), "FSDirectory did not use correct LockFactory: got " + writer.GetDirectory().GetLockFactory());
- writer.Close();
-
- // SingleInstanceLockFactory:
- SupportClass.AppSettings.Set(prpName, "Lucene.Net.Store.SingleInstanceLockFactory");
- writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
- Assert.IsTrue(typeof(SingleInstanceLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()), "FSDirectory did not use correct LockFactory: got " + writer.GetDirectory().GetLockFactory());
- writer.Close();
-
- // NativeFSLockFactory:
- SupportClass.AppSettings.Set(prpName, "Lucene.Net.Store.NativeFSLockFactory");
- writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
- Assert.IsTrue(typeof(NativeFSLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()), "FSDirectory did not use correct LockFactory: got " + writer.GetDirectory().GetLockFactory());
- writer.Close();
-
- // SimpleFSLockFactory:
- SupportClass.AppSettings.Set(prpName, "Lucene.Net.Store.SimpleFSLockFactory");
- writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
- Assert.IsTrue(typeof(SimpleFSLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()), "FSDirectory did not use correct LockFactory: got " + writer.GetDirectory().GetLockFactory());
- writer.Close();
- }
- finally
- {
- // Put back to the correct default for subsequent tests:
- SupportClass.AppSettings.Set("Lucene.Net.Store.FSDirectoryLockFactoryClass", "");
- }
-
- // Cleanup
- _TestUtil.RmDir(indexDirName);
- }
-
- // Verify: setDisableLocks works
- [Test]
- public virtual void TestDisableLocks()
- {
- System.IO.FileInfo indexDirName = _TestUtil.GetTempDir("index.TestLockFactory4");
-
- Assert.IsTrue(!FSDirectory.GetDisableLocks(), "Locks are already disabled");
- FSDirectory.SetDisableLocks(true);
-
- IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
-
- Assert.IsTrue(typeof(NoLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()), "FSDirectory did not use correct default LockFactory: got " + writer.GetDirectory().GetLockFactory());
-
- // Should be no error since locking is disabled:
- IndexWriter writer2 = null;
- try
- {
- writer2 = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
- }
- catch (System.IO.IOException e)
- {
- System.Console.Out.WriteLine(e.StackTrace);
- Assert.Fail("Should not have hit an IOException with locking disabled");
- }
-
- FSDirectory.SetDisableLocks(false);
- writer.Close();
- if (writer2 != null)
- {
- writer2.Close();
- }
- // Cleanup
- _TestUtil.RmDir(indexDirName);
- }
-
- // Verify: if I try to getDirectory() with two different locking implementations, I get an IOException
- [Test]
- public virtual void TestFSDirectoryDifferentLockFactory()
- {
- System.IO.FileInfo indexDirName = _TestUtil.GetTempDir("index.TestLockFactory5");
-
- LockFactory lf = new SingleInstanceLockFactory();
- FSDirectory fs1 = FSDirectory.GetDirectory(indexDirName, lf);
-
- // Different lock factory instance should hit IOException:
- try
- {
- FSDirectory.GetDirectory(indexDirName, new SingleInstanceLockFactory());
- Assert.Fail("Should have hit an IOException because LockFactory instances differ");
- }
- catch (System.IO.IOException e)
- {
- }
-
- FSDirectory fs2 = null;
-
- // Same lock factory instance should not:
- try
- {
- fs2 = FSDirectory.GetDirectory(indexDirName, lf);
- }
- catch (System.IO.IOException e)
- {
- System.Console.Out.WriteLine(e.StackTrace);
- Assert.Fail("Should not have hit an IOException because LockFactory instances are the same");
- }
-
- fs1.Close();
- if (fs2 != null)
- {
- fs2.Close();
- }
- // Cleanup
- _TestUtil.RmDir(indexDirName);
- }
+
+ [Test]
+ public void TestSimpleFSLockFactory()
+ {
+ // test string file instantiation
+ new SimpleFSLockFactory("test");
+ }
// Verify: do stress test, by opening IndexReaders and
// IndexWriters over & over in 2 threads and making sure
@@ -362,11 +158,11 @@ namespace Lucene.Net.Store
[Test]
public virtual void TestStressLocksNativeFSLockFactory()
{
- System.IO.FileInfo dir = _TestUtil.GetTempDir("index.TestLockFactory7");
+ System.IO.DirectoryInfo dir = _TestUtil.GetTempDir("index.TestLockFactory7");
_testStressLocks(new NativeFSLockFactory(dir), dir);
}
- public virtual void _testStressLocks(LockFactory lockFactory, System.IO.FileInfo indexDir)
+ public virtual void _testStressLocks(LockFactory lockFactory, System.IO.DirectoryInfo indexDir)
{
FSDirectory fs1 = FSDirectory.Open(new System.IO.DirectoryInfo(indexDir.FullName), lockFactory);
@@ -397,7 +193,7 @@ namespace Lucene.Net.Store
public virtual void TestNativeFSLockFactory()
{
- NativeFSLockFactory f = new NativeFSLockFactory(SupportClass.AppSettings.Get("tempDir", System.IO.Path.GetTempPath()));
+ NativeFSLockFactory f = new NativeFSLockFactory(AppSettings.Get("tempDir", System.IO.Path.GetTempPath()));
f.SetLockPrefix("test");
Lock l = f.MakeLock("commit");
@@ -424,8 +220,8 @@ namespace Lucene.Net.Store
public virtual void TestNativeFSLockFactoryPrefix()
{
- System.IO.FileInfo fdir1 = _TestUtil.GetTempDir("TestLockFactory.8");
- System.IO.FileInfo fdir2 = _TestUtil.GetTempDir("TestLockFactory.8.Lockdir");
+ System.IO.DirectoryInfo fdir1 = _TestUtil.GetTempDir("TestLockFactory.8");
+ System.IO.DirectoryInfo fdir2 = _TestUtil.GetTempDir("TestLockFactory.8.Lockdir");
Directory dir1 = FSDirectory.Open(new System.IO.DirectoryInfo(fdir1.FullName), new NativeFSLockFactory(fdir1));
// same directory, but locks are stored somewhere else. The prefix of the lock factory should != null
Directory dir2 = FSDirectory.Open(new System.IO.DirectoryInfo(fdir1.FullName), new NativeFSLockFactory(fdir2));
@@ -447,7 +243,7 @@ namespace Lucene.Net.Store
{
// Make sure we get null prefix:
- System.IO.FileInfo dirName = _TestUtil.GetTempDir("TestLockFactory.10");
+ System.IO.DirectoryInfo dirName = _TestUtil.GetTempDir("TestLockFactory.10");
Directory dir = FSDirectory.Open(dirName);
System.String prefix = dir.GetLockFactory().GetLockPrefix();
@@ -457,7 +253,7 @@ namespace Lucene.Net.Store
_TestUtil.RmDir(dirName);
}
- private class WriterThread:SupportClass.ThreadClass
+ private class WriterThread:ThreadClass
{
private void InitBlock(TestLockFactory enclosingInstance)
{
@@ -546,7 +342,7 @@ namespace Lucene.Net.Store
}
}
- private class SearcherThread:SupportClass.ThreadClass
+ private class SearcherThread:ThreadClass
{
private void InitBlock(TestLockFactory enclosingInstance)
{
@@ -578,7 +374,7 @@ namespace Lucene.Net.Store
{
try
{
- searcher = new IndexSearcher(dir);
+ searcher = new IndexSearcher(dir, false);
}
catch (System.Exception e)
{
Modified: incubator/lucene.net/trunk/test/core/Store/TestRAMDirectory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Store/TestRAMDirectory.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Store/TestRAMDirectory.cs (original)
+++ incubator/lucene.net/trunk/test/core/Store/TestRAMDirectory.cs Tue Feb 28 22:43:08 2012
@@ -17,7 +17,7 @@
using System;
using System.IO;
-
+using Lucene.Net.Support;
using NUnit.Framework;
using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
@@ -34,15 +34,11 @@ namespace Lucene.Net.Store
/// <summary> JUnit testcase to test RAMDirectory. RAMDirectory itself is used in many testcases,
/// but not one of them uses an different constructor other than the default constructor.
- ///
- ///
/// </summary>
- /// <version> $Id: RAMDirectory.java 150537 2004-09-28 22:45:26 +0200 (Di, 28 Sep 2004) cutting $
- /// </version>
[TestFixture]
public class TestRAMDirectory:LuceneTestCase
{
- private class AnonymousClassThread:SupportClass.ThreadClass
+ private class AnonymousClassThread:ThreadClass
{
public AnonymousClassThread(int num, Lucene.Net.Index.IndexWriter writer, Lucene.Net.Store.MockRAMDirectory ramDir, TestRAMDirectory enclosingInstance)
{
@@ -85,7 +81,7 @@ namespace Lucene.Net.Store
}
}
- private System.IO.FileInfo indexDir = null;
+ private System.IO.DirectoryInfo indexDir = null;
// add enough document so that the index will be larger than RAMDirectory.READ_BUFFER_SIZE
private int docsToAdd = 500;
@@ -98,9 +94,10 @@ namespace Lucene.Net.Store
System.String tempDir = System.IO.Path.GetTempPath();
if (tempDir == null)
throw new System.IO.IOException("java.io.tmpdir undefined, cannot run test");
- indexDir = new System.IO.FileInfo(Path.Combine(tempDir, "RAMDirIndex"));
-
- IndexWriter writer = new IndexWriter(indexDir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
+ indexDir = new System.IO.DirectoryInfo(Path.Combine(tempDir, "RAMDirIndex"));
+
+ Directory dir = FSDirectory.Open(indexDir);
+ IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
// add some documents
Document doc = null;
for (int i = 0; i < docsToAdd; i++)
@@ -109,8 +106,9 @@ namespace Lucene.Net.Store
doc.Add(new Field("content", English.IntToEnglish(i).Trim(), Field.Store.YES, Field.Index.NOT_ANALYZED));
writer.AddDocument(doc);
}
- Assert.AreEqual(docsToAdd, writer.DocCount());
+ Assert.AreEqual(docsToAdd, writer.MaxDoc());
writer.Close();
+ dir.Close();
}
[Test]
@@ -127,63 +125,7 @@ namespace Lucene.Net.Store
Assert.AreEqual(ramDir.SizeInBytes(), ramDir.GetRecomputedSizeInBytes());
// open reader to test document count
- IndexReader reader = IndexReader.Open(ramDir);
- Assert.AreEqual(docsToAdd, reader.NumDocs());
-
- // open search zo check if all doc's are there
- IndexSearcher searcher = new IndexSearcher(reader);
-
- // search for all documents
- for (int i = 0; i < docsToAdd; i++)
- {
- Document doc = searcher.Doc(i);
- Assert.IsTrue(doc.GetField("content") != null);
- }
-
- // cleanup
- reader.Close();
- searcher.Close();
- }
-
- [Test]
- public virtual void TestRAMDirectoryFile()
- {
-
- MockRAMDirectory ramDir = new MockRAMDirectory(indexDir);
-
- // Check size
- Assert.AreEqual(ramDir.SizeInBytes(), ramDir.GetRecomputedSizeInBytes());
-
- // open reader to test document count
- IndexReader reader = IndexReader.Open(ramDir);
- Assert.AreEqual(docsToAdd, reader.NumDocs());
-
- // open search zo check if all doc's are there
- IndexSearcher searcher = new IndexSearcher(reader);
-
- // search for all documents
- for (int i = 0; i < docsToAdd; i++)
- {
- Document doc = searcher.Doc(i);
- Assert.IsTrue(doc.GetField("content") != null);
- }
-
- // cleanup
- reader.Close();
- searcher.Close();
- }
-
- [Test]
- public virtual void TestRAMDirectoryString()
- {
-
- MockRAMDirectory ramDir = new MockRAMDirectory(indexDir.FullName);
-
- // Check size
- Assert.AreEqual(ramDir.SizeInBytes(), ramDir.GetRecomputedSizeInBytes());
-
- // open reader to test document count
- IndexReader reader = IndexReader.Open(ramDir);
+ IndexReader reader = IndexReader.Open(ramDir, true);
Assert.AreEqual(docsToAdd, reader.NumDocs());
// open search zo check if all doc's are there
@@ -206,15 +148,16 @@ namespace Lucene.Net.Store
[Test]
public virtual void TestRAMDirectorySize()
- {
-
- MockRAMDirectory ramDir = new MockRAMDirectory(indexDir.FullName);
+ {
+ Directory dir = FSDirectory.Open(indexDir);
+ MockRAMDirectory ramDir = new MockRAMDirectory(dir);
+ dir.Close();
IndexWriter writer = new IndexWriter(ramDir, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
writer.Optimize();
Assert.AreEqual(ramDir.SizeInBytes(), ramDir.GetRecomputedSizeInBytes());
- SupportClass.ThreadClass[] threads = new SupportClass.ThreadClass[numThreads];
+ ThreadClass[] threads = new ThreadClass[numThreads];
for (int i = 0; i < numThreads; i++)
{
int num = i;
Modified: incubator/lucene.net/trunk/test/core/Store/TestWindowsMMap.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Store/TestWindowsMMap.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Store/TestWindowsMMap.cs (original)
+++ incubator/lucene.net/trunk/test/core/Store/TestWindowsMMap.cs Tue Feb 28 22:43:08 2012
@@ -16,7 +16,7 @@
*/
using System;
-
+using Lucene.Net.Support;
using NUnit.Framework;
using StandardAnalyzer = Lucene.Net.Analysis.Standard.StandardAnalyzer;
@@ -25,6 +25,7 @@ using Field = Lucene.Net.Documents.Field
using IndexWriter = Lucene.Net.Index.IndexWriter;
using IndexSearcher = Lucene.Net.Search.IndexSearcher;
using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
+using System.Collections.Generic;
namespace Lucene.Net.Store
{
@@ -67,20 +68,20 @@ namespace Lucene.Net.Store
return fb.ToString();
}
- private static readonly System.String storePathname = new System.IO.FileInfo(System.IO.Path.Combine(SupportClass.AppSettings.Get("tempDir", ""), "testLuceneMmap")).FullName;
+ private static readonly System.String storePathname = new System.IO.DirectoryInfo(System.IO.Path.Combine(AppSettings.Get("tempDir", ""), "testLuceneMmap")).FullName;
[Test]
public virtual void TestMmapIndex()
{
FSDirectory storeDirectory;
- storeDirectory = new MMapDirectory(new System.IO.FileInfo(storePathname), null);
+ storeDirectory = new MMapDirectory(new System.IO.DirectoryInfo(storePathname), null);
// plan to add a set of useful stopwords, consider changing some of the
// interior filters.
- StandardAnalyzer analyzer = new StandardAnalyzer(new System.Collections.Hashtable());
+ StandardAnalyzer analyzer = new StandardAnalyzer(Util.Version.LUCENE_CURRENT, new HashSet<string>());
// TODO: something about lock timeouts and leftover locks.
IndexWriter writer = new IndexWriter(storeDirectory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
- IndexSearcher searcher = new IndexSearcher(storePathname);
+ IndexSearcher searcher = new IndexSearcher(storeDirectory, true);
for (int dx = 0; dx < 1000; dx++)
{
@@ -97,7 +98,7 @@ namespace Lucene.Net.Store
private void RmDir(System.IO.FileInfo dir)
{
- System.IO.FileInfo[] files = SupportClass.FileSupport.GetFiles(dir);
+ System.IO.FileInfo[] files = FileSupport.GetFiles(dir);
for (int i = 0; i < files.Length; i++)
{
bool tmpBool;
Modified: incubator/lucene.net/trunk/test/core/TestDemo.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/TestDemo.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/TestDemo.cs (original)
+++ incubator/lucene.net/trunk/test/core/TestDemo.cs Tue Feb 28 22:43:08 2012
@@ -67,7 +67,7 @@ namespace Lucene.Net
// Now search the index:
IndexSearcher isearcher = new IndexSearcher(directory, true); // read-only=true
// Parse a simple query that searches for "text":
- QueryParser parser = new QueryParser("fieldname", analyzer);
+ QueryParser parser = new QueryParser(Util.Version.LUCENE_CURRENT, "fieldname", analyzer);
Query query = parser.Parse("text");
ScoreDoc[] hits = isearcher.Search(query, null, 1000).ScoreDocs;
Assert.AreEqual(1, hits.Length);
Modified: incubator/lucene.net/trunk/test/core/TestMergeSchedulerExternal.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/TestMergeSchedulerExternal.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/TestMergeSchedulerExternal.cs (original)
+++ incubator/lucene.net/trunk/test/core/TestMergeSchedulerExternal.cs Tue Feb 28 22:43:08 2012
@@ -110,7 +110,7 @@ namespace Lucene.Net
}
}
- protected /*internal*/ override MergeThread GetMergeThread(IndexWriter writer, MergePolicy.OneMerge merge)
+ protected internal override MergeThread GetMergeThread(IndexWriter writer, MergePolicy.OneMerge merge)
{
MergeThread thread = new MyMergeThread(this, writer, merge);
thread.SetThreadPriority(GetMergeThreadPriority());
@@ -118,13 +118,14 @@ namespace Lucene.Net
thread.Name = "MyMergeThread";
return thread;
}
-
- protected /*internal*/ override void HandleMergeException(System.Exception t)
+
+ protected internal override void HandleMergeException(System.Exception t)
{
Enclosing_Instance.excCalled = true;
}
-
- protected /*internal*/ override void DoMerge(MergePolicy.OneMerge merge)
+
+ [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
+ protected internal override void DoMerge(MergePolicy.OneMerge merge)
{
Enclosing_Instance.mergeCalled = true;
base.DoMerge(merge);
@@ -145,10 +146,6 @@ namespace Lucene.Net
}
}
-#if GALLIO
- // TODO: figure out why this fails in release mode when running in gallio.
- [Ignore]
-#endif
[Test]
public virtual void TestSubclassConcurrentMergeScheduler()
{
@@ -161,6 +158,7 @@ namespace Lucene.Net
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
MyMergeScheduler ms = new MyMergeScheduler(this);
+
writer.SetMergeScheduler(ms);
writer.SetMaxBufferedDocs(2);
writer.SetRAMBufferSizeMB(Lucene.Net.Index.IndexWriter.DISABLE_AUTO_FLUSH);
@@ -177,7 +175,8 @@ namespace Lucene.Net
Assert.IsTrue(mergeCalled);
Console.WriteLine("exec called");
- Assert.IsTrue(excCalled);
+ Assert.IsTrue(excCalled);
+ Console.WriteLine("exec true");
dir.Close();
Console.WriteLine("Last");
Modified: incubator/lucene.net/trunk/test/core/TestSearch.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/TestSearch.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/TestSearch.cs (original)
+++ incubator/lucene.net/trunk/test/core/TestSearch.cs Tue Feb 28 22:43:08 2012
@@ -30,11 +30,7 @@ using LuceneTestCase = Lucene.Net.Util.L
namespace Lucene.Net
{
- /// <summary>JUnit adaptation of an older test case SearchTest.
- ///
- /// </summary>
- /// <version> $Id: TestSearch.java 694004 2008-09-10 21:38:52Z mikemccand $
- /// </version>
+ /// <summary>JUnit adaptation of an older test case SearchTest.</summary>
[TestFixture]
public class TestSearch:LuceneTestCase
{
@@ -93,13 +89,13 @@ namespace Lucene.Net
writer.AddDocument(d);
}
writer.Close();
-
- Searcher searcher = new IndexSearcher(directory);
+
+ Searcher searcher = new IndexSearcher(directory, true);
System.String[] queries = new System.String[]{"a b", "\"a b\"", "\"a b c\"", "a c", "\"a c\"", "\"a c e\""};
ScoreDoc[] hits = null;
- QueryParser parser = new QueryParser("contents", analyzer);
+ QueryParser parser = new QueryParser(Util.Version.LUCENE_CURRENT, "contents", analyzer);
parser.SetPhraseSlop(4);
for (int j = 0; j < queries.Length; j++)
{
Modified: incubator/lucene.net/trunk/test/core/TestSearchForDuplicates.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/TestSearchForDuplicates.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/TestSearchForDuplicates.cs (original)
+++ incubator/lucene.net/trunk/test/core/TestSearchForDuplicates.cs Tue Feb 28 22:43:08 2012
@@ -31,11 +31,7 @@ namespace Lucene.Net
{
- /// <summary>JUnit adaptation of an older test case DocTest.
- ///
- /// </summary>
- /// <version> $Id: TestSearchForDuplicates.java 694004 2008-09-10 21:38:52Z mikemccand $
- /// </version>
+ /// <summary>JUnit adaptation of an older test case DocTest.</summary>
[TestFixture]
public class TestSearchForDuplicates : LuceneTestCase
{
@@ -106,9 +102,9 @@ namespace Lucene.Net
writer.Close();
// try a search without OR
- Searcher searcher = new IndexSearcher(directory);
+ Searcher searcher = new IndexSearcher(directory, true);
- QueryParser parser = new QueryParser(PRIORITY_FIELD, analyzer);
+ QueryParser parser = new QueryParser(Util.Version.LUCENE_CURRENT, PRIORITY_FIELD, analyzer);
Query query = parser.Parse(HIGH_PRIORITY);
out_Renamed.WriteLine("Query: " + query.ToString(PRIORITY_FIELD));
@@ -120,10 +116,10 @@ namespace Lucene.Net
searcher.Close();
// try a new search with OR
- searcher = new IndexSearcher(directory);
+ searcher = new IndexSearcher(directory, true);
hits = null;
- parser = new QueryParser(PRIORITY_FIELD, analyzer);
+ parser = new QueryParser(Util.Version.LUCENE_CURRENT, PRIORITY_FIELD, analyzer);
query = parser.Parse(HIGH_PRIORITY + " OR " + MED_PRIORITY);
out_Renamed.WriteLine("Query: " + query.ToString(PRIORITY_FIELD));
Modified: incubator/lucene.net/trunk/test/core/Util/Cache/TestSimpleLRUCache.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Util/Cache/TestSimpleLRUCache.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Util/Cache/TestSimpleLRUCache.cs (original)
+++ incubator/lucene.net/trunk/test/core/Util/Cache/TestSimpleLRUCache.cs Tue Feb 28 22:43:08 2012
@@ -32,45 +32,45 @@ namespace Lucene.Net.Util.Cache
public virtual void TestLRUCache()
{
int n = 100;
- System.Object dummy = new System.Object();
-
- Cache cache = new SimpleLRUCache(n);
+ object dummy = new object();
+
+ Cache<int, object> cache = new SimpleLRUCache<int, object>(n);
for (int i = 0; i < n; i++)
{
- cache.Put((System.Object) i, dummy);
+ cache.Put(i, dummy);
}
// access every 2nd item in cache
for (int i = 0; i < n; i += 2)
{
- Assert.IsNotNull(cache.Get((System.Object) i));
+ Assert.IsNotNull(cache.Get(i));
}
// add n/2 elements to cache, the ones that weren't
// touched in the previous loop should now be thrown away
for (int i = n; i < n + (n / 2); i++)
{
- cache.Put((System.Object) i, dummy);
+ cache.Put(i, dummy);
}
// access every 4th item in cache
for (int i = 0; i < n; i += 4)
{
- Assert.IsNotNull(cache.Get((System.Object) i));
+ Assert.IsNotNull(cache.Get(i));
}
// add 3/4n elements to cache, the ones that weren't
// touched in the previous loops should now be thrown away
for (int i = n; i < n + (n * 3 / 4); i++)
{
- cache.Put((System.Object) i, dummy);
+ cache.Put(i, dummy);
}
// access every 4th item in cache
for (int i = 0; i < n; i += 4)
{
- Assert.IsNotNull(cache.Get((System.Object) i));
+ Assert.IsNotNull(cache.Get(i));
}
}
}
Modified: incubator/lucene.net/trunk/test/core/Util/LuceneTestCase.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Util/LuceneTestCase.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Util/LuceneTestCase.cs (original)
+++ incubator/lucene.net/trunk/test/core/Util/LuceneTestCase.cs Tue Feb 28 22:43:08 2012
@@ -19,7 +19,6 @@ using System;
using NUnit.Framework;
-using TokenStream = Lucene.Net.Analysis.TokenStream;
using ConcurrentMergeScheduler = Lucene.Net.Index.ConcurrentMergeScheduler;
using Insanity = Lucene.Net.Util.FieldCacheSanityChecker.Insanity;
using FieldCache = Lucene.Net.Search.FieldCache;
@@ -56,29 +55,20 @@ namespace Lucene.Net.Util
TEMP_DIR = new System.IO.FileInfo(directory);
}
- [NonSerialized]
- private bool savedAPISetting = false;
bool allowDocsOutOfOrder = true;
- public LuceneTestCase():base()
+ public LuceneTestCase() : base()
{
}
public LuceneTestCase(System.String name)
{
}
-
[SetUp]
public virtual void SetUp()
{
- //{{Lucene.Net-2.9.1}}
- allowDocsOutOfOrder = Lucene.Net.Search.BooleanQuery.GetAllowDocsOutOfOrder();
-
ConcurrentMergeScheduler.SetTestMode();
-
- savedAPISetting = TokenStream.GetOnlyUseNewAPI();
- TokenStream.SetOnlyUseNewAPI(false);
}
/// <summary> Forcible purges all cache entries from the FieldCache.
@@ -125,12 +115,8 @@ namespace Lucene.Net.Util
PurgeFieldCache(Lucene.Net.Search.FieldCache_Fields.DEFAULT);
}
- TokenStream.SetOnlyUseNewAPI(savedAPISetting);
//base.TearDown(); // {{Aroush-2.9}}
- this.seed_init = false;
-
- //{{Lucene.Net-2.9.1}}
- Lucene.Net.Search.BooleanQuery.SetAllowDocsOutOfOrder(allowDocsOutOfOrder);
+ this.seed = null;
}
/// <summary> Asserts that FieldCacheSanityChecker does not detect any
@@ -226,7 +212,7 @@ namespace Lucene.Net.Util
/// </summary>
public virtual System.Random NewRandom()
{
- if (seed_init != false)
+ if (this.seed != null)
{
throw new System.SystemException("please call LuceneTestCase.newRandom only once per test");
}
@@ -239,11 +225,10 @@ namespace Lucene.Net.Util
/// </summary>
public virtual System.Random NewRandom(int seed)
{
- if (this.seed_init != false)
+ if (this.seed != null)
{
throw new System.SystemException("please call LuceneTestCase.newRandom only once per test");
}
- this.seed_init = true;
this.seed = seed;
return new System.Random(seed);
}
@@ -253,13 +238,13 @@ namespace Lucene.Net.Util
{
try
{
- seed_init = false;
+ this.seed = null;
//base.RunBare(); // {{Aroush-2.9}}
System.Diagnostics.Debug.Fail("Port issue:", "base.RunBare()"); // {{Aroush-2.9}}
}
catch (System.Exception e)
{
- if (seed_init != false)
+ if (this.seed != null)
{
System.Console.Out.WriteLine("NOTE: random seed of testcase '" + GetType() + "' was: " + seed);
}
@@ -269,8 +254,8 @@ namespace Lucene.Net.Util
// recorded seed
[NonSerialized]
- protected internal int seed = 0;
- protected internal bool seed_init = false;
+ protected internal int? seed = null;
+ //protected internal bool seed_init = false;
// static members
[NonSerialized]
Modified: incubator/lucene.net/trunk/test/core/Util/Paths.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Util/Paths.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Util/Paths.cs (original)
+++ incubator/lucene.net/trunk/test/core/Util/Paths.cs Tue Feb 28 22:43:08 2012
@@ -19,6 +19,7 @@ using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
+using Lucene.Net.Support;
namespace Lucene.Net.Util
{
@@ -53,7 +54,7 @@ namespace Lucene.Net.Util
if (s_tempDirectory == null)
{
- string tempDirectory = SupportClass.AppSettings.Get("tempDir", "");
+ string tempDirectory = AppSettings.Get("tempDir", "");
if (string.IsNullOrWhiteSpace(tempDirectory) ||
!Directory.Exists(tempDirectory))