You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ar...@apache.org on 2009/11/03 19:06:38 UTC
svn commit: r832486 [16/29] - in /incubator/lucene.net/trunk/C#/src: ./
Demo/DeleteFiles/ Demo/DemoLib/ Demo/IndexFiles/ Demo/IndexHtml/
Demo/SearchFiles/ Lucene.Net/ Lucene.Net/Analysis/ Lucene.Net/Document/
Lucene.Net/Index/ Lucene.Net/Search/ Lucene...
Modified: incubator/lucene.net/trunk/C#/src/Test/Search/CheckHits.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/CheckHits.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/CheckHits.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/CheckHits.cs Tue Nov 3 18:06:27 2009
@@ -1,4 +1,4 @@
-/*
+/*
* 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.
@@ -27,25 +27,9 @@
public class CheckHits
{
- private class AnonymousClassHitCollector : HitCollector
- {
- public AnonymousClassHitCollector(System.Collections.Hashtable actual)
- {
- InitBlock(actual);
- }
- private void InitBlock(System.Collections.Hashtable actual)
- {
- this.actual = actual;
- }
- private System.Collections.Hashtable actual;
- public override void Collect(int doc, float score)
- {
- actual.Add((System.Int32) doc, (System.Int32) doc);
- }
- }
- /// <summary> Some explains methods calculate their vlaues though a slightly
- /// differnet order of operations from the acctaul scoring method ...
+ /// <summary> Some explains methods calculate their values though a slightly
+ /// different order of operations from the actual scoring method ...
/// this allows for a small amount of variation
/// </summary>
public static float EXPLAIN_SCORE_TOLERANCE_DELTA = 0.00005f;
@@ -61,7 +45,7 @@
System.Collections.Hashtable ignore = new System.Collections.Hashtable();
for (int i = 0; i < results.Length; i++)
{
- ignore.Add((System.Int32) results[i], (System.Int32) results[i]);
+ SupportClass.CollectionsHelper.AddIfNotContains(ignore, (System.Int32) results[i]);
}
int maxDoc = searcher.MaxDoc();
@@ -72,9 +56,7 @@
Explanation exp = searcher.Explain(q, doc);
Assert.IsNotNull(exp, "Explanation of [[" + d + "]] for #" + doc + " is null");
- //Assert.AreEqual(0.0f, exp.GetValue(), 0.0f, "Explanation of [[" + d + "]] for #" + doc + " doesn't indicate non-match: " + exp.ToString());
- // also check for NaN
- Assert.AreEqual(0.0f, float.IsNaN(exp.GetValue()) ? 0.0f : exp.GetValue(), 0.0f, "Explanation of [[" + d + "]] for #" + doc + " doesn't indicate non-match: " + exp.ToString());
+ Assert.AreEqual(0.0f, exp.GetValue(), 0.0f, "Explanation of [[" + d + "]] for #" + doc + " doesn't indicate non-match: " + exp.ToString());
}
}
@@ -90,7 +72,7 @@
/// </param>
/// <param name="searcher">the searcher to test the query against
/// </param>
- /// <param name="defaultFieldName">used for displaing the query in assertion messages
+ /// <param name="defaultFieldName">used for displaying the query in assertion messages
/// </param>
/// <param name="results">a list of documentIds that must match the query
/// </param>
@@ -101,22 +83,60 @@
public static void CheckHitCollector(Query query, System.String defaultFieldName, Searcher searcher, int[] results)
{
- System.Collections.ArrayList correct = new System.Collections.ArrayList(results.Length);
+ QueryUtils.Check(query, searcher);
+
+ System.Collections.Hashtable correct = new System.Collections.Hashtable();
for (int i = 0; i < results.Length; i++)
{
- correct.Add(results[i]);
+ SupportClass.CollectionsHelper.AddIfNotContains(correct, (System.Int32) results[i]);
}
-
System.Collections.Hashtable actual = new System.Collections.Hashtable();
- searcher.Search(query, new AnonymousClassHitCollector(actual));
-
- System.Collections.IDictionaryEnumerator e = actual.GetEnumerator();
- while (e.MoveNext())
+ Collector c = new SetCollector(actual);
+
+ searcher.Search(query, c);
+ Assert.AreEqual(correct, actual, "Simple: " + query.ToString(defaultFieldName));
+
+ for (int i = - 1; i < 2; i++)
{
- Assert.Contains(e.Key, correct, query.ToString(defaultFieldName));
+ actual.Clear();
+ QueryUtils.WrapSearcher(searcher, i).Search(query, c);
+ Assert.AreEqual(correct, actual, "Wrap Searcher " + i + ": " + query.ToString(defaultFieldName));
}
- QueryUtils.Check(query, searcher);
+ if (!(searcher is IndexSearcher))
+ return ;
+
+ for (int i = - 1; i < 2; i++)
+ {
+ actual.Clear();
+ QueryUtils.WrapUnderlyingReader((IndexSearcher) searcher, i).Search(query, c);
+ Assert.AreEqual(correct, actual, "Wrap Reader " + i + ": " + query.ToString(defaultFieldName));
+ }
+ }
+
+ public class SetCollector:Collector
+ {
+ internal System.Collections.Hashtable bag;
+ public SetCollector(System.Collections.Hashtable bag)
+ {
+ this.bag = bag;
+ }
+ private int base_Renamed = 0;
+ public override void SetScorer(Scorer scorer)
+ {
+ }
+ public override void Collect(int doc)
+ {
+ SupportClass.CollectionsHelper.AddIfNotContains(bag, (System.Int32)(doc + base_Renamed));
+ }
+ public override void SetNextReader(IndexReader reader, int docBase)
+ {
+ base_Renamed = docBase;
+ }
+ public override bool AcceptsDocsOutOfOrder()
+ {
+ return true;
+ }
}
/// <summary> Tests that a query matches the an expected set of documents using Hits.
@@ -136,36 +156,32 @@
/// </param>
/// <seealso cref="Searcher.Search(Query)">
/// </seealso>
- /// <seealso cref="CheckHitCollector">
+ /// <seealso cref="checkHitCollector">
/// </seealso>
- public static void CheckHits_Renamed(Query query, System.String defaultFieldName, Searcher searcher, int[] results)
+ public static void CheckHits_Renamed_Method(Query query, System.String defaultFieldName, Searcher searcher, int[] results)
{
if (searcher is IndexSearcher)
{
- QueryUtils.Check(query, (IndexSearcher) searcher);
+ QueryUtils.Check(query, searcher);
}
ScoreDoc[] hits = searcher.Search(query, null, 1000).scoreDocs;
- System.Collections.ArrayList correct = new System.Collections.ArrayList(results.Length);
+ System.Collections.ArrayList correct = new System.Collections.ArrayList();
for (int i = 0; i < results.Length; i++)
{
- correct.Add(results[i]);
+ SupportClass.CollectionsHelper.AddIfNotContains(correct, results[i]);
}
-
- System.Collections.ArrayList actual = new System.Collections.ArrayList(hits.Length);
+ correct.Sort();
+
+ System.Collections.ArrayList actual = new System.Collections.ArrayList();
for (int i = 0; i < hits.Length; i++)
{
- actual.Add(hits[i].doc);
+ SupportClass.CollectionsHelper.AddIfNotContains(actual, hits[i].doc);
}
+ actual.Sort();
- Assert.AreEqual(correct.Count, actual.Count);
- correct.Sort();
- actual.Sort();
- for (int i = 0; i < correct.Count; i++)
- {
- Assert.AreEqual(correct[i], actual[i]);
- }
+ Assert.AreEqual(correct, actual, query.ToString(defaultFieldName));
QueryUtils.Check(query, searcher);
}
@@ -173,7 +189,7 @@
/// <summary>Tests that a Hits has an expected order of documents </summary>
public static void CheckDocIds(System.String mes, int[] results, ScoreDoc[] hits)
{
- Assert.AreEqual(results.Length, hits.Length, mes + " nr of hits");
+ Assert.AreEqual(hits.Length, results.Length, mes + " nr of hits");
for (int i = 0; i < results.Length; i++)
{
Assert.AreEqual(results[i], hits[i].doc, mes + " doc nrs for hit " + i);
@@ -183,15 +199,15 @@
/// <summary>Tests that two queries have an expected order of documents,
/// and that the two queries have the same score values.
/// </summary>
- public static void CheckHitsQuery(Query query, ScoreDoc[] hits1, ScoreDoc[] hits2, int[] results)
+ public static void CheckHitsQuery(Query query, ScoreDoc[] hits1, ScoreDoc[] hits2, int[] results)
{
CheckDocIds("hits1", results, hits1);
CheckDocIds("hits2", results, hits2);
CheckEqual(query, hits1, hits2);
}
-
- public static void CheckEqual(Query query, ScoreDoc[] hits1, ScoreDoc[] hits2)
+
+ public static void CheckEqual(Query query, ScoreDoc[] hits1, ScoreDoc[] hits2)
{
float scoreTolerance = 1.0e-6f;
if (hits1.Length != hits2.Length)
@@ -200,19 +216,19 @@
}
for (int i = 0; i < hits1.Length; i++)
{
- if (hits1[i].doc != hits2[i].doc)
+ if (hits1[i].doc != hits2[i].doc)
{
Assert.Fail("Hit " + i + " docnumbers don't match\n" + Hits2str(hits1, hits2, 0, 0) + "for query:" + query.ToString());
}
-
- if ((hits1[i].doc != hits2[i].doc) || System.Math.Abs(hits1[i].score - hits2[i].score) > scoreTolerance)
+
+ if ((hits1[i].doc != hits2[i].doc) || System.Math.Abs(hits1[i].score - hits2[i].score) > scoreTolerance)
{
Assert.Fail("Hit " + i + ", doc nrs " + hits1[i].doc + " and " + hits2[i].doc + "\nunequal : " + hits1[i].score + "\n and: " + hits2[i].score + "\nfor query:" + query.ToString());
}
}
}
-
- public static System.String Hits2str(ScoreDoc[] hits1, ScoreDoc[] hits2, int start, int end)
+
+ public static System.String Hits2str(ScoreDoc[] hits1, ScoreDoc[] hits2, int start, int end)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
int len1 = hits1 == null?0:hits1.Length;
@@ -274,7 +290,7 @@
/// </summary>
/// <seealso cref="ExplanationAsserter">
/// </seealso>
- /// <seealso cref="CheckExplanations(Query, String, Searcher, bool) for a">
+ /// <seealso cref="CheckExplanations(Query, String, Searcher, boolean) for a">
/// "deep" testing of the explanation details.
///
/// </seealso>
@@ -362,13 +378,13 @@
int k2 = descr.IndexOf(" ", k1);
try
{
- x = SupportClass.Single.Parse(descr.Substring(k1, (k2) - (k1)).Trim());
+ x = System.Single.Parse(descr.Substring(k1, (k2) - (k1)).Trim());
if (descr.Substring(k2).Trim().Equals("times others of:"))
{
maxTimesOthers = true;
}
}
- catch (System.FormatException)
+ catch (System.FormatException e)
{
}
}
@@ -417,12 +433,12 @@
/// </summary>
/// <seealso cref="ExplanationAsserter">
/// </seealso>
- public class ExplanationAssertingSearcher : IndexSearcher
+ public class ExplanationAssertingSearcher:IndexSearcher
{
- public ExplanationAssertingSearcher(Directory d) : base(d)
+ public ExplanationAssertingSearcher(Directory d):base(d)
{
}
- public ExplanationAssertingSearcher(IndexReader r) : base(r)
+ public ExplanationAssertingSearcher(IndexReader r):base(r)
{
}
protected internal virtual void CheckExplanations(Query q)
@@ -435,13 +451,25 @@
CheckExplanations(query);
return base.Search(query, filter, n, sort);
}
+ /// <deprecated> use {@link #Search(Query, Collector)} instead.
+ /// </deprecated>
public override void Search(Query query, HitCollector results)
{
+ Search(query, new HitCollectorWrapper(results));
+ }
+ public override void Search(Query query, Collector results)
+ {
CheckExplanations(query);
base.Search(query, results);
}
+ /// <deprecated> use {@link #Search(Query, Filter, Collector)} instead.
+ /// </deprecated>
public override void Search(Query query, Filter filter, HitCollector results)
{
+ Search(query, filter, new HitCollectorWrapper(results));
+ }
+ public override void Search(Query query, Filter filter, Collector results)
+ {
CheckExplanations(query);
base.Search(query, filter, results);
}
@@ -462,7 +490,7 @@
/// </summary>
/// <seealso cref="CheckHits.verifyExplanation">
/// </seealso>
- public class ExplanationAsserter : HitCollector
+ public class ExplanationAsserter:Collector
{
/// <deprecated>
@@ -476,6 +504,9 @@
internal System.String d;
internal bool deep;
+ internal Scorer scorer;
+ private int base_Renamed = 0;
+
/// <summary>Constructs an instance which does shallow tests on the Explanation </summary>
public ExplanationAsserter(Query q, System.String defaultFieldName, Searcher s):this(q, defaultFieldName, s, false)
{
@@ -487,11 +518,16 @@
this.d = q.ToString(defaultFieldName);
this.deep = deep;
}
-
- public override void Collect(int doc, float score)
+
+ public override void SetScorer(Scorer scorer)
+ {
+ this.scorer = scorer;
+ }
+
+ public override void Collect(int doc)
{
Explanation exp = null;
-
+ doc = doc + base_Renamed;
try
{
exp = s.Explain(q, doc);
@@ -502,8 +538,16 @@
}
Assert.IsNotNull(exp, "Explanation of [[" + d + "]] for #" + doc + " is null");
- Assert.AreEqual(score, exp.GetValue(), SCORE_TOLERANCE_DELTA, "Score of [[" + d + "]] for #" + doc + " does not match explanation: " + exp.ToString());
+ Lucene.Net.Search.CheckHits.VerifyExplanation(d, doc, scorer.Score(), deep, exp);
+ }
+ public override void SetNextReader(IndexReader reader, int docBase)
+ {
+ base_Renamed = docBase;
+ }
+ public override bool AcceptsDocsOutOfOrder()
+ {
+ return true;
}
}
}
-}
+}
\ No newline at end of file
Modified: incubator/lucene.net/trunk/C#/src/Test/Search/Function/FunctionTestSetup.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Function/FunctionTestSetup.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Function/FunctionTestSetup.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Function/FunctionTestSetup.cs Tue Nov 3 18:06:27 2009
@@ -1,4 +1,4 @@
-/*
+/*
* 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.
@@ -19,6 +19,8 @@
using NUnit.Framework;
+using Analyzer = Lucene.Net.Analysis.Analyzer;
+using StandardAnalyzer = Lucene.Net.Analysis.Standard.StandardAnalyzer;
using Document = Lucene.Net.Documents.Document;
using Field = Lucene.Net.Documents.Field;
using Fieldable = Lucene.Net.Documents.Fieldable;
@@ -26,15 +28,13 @@
using Directory = Lucene.Net.Store.Directory;
using RAMDirectory = Lucene.Net.Store.RAMDirectory;
using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
-using Analyzer = Lucene.Net.Analysis.Analyzer;
-using StandardAnalyzer = Lucene.Net.Analysis.Standard.StandardAnalyzer;
namespace Lucene.Net.Search.Function
{
/// <summary> Setup for function tests</summary>
- [TestFixture]
- public /*abstract*/ class FunctionTestSetup : LuceneTestCase
+ [TestFixture]
+ public abstract class FunctionTestSetup:LuceneTestCase
{
/// <summary> Actual score computation order is slightly different than assumptios
@@ -57,16 +57,15 @@
protected internal Analyzer anlzr;
/* @override constructor */
- //public FunctionTestSetup(System.String name):base(name)
- //{
- //}
+ public FunctionTestSetup(System.String name):base(name)
+ {
+ }
/* @override */
[TearDown]
public override void TearDown()
{
base.TearDown();
- base.TearDown();
dir = null;
anlzr = null;
}
@@ -77,6 +76,7 @@
{
base.SetUp();
// prepare a small index with just a few documents.
+ base.SetUp();
dir = new RAMDirectory();
anlzr = new StandardAnalyzer();
IndexWriter iw = new IndexWriter(dir, anlzr, IndexWriter.MaxFieldLength.LIMITED);
@@ -142,7 +142,7 @@
// extract expected doc score from its ID Field: "ID7" --> 7.0
protected internal virtual float ExpectedFieldScore(System.String docIDFieldVal)
{
- return SupportClass.Single.Parse(docIDFieldVal.Substring(2));
+ return System.Single.Parse(docIDFieldVal.Substring(2));
}
// debug messages (change DBG to true for anything to print)
@@ -153,11 +153,5 @@
System.Console.Out.WriteLine(o.ToString());
}
}
-
- [Test]
- override public void TestDummy()
- {
- // So that NUnit doesn't complain
- }
}
}
\ No newline at end of file
Added: incubator/lucene.net/trunk/C#/src/Test/Search/Function/JustCompileSearchSpans.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Function/JustCompileSearchSpans.cs?rev=832486&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Function/JustCompileSearchSpans.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Function/JustCompileSearchSpans.cs Tue Nov 3 18:06:27 2009
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+using NUnit.Framework;
+
+using IndexReader = Lucene.Net.Index.IndexReader;
+using FieldCache = Lucene.Net.Search.FieldCache;
+
+namespace Lucene.Net.Search.Function
+{
+
+ /// <summary> Holds all implementations of classes in the o.a.l.s.function package as a
+ /// back-compatibility test. It does not run any tests per-se, however if
+ /// someone adds a method to an interface or abstract method to an abstract
+ /// class, one of the implementations here will fail to compile and so we know
+ /// back-compat policy was violated.
+ /// </summary>
+ sealed class JustCompileSearchFunction
+ {
+
+ private const System.String UNSUPPORTED_MSG = "unsupported: used for back-compat testing only !";
+
+ internal sealed class JustCompileDocValues:DocValues
+ {
+
+ public override float FloatVal(int doc)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.Function.JustCompileSearchFunction.UNSUPPORTED_MSG);
+ }
+
+ public override System.String ToString(int doc)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.Function.JustCompileSearchFunction.UNSUPPORTED_MSG);
+ }
+ }
+
+ [Serializable]
+ internal sealed class JustCompileFieldCacheSource:FieldCacheSource
+ {
+
+ public JustCompileFieldCacheSource(System.String field):base(field)
+ {
+ }
+
+ public override bool CachedFieldSourceEquals(FieldCacheSource other)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.Function.JustCompileSearchFunction.UNSUPPORTED_MSG);
+ }
+
+ public override int CachedFieldSourceHashCode()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.Function.JustCompileSearchFunction.UNSUPPORTED_MSG);
+ }
+
+ public override DocValues GetCachedFieldValues(FieldCache cache, System.String field, IndexReader reader)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.Function.JustCompileSearchFunction.UNSUPPORTED_MSG);
+ }
+ }
+
+ [Serializable]
+ internal sealed class JustCompileValueSource:ValueSource
+ {
+
+ public override System.String Description()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.Function.JustCompileSearchFunction.UNSUPPORTED_MSG);
+ }
+
+ public override bool Equals(System.Object o)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.Function.JustCompileSearchFunction.UNSUPPORTED_MSG);
+ }
+
+ public override DocValues GetValues(IndexReader reader)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.Function.JustCompileSearchFunction.UNSUPPORTED_MSG);
+ }
+
+ public override int GetHashCode()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.Function.JustCompileSearchFunction.UNSUPPORTED_MSG);
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestCustomScoreQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Function/TestCustomScoreQuery.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestCustomScoreQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestCustomScoreQuery.cs Tue Nov 3 18:06:27 2009
@@ -1,4 +1,4 @@
-/*
+/*
* 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.
@@ -31,28 +31,13 @@
{
/// <summary> Test CustomScoreQuery search.</summary>
- [TestFixture]
- public class TestCustomScoreQuery : FunctionTestSetup
+ [TestFixture]
+ public class TestCustomScoreQuery:FunctionTestSetup
{
/* @override constructor */
- //public TestCustomScoreQuery(System.String name):base(name)
- //{
- //}
-
- /* @override */
- [TearDown]
- public override void TearDown()
- {
- base.TearDown();
- }
-
- /* @override */
- [SetUp]
- public override void SetUp()
+ public TestCustomScoreQuery(System.String name):base(name)
{
- // prepare a small index with just a few documents.
- base.SetUp();
}
/// <summary>Test that CustomScoreQuery of Type.BYTE returns the expected scores. </summary>
@@ -95,7 +80,7 @@
// must have static class otherwise serialization tests fail
[Serializable]
- private class CustomAddQuery : CustomScoreQuery
+ private class CustomAddQuery:CustomScoreQuery
{
// constructor
internal CustomAddQuery(Query q, ValueSourceQuery qValSrc):base(q, qValSrc)
@@ -127,7 +112,7 @@
// must have static class otherwise serialization tests fail
[Serializable]
- private class CustomMulAddQuery : CustomScoreQuery
+ private class CustomMulAddQuery:CustomScoreQuery
{
// constructor
internal CustomMulAddQuery(Query q, ValueSourceQuery qValSrc1, ValueSourceQuery qValSrc2):base(q, new ValueSourceQuery[]{qValSrc1, qValSrc2})
@@ -179,10 +164,10 @@
float boost = (float) dboost;
IndexSearcher s = new IndexSearcher(dir);
FieldScoreQuery qValSrc = new FieldScoreQuery(field, tp); // a query that would score by the field
- Lucene.Net.QueryParsers.QueryParser qp = new Lucene.Net.QueryParsers.QueryParser(TEXT_FIELD, anlzr);
+ QueryParser qp = new QueryParser(TEXT_FIELD, anlzr);
System.String qtxt = "first aid text"; // from the doc texts in FunctionQuerySetup.
- // regular (bool) query.
+ // regular (boolean) query.
Query q1 = qp.Parse(qtxt);
Log(q1);
Added: incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestDocValues.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Function/TestDocValues.cs?rev=832486&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestDocValues.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestDocValues.cs Tue Nov 3 18:06:27 2009
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+using NUnit.Framework;
+
+using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
+
+namespace Lucene.Net.Search.Function
+{
+
+ /// <summary> DocValues TestCase </summary>
+ [TestFixture]
+ public class TestDocValues : LuceneTestCase
+ {
+
+ /* @override constructor */
+ public TestDocValues(System.String name):base(name)
+ {
+ }
+
+ [Test]
+ public virtual void TestGetMinValue()
+ {
+ float[] innerArray = new float[]{1.0f, 2.0f, - 1.0f, 100.0f};
+ DocValuesTestImpl docValues = new DocValuesTestImpl(innerArray);
+ Assert.AreEqual(- 1.0f, docValues.GetMinValue(), 0, "-1.0f is the min value in the source array");
+
+ // test with without values - NaN
+ innerArray = new float[]{};
+ docValues = new DocValuesTestImpl(innerArray);
+ Assert.IsTrue(System.Single.IsNaN(docValues.GetMinValue()), "max is NaN - no values in inner array");
+ }
+
+ [Test]
+ public virtual void TestGetMaxValue()
+ {
+ float[] innerArray = new float[]{1.0f, 2.0f, - 1.0f, 10.0f};
+ DocValuesTestImpl docValues = new DocValuesTestImpl(innerArray);
+ Assert.AreEqual(10.0f, docValues.GetMaxValue(), 0, "10.0f is the max value in the source array");
+
+ innerArray = new float[]{- 3.0f, - 1.0f, - 100.0f};
+ docValues = new DocValuesTestImpl(innerArray);
+ Assert.AreEqual(- 1.0f, docValues.GetMaxValue(), 0, "-1.0f is the max value in the source array");
+
+ innerArray = new float[]{- 3.0f, - 1.0f, 100.0f, System.Single.MaxValue, System.Single.MaxValue - 1};
+ docValues = new DocValuesTestImpl(innerArray);
+ Assert.AreEqual(System.Single.MaxValue, docValues.GetMaxValue(), 0, System.Single.MaxValue + " is the max value in the source array");
+
+ // test with without values - NaN
+ innerArray = new float[]{};
+ docValues = new DocValuesTestImpl(innerArray);
+ Assert.IsTrue(System.Single.IsNaN(docValues.GetMaxValue()), "max is NaN - no values in inner array");
+ }
+
+ [Test]
+ public virtual void TestGetAverageValue()
+ {
+ float[] innerArray = new float[]{1.0f, 1.0f, 1.0f, 1.0f};
+ DocValuesTestImpl docValues = new DocValuesTestImpl(innerArray);
+ Assert.AreEqual(1.0f, docValues.GetAverageValue(), 0, "the average is 1.0f");
+
+ innerArray = new float[]{1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f};
+ docValues = new DocValuesTestImpl(innerArray);
+ Assert.AreEqual(3.5f, docValues.GetAverageValue(), 0, "the average is 3.5f");
+
+ // test with negative values
+ innerArray = new float[]{- 1.0f, 2.0f};
+ docValues = new DocValuesTestImpl(innerArray);
+ Assert.AreEqual(0.5f, docValues.GetAverageValue(), 0, "the average is 0.5f");
+
+ // test with without values - NaN
+ innerArray = new float[]{};
+ docValues = new DocValuesTestImpl(innerArray);
+ Assert.IsTrue(System.Single.IsNaN(docValues.GetAverageValue()), "the average is NaN - no values in inner array");
+ }
+
+ internal class DocValuesTestImpl:DocValues
+ {
+ internal float[] innerArray;
+
+ internal DocValuesTestImpl(float[] innerArray)
+ {
+ this.innerArray = innerArray;
+ }
+
+ /// <seealso cref="Lucene.Net.Search.Function.DocValues.FloatVal(int)">
+ /// </seealso>
+ /* @Override */
+ public override float FloatVal(int doc)
+ {
+ return innerArray[doc];
+ }
+
+ /// <seealso cref="Lucene.Net.Search.Function.DocValues.ToString(int)">
+ /// </seealso>
+ /* @Override */
+ public override System.String ToString(int doc)
+ {
+ return System.Convert.ToString(doc);
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestFieldScoreQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Function/TestFieldScoreQuery.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestFieldScoreQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestFieldScoreQuery.cs Tue Nov 3 18:06:27 2009
@@ -1,4 +1,4 @@
-/*
+/*
* 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,6 +20,7 @@
using NUnit.Framework;
using CorruptIndexException = Lucene.Net.Index.CorruptIndexException;
+using IndexReader = Lucene.Net.Index.IndexReader;
using IndexSearcher = Lucene.Net.Search.IndexSearcher;
using Query = Lucene.Net.Search.Query;
using QueryUtils = Lucene.Net.Search.QueryUtils;
@@ -39,28 +40,13 @@
/// <p>
/// The exact score tests use TopDocs top to verify the exact score.
/// </summary>
- [TestFixture]
- public class TestFieldScoreQuery : FunctionTestSetup
+ [TestFixture]
+ public class TestFieldScoreQuery:FunctionTestSetup
{
/* @override constructor */
- //public TestFieldScoreQuery(System.String name):base(name)
- //{
- //}
-
- /* @override */
- [TearDown]
- public override void TearDown()
+ public TestFieldScoreQuery(System.String name):base(name)
{
- base.TearDown();
- }
-
- /* @override */
- [SetUp]
- public override void SetUp()
- {
- // prepare a small index with just a few documents.
- base.SetUp();
}
/// <summary>Test that FieldScoreQuery of Type.BYTE returns docs in expected order. </summary>
@@ -205,7 +191,7 @@
{
// prepare expected array types for comparison
System.Collections.Hashtable expectedArrayTypes = new System.Collections.Hashtable();
- expectedArrayTypes[FieldScoreQuery.Type.BYTE] = new byte[0];
+ expectedArrayTypes[FieldScoreQuery.Type.BYTE] = new sbyte[0];
expectedArrayTypes[FieldScoreQuery.Type.SHORT] = new short[0];
expectedArrayTypes[FieldScoreQuery.Type.INT] = new int[0];
expectedArrayTypes[FieldScoreQuery.Type.FLOAT] = new float[0];
@@ -219,26 +205,31 @@
FieldScoreQuery q = new FieldScoreQuery(field, tp);
ScoreDoc[] h = s.Search(q, null, 1000).scoreDocs;
Assert.AreEqual(N_DOCS, h.Length, "All docs should be matched!");
- try
+ IndexReader[] readers = s.GetIndexReader().GetSequentialSubReaders();
+ for (int j = 0; j < readers.Length; j++)
{
- if (i == 0)
+ IndexReader reader = readers[j];
+ try
{
- innerArray = q.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray();
- Log(i + ". compare: " + innerArray.GetType() + " to " + expectedArrayTypes[tp].GetType());
- Assert.AreEqual(innerArray.GetType(), expectedArrayTypes[tp].GetType(), "field values should be cached in the correct array type!");
+ if (i == 0)
+ {
+ innerArray = q.valSrc_ForNUnit.GetValues(reader).GetInnerArray();
+ Log(i + ". compare: " + innerArray.GetType() + " to " + expectedArrayTypes[tp].GetType());
+ Assert.AreEqual(innerArray.GetType(), expectedArrayTypes[tp].GetType(), "field values should be cached in the correct array type!");
+ }
+ else
+ {
+ Log(i + ". compare: " + innerArray + " to " + q.valSrc_ForNUnit.GetValues(reader).GetInnerArray());
+ Assert.AreSame(innerArray, q.valSrc_ForNUnit.GetValues(reader).GetInnerArray(), "field values should be cached and reused!");
+ }
}
- else
- {
- Log(i + ". compare: " + innerArray + " to " + q.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray());
- Assert.AreSame(innerArray, q.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray(), "field values should be cached and reused!");
- }
- }
- catch (System.NotSupportedException)
- {
- if (!warned)
+ catch (System.NotSupportedException e)
{
- System.Console.Error.WriteLine("WARNING: " + TestName() + " cannot fully test values of " + q);
- warned = true;
+ if (!warned)
+ {
+ System.Console.Error.WriteLine("WARNING: " + TestName() + " cannot fully test values of " + q);
+ warned = true;
+ }
}
}
}
@@ -248,24 +239,29 @@
FieldScoreQuery q2 = new FieldScoreQuery(field, tp);
ScoreDoc[] h2 = s.Search(q2, null, 1000).scoreDocs;
Assert.AreEqual(N_DOCS, h2.Length, "All docs should be matched!");
- try
- {
- Log("compare: " + innerArray + " to " + q2.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray());
- Assert.AreNotSame(innerArray, q2.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray(), "cached field values should not be reused if reader as changed!");
- }
- catch (System.NotSupportedException)
+ IndexReader[] readers2 = s.GetIndexReader().GetSequentialSubReaders();
+ for (int j = 0; j < readers2.Length; j++)
{
- if (!warned)
+ IndexReader reader = readers2[j];
+ try
+ {
+ Log("compare: " + innerArray + " to " + q2.valSrc_ForNUnit.GetValues(reader).GetInnerArray());
+ Assert.AreNotSame(innerArray, q2.valSrc_ForNUnit.GetValues(reader).GetInnerArray(), "cached field values should not be reused if reader as changed!");
+ }
+ catch (System.NotSupportedException e)
{
- System.Console.Error.WriteLine("WARNING: " + TestName() + " cannot fully test values of " + q2);
- warned = true;
+ if (!warned)
+ {
+ System.Console.Error.WriteLine("WARNING: " + TestName() + " cannot fully test values of " + q2);
+ warned = true;
+ }
}
}
}
private System.String TestName()
{
- return GetType().FullName;
+ return GetType().Name + "." + "getName()"; // {{Aroush-2.9}} String junit.framework.TestCase.getName()
}
}
}
\ No newline at end of file
Modified: incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestOrdValues.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Function/TestOrdValues.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestOrdValues.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestOrdValues.cs Tue Nov 3 18:06:27 2009
@@ -1,4 +1,4 @@
-/*
+/*
* 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,6 +20,7 @@
using NUnit.Framework;
using CorruptIndexException = Lucene.Net.Index.CorruptIndexException;
+using IndexReader = Lucene.Net.Index.IndexReader;
using IndexSearcher = Lucene.Net.Search.IndexSearcher;
using Query = Lucene.Net.Search.Query;
using QueryUtils = Lucene.Net.Search.QueryUtils;
@@ -39,28 +40,13 @@
/// <p>
/// The exact score tests use TopDocs top to verify the exact score.
/// </summary>
- [TestFixture]
- public class TestOrdValues : FunctionTestSetup
+ [TestFixture]
+ public class TestOrdValues:FunctionTestSetup
{
/* @override constructor */
- //public TestOrdValues(System.String name):base(name)
- //{
- //}
-
- /* @override */
- [TearDown]
- public override void TearDown()
+ public TestOrdValues(System.String name):base(name)
{
- base.TearDown();
- }
-
- /* @override */
- [SetUp]
- public override void SetUp()
- {
- // prepare a small index with just a few documents.
- base.SetUp();
}
/// <summary>Test OrdFieldSource </summary>
@@ -84,17 +70,17 @@
ValueSource vs;
if (inOrder)
{
- vs = new OrdFieldSource(field);
+ vs = new MultiValueSource(new OrdFieldSource(field));
}
else
{
- vs = new ReverseOrdFieldSource(field);
+ vs = new MultiValueSource(new ReverseOrdFieldSource(field));
}
Query q = new ValueSourceQuery(vs);
Log("test: " + q);
QueryUtils.Check(q, s);
- ScoreDoc[] h = s.Search(q,null, 1000).scoreDocs;
+ ScoreDoc[] h = s.Search(q, null, 1000).scoreDocs;
Assert.AreEqual(N_DOCS, h.Length, "All docs should be matched!");
System.String prevID = inOrder?"IE":"IC"; // smaller than all ids of docs in this test ("ID0001", etc.)
@@ -168,8 +154,7 @@
}
/// <summary>Test caching for ReverseOrdFieldSource </summary>
- [Test]
- public virtual void TesCachingReverseOrd()
+ public virtual void tesCachingReverseOrd()
{
DoTestCaching(ID_FIELD, false);
}
@@ -194,21 +179,27 @@
vs = new ReverseOrdFieldSource(field);
}
ValueSourceQuery q = new ValueSourceQuery(vs);
- ScoreDoc[] h = s.Search(q, null, 1000).scoreDocs;
- try
+ ScoreDoc[] h = s.Search(q, null, 1000).scoreDocs;
+ try
{
Assert.AreEqual(N_DOCS, h.Length, "All docs should be matched!");
- if (i == 0)
- {
- innerArray = q.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray();
- }
- else
+ IndexReader[] readers = s.GetIndexReader().GetSequentialSubReaders();
+
+ for (int j = 0; j < readers.Length; j++)
{
- Log(i + ". compare: " + innerArray + " to " + q.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray());
- Assert.AreSame(innerArray, q.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray(), "field values should be cached and reused!");
+ IndexReader reader = readers[j];
+ if (i == 0)
+ {
+ innerArray = q.valSrc_ForNUnit.GetValues(reader).GetInnerArray();
+ }
+ else
+ {
+ Log(i + ". compare: " + innerArray + " to " + q.valSrc_ForNUnit.GetValues(reader).GetInnerArray());
+ Assert.AreSame(innerArray, q.valSrc_ForNUnit.GetValues(reader).GetInnerArray(), "field values should be cached and reused!");
+ }
}
}
- catch (System.NotSupportedException)
+ catch (System.NotSupportedException e)
{
if (!warned)
{
@@ -236,17 +227,23 @@
q2 = new ValueSourceQuery(vs2);
h2 = s.Search(q2, null, 1000).scoreDocs;
Assert.AreEqual(N_DOCS, h2.Length, "All docs should be matched!");
- try
- {
- Log("compare (should differ): " + innerArray + " to " + q2.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray());
- Assert.AreNotSame(innerArray, q2.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray(), "different values shuold be loaded for a different field!");
- }
- catch (System.NotSupportedException)
+ IndexReader[] readers2 = s.GetIndexReader().GetSequentialSubReaders();
+
+ for (int j = 0; j < readers2.Length; j++)
{
- if (!warned)
+ IndexReader reader = readers2[j];
+ try
{
- System.Console.Error.WriteLine("WARNING: " + TestName() + " cannot fully test values of " + q2);
- warned = true;
+ Log("compare (should differ): " + innerArray + " to " + q2.valSrc_ForNUnit.GetValues(reader).GetInnerArray());
+ Assert.AreNotSame(innerArray, q2.valSrc_ForNUnit.GetValues(reader).GetInnerArray(), "different values shuold be loaded for a different field!");
+ }
+ catch (System.NotSupportedException e)
+ {
+ if (!warned)
+ {
+ System.Console.Error.WriteLine("WARNING: " + TestName() + " cannot fully test values of " + q2);
+ warned = true;
+ }
}
}
@@ -263,24 +260,30 @@
q2 = new ValueSourceQuery(vs2);
h2 = s.Search(q2, null, 1000).scoreDocs;
Assert.AreEqual(N_DOCS, h2.Length, "All docs should be matched!");
- try
- {
- Log("compare (should differ): " + innerArray + " to " + q2.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray());
- Assert.AreNotSame(innerArray, q2.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray(), "cached field values should not be reused if reader as changed!");
- }
- catch (System.NotSupportedException)
+ readers2 = s.GetIndexReader().GetSequentialSubReaders();
+
+ for (int j = 0; j < readers2.Length; j++)
{
- if (!warned)
+ IndexReader reader = readers2[j];
+ try
{
- System.Console.Error.WriteLine("WARNING: " + TestName() + " cannot fully test values of " + q2);
- warned = true;
+ Log("compare (should differ): " + innerArray + " to " + q2.valSrc_ForNUnit.GetValues(reader).GetInnerArray());
+ Assert.AreNotEqual(innerArray, q2.valSrc_ForNUnit.GetValues(reader).GetInnerArray(), "cached field values should not be reused if reader as changed!");
+ }
+ catch (System.NotSupportedException e)
+ {
+ if (!warned)
+ {
+ System.Console.Error.WriteLine("WARNING: " + TestName() + " cannot fully test values of " + q2);
+ warned = true;
+ }
}
}
}
private System.String TestName()
{
- return GetType().FullName;
- }
+ return GetType().Name + "." + "getName()"; // {{Aroush-2.9}} String junit.framework.TestCase.getName()
+ }
}
}
\ No newline at end of file
Added: incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestValueSource.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Function/TestValueSource.cs?rev=832486&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestValueSource.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestValueSource.cs Tue Nov 3 18:06:27 2009
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+using NUnit.Framework;
+
+using Lucene.Net.Analysis;
+using Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.Store;
+using Lucene.Net.Util;
+using Lucene.Net.Search;
+using Lucene.Net.Search.Function;
+using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
+
+namespace Lucene.Net.Search.Function
+{
+
+ [TestFixture]
+ public class TestValueSource:LuceneTestCase
+ {
+
+ [Test]
+ public virtual void TestMultiValueSource()
+ {
+ Directory dir = new MockRAMDirectory();
+ IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
+ Document doc = new Document();
+ Field f = new Field("field", "", Field.Store.NO, Field.Index.NOT_ANALYZED);
+ doc.Add(f);
+
+ for (int i = 0; i < 17; i++)
+ {
+ f.SetValue("" + i);
+ w.AddDocument(doc);
+ w.Commit();
+ }
+
+ IndexReader r = w.GetReader();
+ w.Close();
+
+ Assert.IsTrue(r.GetSequentialSubReaders().Length > 1);
+
+ ValueSource s1 = new IntFieldSource("field");
+ DocValues v1 = s1.GetValues(r);
+ DocValues v2 = new MultiValueSource(s1).GetValues(r);
+
+ for (int i = 0; i < r.MaxDoc(); i++)
+ {
+ Assert.AreEqual(v1.IntVal(i), i);
+ Assert.AreEqual(v2.IntVal(i), i);
+ }
+
+ Lucene.Net.Search.FieldCache_Fields.DEFAULT.PurgeAllCaches();
+
+ r.Close();
+ dir.Close();
+ }
+ }
+}
\ No newline at end of file
Added: incubator/lucene.net/trunk/C#/src/Test/Search/JustCompileSearch.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/JustCompileSearch.cs?rev=832486&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/JustCompileSearch.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/JustCompileSearch.cs Tue Nov 3 18:06:27 2009
@@ -0,0 +1,548 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+using NUnit.Framework;
+
+using Document = Lucene.Net.Documents.Document;
+using FieldSelector = Lucene.Net.Documents.FieldSelector;
+using CorruptIndexException = Lucene.Net.Index.CorruptIndexException;
+using IndexReader = Lucene.Net.Index.IndexReader;
+using Term = Lucene.Net.Index.Term;
+using TermPositions = Lucene.Net.Index.TermPositions;
+using PriorityQueue = Lucene.Net.Util.PriorityQueue;
+
+namespace Lucene.Net.Search
+{
+
+ /// <summary> Holds all implementations of classes in the o.a.l.search package as a
+ /// back-compatibility test. It does not run any tests per-se, however if
+ /// someone adds a method to an interface or abstract method to an abstract
+ /// class, one of the implementations here will fail to compile and so we know
+ /// back-compat policy was violated.
+ /// </summary>
+ sealed class JustCompileSearch
+ {
+
+ private const System.String UNSUPPORTED_MSG = "unsupported: used for back-compat testing only !";
+
+ internal sealed class JustCompileSearcher:Searcher
+ {
+
+ public /*protected internal*/ override Weight CreateWeight(Query query)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override void Close()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override Document Doc(int i)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override int[] DocFreqs(Term[] terms)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override Explanation Explain(Query query, int doc)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override Similarity GetSimilarity()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override void Search(Query query, Collector results)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override void Search(Query query, Filter filter, Collector results)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override TopDocs Search(Query query, Filter filter, int n)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override TopFieldDocs Search(Query query, Filter filter, int n, Sort sort)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override TopDocs Search(Query query, int n)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override void SetSimilarity(Similarity similarity)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override int DocFreq(Term term)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override Explanation Explain(Weight weight, int doc)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override int MaxDoc()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override Query Rewrite(Query query)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override void Search(Weight weight, Filter filter, Collector results)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override TopDocs Search(Weight weight, Filter filter, int n)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override TopFieldDocs Search(Weight weight, Filter filter, int n, Sort sort)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override Document Doc(int n, FieldSelector fieldSelector)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }
+
+ internal sealed class JustCompileCollector:Collector
+ {
+
+ public override void Collect(int doc)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override void SetNextReader(IndexReader reader, int docBase)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override void SetScorer(Scorer scorer)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override bool AcceptsDocsOutOfOrder()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }
+
+ internal sealed class JustCompileDocIdSet:DocIdSet
+ {
+
+ public override DocIdSetIterator Iterator()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }
+
+ internal sealed class JustCompileDocIdSetIterator:DocIdSetIterator
+ {
+
+ /// <deprecated> delete in 3.0
+ /// </deprecated>
+ public override int Doc()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override int DocID()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ /// <deprecated> delete in 3.0
+ /// </deprecated>
+ public override bool Next()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ /// <deprecated> delete in 3.0
+ /// </deprecated>
+ public override bool SkipTo(int target)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override int NextDoc()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override int Advance(int target)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }
+
+ [Serializable]
+ internal sealed class JustCompileExtendedFieldCacheLongParser : Lucene.Net.Search.LongParser
+ {
+
+ public long ParseLong(System.String string_Renamed)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }
+
+ [Serializable]
+ internal sealed class JustCompileExtendedFieldCacheDoubleParser : Lucene.Net.Search.DoubleParser
+ {
+
+ public double ParseDouble(System.String string_Renamed)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }
+
+ internal sealed class JustCompileFieldComparator:FieldComparator
+ {
+
+ public override int Compare(int slot1, int slot2)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override int CompareBottom(int doc)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override void Copy(int slot, int doc)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override void SetBottom(int slot)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override void SetNextReader(IndexReader reader, int docBase)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override System.IComparable Value(int slot)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }
+
+ [Serializable]
+ internal sealed class JustCompileFieldComparatorSource:FieldComparatorSource
+ {
+
+ public override FieldComparator NewComparator(System.String fieldname, int numHits, int sortPos, bool reversed)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }
+
+ [Serializable]
+ internal sealed class JustCompileFilter:Filter
+ {
+ // Filter is just an abstract class with no abstract methods. However it is
+ // still added here in case someone will add abstract methods in the future.
+ }
+
+ internal sealed class JustCompileFilteredDocIdSet:FilteredDocIdSet
+ {
+
+ public JustCompileFilteredDocIdSet(DocIdSet innerSet):base(innerSet)
+ {
+ }
+
+ public /*protected internal*/ override bool Match(int docid)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }
+
+ internal sealed class JustCompileFilteredDocIdSetIterator:FilteredDocIdSetIterator
+ {
+
+ public JustCompileFilteredDocIdSetIterator(DocIdSetIterator innerIter):base(innerIter)
+ {
+ }
+
+ public /*protected internal*/ override bool Match(int doc)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }
+
+ internal sealed class JustCompileFilteredTermEnum:FilteredTermEnum
+ {
+
+ public override float Difference()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override bool EndEnum()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public /*protected internal*/ override bool TermCompare(Term term)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }
+
+ [Serializable]
+ internal sealed class JustCompileMultiTermQuery:MultiTermQuery
+ {
+
+ public /*protected internal*/ override FilteredTermEnum GetEnum(IndexReader reader)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }
+
+ /*internal sealed class JustCompilePhraseScorer : Lucene.Net.Search.PhraseScorer // {{Not needed for Lucene.Net}}
+ {
+
+ internal JustCompilePhraseScorer(Weight weight, TermPositions[] tps, int[] offsets, Similarity similarity, sbyte[] norms):base(weight, tps, offsets, similarity, norms)
+ {
+ }
+
+ protected internal override float PhraseFreq()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }*/
+
+ [Serializable]
+ internal sealed class JustCompileQuery:Query
+ {
+
+ public override System.String ToString(System.String field)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ override public System.Object Clone()
+ {
+ return null;
+ }
+ }
+
+ internal sealed class JustCompileScorer:Scorer
+ {
+
+ internal JustCompileScorer(Similarity similarity):base(similarity)
+ {
+ }
+
+ public /*protected internal*/ override bool Score(Collector collector, int max, int firstDocID)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override Explanation Explain(int doc)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override float Score()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ /// <deprecated> delete in 3.0
+ /// </deprecated>
+ public override int Doc()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override int DocID()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ /// <deprecated> delete in 3.0.
+ /// </deprecated>
+ public override bool Next()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ /// <deprecated> delete in 3.0.
+ /// </deprecated>
+ public override bool SkipTo(int target)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override int NextDoc()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override int Advance(int target)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }
+
+ [Serializable]
+ internal sealed class JustCompileSimilarity:Similarity
+ {
+
+ public override float Coord(int overlap, int maxOverlap)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override float Idf(int docFreq, int numDocs)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override float LengthNorm(System.String fieldName, int numTokens)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override float QueryNorm(float sumOfSquaredWeights)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override float SloppyFreq(int distance)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override float Tf(float freq)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }
+
+ [Serializable]
+ internal sealed class JustCompileSpanFilter:SpanFilter
+ {
+
+ public override SpanFilterResult BitSpans(IndexReader reader)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }
+
+ internal sealed class JustCompileTopDocsCollector:TopDocsCollector
+ {
+
+ internal JustCompileTopDocsCollector(PriorityQueue pq):base(pq)
+ {
+ }
+
+ public override void Collect(int doc)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override void SetNextReader(IndexReader reader, int docBase)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override void SetScorer(Scorer scorer)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override bool AcceptsDocsOutOfOrder()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }
+
+ [Serializable]
+ internal sealed class JustCompileWeight:Weight
+ {
+
+ public override Explanation Explain(IndexReader reader, int doc)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override Query GetQuery()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override float GetValue()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override void Normalize(float norm)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ /// <deprecated> delete in 3.0
+ /// </deprecated>
+ public Scorer Scorer(IndexReader reader)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override float SumOfSquaredWeights()
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+
+ public override Scorer Scorer(IndexReader reader, bool scoreDocsInOrder, bool topScorer)
+ {
+ throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: incubator/lucene.net/trunk/C#/src/Test/Search/MockFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/MockFilter.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/MockFilter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/MockFilter.cs Tue Nov 3 18:06:27 2009
@@ -1,4 +1,4 @@
-/*
+/*
* 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.
@@ -17,22 +17,19 @@
using System;
+using NUnit.Framework;
+
using IndexReader = Lucene.Net.Index.IndexReader;
using DocIdBitSet = Lucene.Net.Util.DocIdBitSet;
namespace Lucene.Net.Search
{
+
[Serializable]
- public class MockFilter : Filter
+ public class MockFilter:Filter
{
private bool wasCalled;
-
- [System.Obsolete()]
- public override System.Collections.BitArray Bits(IndexReader reader)
- {
- return null;
- }
-
+
public override DocIdSet GetDocIdSet(IndexReader reader)
{
wasCalled = true;
Modified: incubator/lucene.net/trunk/C#/src/Test/Search/Payloads/PayloadHelper.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Payloads/PayloadHelper.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Payloads/PayloadHelper.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Payloads/PayloadHelper.cs Tue Nov 3 18:06:27 2009
@@ -1,4 +1,4 @@
-/*
+/*
* 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.
@@ -15,109 +15,152 @@
* limitations under the License.
*/
-using Analyzer = Lucene.Net.Analysis.Analyzer;
-using LowerCaseTokenizer = Lucene.Net.Analysis.LowerCaseTokenizer;
-using Token = Lucene.Net.Analysis.Token;
-using TokenFilter = Lucene.Net.Analysis.TokenFilter;
-using TokenStream = Lucene.Net.Analysis.TokenStream;
+using System;
+
+using NUnit.Framework;
+
+using Lucene.Net.Analysis;
+using PayloadAttribute = Lucene.Net.Analysis.Tokenattributes.PayloadAttribute;
using Document = Lucene.Net.Documents.Document;
using Field = Lucene.Net.Documents.Field;
using IndexWriter = Lucene.Net.Index.IndexWriter;
-using _Payload = Lucene.Net.Index.Payload;
+using Payload = Lucene.Net.Index.Payload;
+using RAMDirectory = Lucene.Net.Store.RAMDirectory;
using IndexSearcher = Lucene.Net.Search.IndexSearcher;
using Similarity = Lucene.Net.Search.Similarity;
-using RAMDirectory = Lucene.Net.Store.RAMDirectory;
using English = Lucene.Net.Util.English;
namespace Lucene.Net.Search.Payloads
{
- public class PayloadHelper
- {
- private static readonly byte[] payloadField = new byte[] { 1 };
- private static readonly byte[] payloadMultiField1 = new byte[] { 2 };
- private static readonly byte[] payloadMultiField2 = new byte[] { 4 };
- public static readonly string NO_PAYLOAD_FIELD = "noPayloadField";
- public static readonly string MULTI_FIELD = "multiField";
- public static readonly string FIELD = "field";
-
- public class PayloadAnalyzer : Analyzer
- {
- public override TokenStream TokenStream(string fieldName, System.IO.TextReader reader)
- {
- TokenStream result = new LowerCaseTokenizer(reader);
- result = new PayloadFilter(result, fieldName);
- return result;
- }
- }
-
- public class PayloadFilter : TokenFilter
- {
- string fieldName;
- int numSeen = 0;
-
- public PayloadFilter(TokenStream input, string fieldName)
- : base(input)
- {
- this.fieldName = fieldName;
- }
-
- public override Token Next()
- {
- Token result = input.Next();
- if (result != null)
- {
- if (fieldName.Equals(FIELD))
- {
- result.SetPayload(new _Payload(PayloadHelper.payloadField));
- }
- else if (fieldName.Equals(MULTI_FIELD))
- {
- if (numSeen % 2 == 0)
- {
- result.SetPayload(new _Payload(PayloadHelper.payloadMultiField1));
- }
- else
- {
- result.SetPayload(new _Payload(PayloadHelper.payloadMultiField2));
- }
- numSeen++;
- }
-
- }
- return result;
- }
- }
-
- /**
- * Sets up a RAMDirectory, and adds documents (using English.intToEnglish()) with two fields: field and multiField
- * and analyzes them using the PayloadAnalyzer
- * @param similarity The Similarity class to use in the Searcher
- * @param numDocs The num docs to add
- * @return An IndexSearcher
- * @throws IOException
- */
- public IndexSearcher SetUp(Similarity similarity, int numDocs)
- {
- RAMDirectory directory = new RAMDirectory();
- PayloadAnalyzer analyzer = new PayloadAnalyzer();
- IndexWriter writer
- = new IndexWriter(directory, analyzer, true);
- writer.SetSimilarity(similarity);
- //writer.infoStream = System.out;
- for (int i = 0; i < numDocs; i++)
- {
- Document doc = new Document();
- doc.Add(new Field(FIELD, English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
- doc.Add(new Field(MULTI_FIELD, English.IntToEnglish(i) + " " + English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
- doc.Add(new Field(NO_PAYLOAD_FIELD, English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
- writer.AddDocument(doc);
- }
- //writer.optimize();
- writer.Close();
-
- IndexSearcher searcher = new IndexSearcher(directory);
- searcher.SetSimilarity(similarity);
- return searcher;
- }
- }
-}
+
+ /// <summary>
+ ///
+ ///
+ /// </summary>
+ public class PayloadHelper
+ {
+
+ private byte[] payloadField = new byte[]{1};
+ private byte[] payloadMultiField1 = new byte[]{2};
+ private byte[] payloadMultiField2 = new byte[]{4};
+ public const System.String NO_PAYLOAD_FIELD = "noPayloadField";
+ public const System.String MULTI_FIELD = "multiField";
+ public const System.String FIELD = "field";
+
+ public class PayloadAnalyzer:Analyzer
+ {
+ public PayloadAnalyzer(PayloadHelper enclosingInstance)
+ {
+ InitBlock(enclosingInstance);
+ }
+ private void InitBlock(PayloadHelper enclosingInstance)
+ {
+ this.enclosingInstance = enclosingInstance;
+ }
+ private PayloadHelper enclosingInstance;
+ public PayloadHelper Enclosing_Instance
+ {
+ get
+ {
+ return enclosingInstance;
+ }
+
+ }
+
+
+
+ public override TokenStream TokenStream(System.String fieldName, System.IO.TextReader reader)
+ {
+ TokenStream result = new LowerCaseTokenizer(reader);
+ result = new PayloadFilter(enclosingInstance, result, fieldName);
+ return result;
+ }
+ }
+
+ public class PayloadFilter:TokenFilter
+ {
+ private void InitBlock(PayloadHelper enclosingInstance)
+ {
+ this.enclosingInstance = enclosingInstance;
+ }
+ private PayloadHelper enclosingInstance;
+ public PayloadHelper Enclosing_Instance
+ {
+ get
+ {
+ return enclosingInstance;
+ }
+
+ }
+ internal System.String fieldName;
+ internal int numSeen = 0;
+ internal PayloadAttribute payloadAtt;
+
+ public PayloadFilter(PayloadHelper enclosingInstance, TokenStream input, System.String fieldName):base(input)
+ {
+ InitBlock(enclosingInstance);
+ this.fieldName = fieldName;
+ payloadAtt = (PayloadAttribute) AddAttribute(typeof(PayloadAttribute));
+ }
+
+ public override bool IncrementToken()
+ {
+
+ if (input.IncrementToken())
+ {
+ if (fieldName.Equals(Lucene.Net.Search.Payloads.PayloadHelper.FIELD))
+ {
+ payloadAtt.SetPayload(new Payload(Enclosing_Instance.payloadField));
+ }
+ else if (fieldName.Equals(Lucene.Net.Search.Payloads.PayloadHelper.MULTI_FIELD))
+ {
+ if (numSeen % 2 == 0)
+ {
+ payloadAtt.SetPayload(new Payload(Enclosing_Instance.payloadMultiField1));
+ }
+ else
+ {
+ payloadAtt.SetPayload(new Payload(Enclosing_Instance.payloadMultiField2));
+ }
+ numSeen++;
+ }
+ return true;
+ }
+ return false;
+ }
+ }
+
+ /// <summary> Sets up a RAMDirectory, and adds documents (using English.intToEnglish()) with two fields: field and multiField
+ /// and analyzes them using the PayloadAnalyzer
+ /// </summary>
+ /// <param name="similarity">The Similarity class to use in the Searcher
+ /// </param>
+ /// <param name="numDocs">The num docs to add
+ /// </param>
+ /// <returns> An IndexSearcher
+ /// </returns>
+ /// <throws> IOException </throws>
+ public virtual IndexSearcher SetUp(Similarity similarity, int numDocs)
+ {
+ RAMDirectory directory = new RAMDirectory();
+ PayloadAnalyzer analyzer = new PayloadAnalyzer(this);
+ IndexWriter writer = new IndexWriter(directory, analyzer, true);
+ writer.SetSimilarity(similarity);
+ //writer.infoStream = System.out;
+ for (int i = 0; i < numDocs; i++)
+ {
+ Document doc = new Document();
+ doc.Add(new Field(FIELD, English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
+ doc.Add(new Field(MULTI_FIELD, English.IntToEnglish(i) + " " + English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
+ doc.Add(new Field(NO_PAYLOAD_FIELD, English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
+ writer.AddDocument(doc);
+ }
+ //writer.optimize();
+ writer.Close();
+
+ IndexSearcher searcher = new IndexSearcher(directory);
+ searcher.SetSimilarity(similarity);
+ return searcher;
+ }
+ }
+}
\ No newline at end of file
Modified: incubator/lucene.net/trunk/C#/src/Test/Search/Payloads/TestBoostingTermQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Payloads/TestBoostingTermQuery.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Payloads/TestBoostingTermQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Payloads/TestBoostingTermQuery.cs Tue Nov 3 18:06:27 2009
@@ -1,4 +1,4 @@
-/*
+/*
* 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.
@@ -21,14 +21,15 @@
using Analyzer = Lucene.Net.Analysis.Analyzer;
using LowerCaseTokenizer = Lucene.Net.Analysis.LowerCaseTokenizer;
-using Token = Lucene.Net.Analysis.Token;
using TokenFilter = Lucene.Net.Analysis.TokenFilter;
using TokenStream = Lucene.Net.Analysis.TokenStream;
+using PayloadAttribute = Lucene.Net.Analysis.Tokenattributes.PayloadAttribute;
using Document = Lucene.Net.Documents.Document;
using Field = Lucene.Net.Documents.Field;
using IndexWriter = Lucene.Net.Index.IndexWriter;
-using _Payload = Lucene.Net.Index.Payload;
+using Payload = Lucene.Net.Index.Payload;
using Term = Lucene.Net.Index.Term;
+using RAMDirectory = Lucene.Net.Store.RAMDirectory;
using BooleanClause = Lucene.Net.Search.BooleanClause;
using BooleanQuery = Lucene.Net.Search.BooleanQuery;
using CheckHits = Lucene.Net.Search.CheckHits;
@@ -36,22 +37,16 @@
using IndexSearcher = Lucene.Net.Search.IndexSearcher;
using ScoreDoc = Lucene.Net.Search.ScoreDoc;
using TopDocs = Lucene.Net.Search.TopDocs;
-using _Spans = Lucene.Net.Search.Spans.Spans;
using TermSpans = Lucene.Net.Search.Spans.TermSpans;
-using RAMDirectory = Lucene.Net.Store.RAMDirectory;
using English = Lucene.Net.Util.English;
using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
namespace Lucene.Net.Search.Payloads
{
- [TestFixture]
- public class TestBoostingTermQuery : LuceneTestCase
+
+ [TestFixture]
+ public class TestBoostingTermQuery:LuceneTestCase
{
- public TestBoostingTermQuery() : base()
- {
- InitBlock();
- }
-
private void InitBlock()
{
similarity = new BoostingSimilarity();
@@ -67,7 +62,7 @@
InitBlock();
}
- private class PayloadAnalyzer : Analyzer
+ private class PayloadAnalyzer:Analyzer
{
public PayloadAnalyzer(TestBoostingTermQuery enclosingInstance)
{
@@ -96,7 +91,7 @@
}
}
- private class PayloadFilter : TokenFilter
+ private class PayloadFilter:TokenFilter
{
private void InitBlock(TestBoostingTermQuery enclosingInstance)
{
@@ -114,36 +109,42 @@
internal System.String fieldName;
internal int numSeen = 0;
+ internal PayloadAttribute payloadAtt;
+
public PayloadFilter(TestBoostingTermQuery enclosingInstance, TokenStream input, System.String fieldName):base(input)
{
InitBlock(enclosingInstance);
this.fieldName = fieldName;
+ payloadAtt = (PayloadAttribute) AddAttribute(typeof(PayloadAttribute));
}
- public override Token Next(Token reusableToken)
+ public override bool IncrementToken()
{
- System.Diagnostics.Debug.Assert(reusableToken != null);
- Token nextToken = input.Next(reusableToken);
- if (nextToken != null)
+ bool hasNext = input.IncrementToken();
+ if (hasNext)
{
if (fieldName.Equals("field"))
{
- nextToken.SetPayload(new _Payload(Enclosing_Instance.payloadField));
+ payloadAtt.SetPayload(new Payload(Enclosing_Instance.payloadField));
}
else if (fieldName.Equals("multiField"))
{
if (numSeen % 2 == 0)
{
- nextToken.SetPayload(new _Payload(Enclosing_Instance.payloadMultiField1));
+ payloadAtt.SetPayload(new Payload(Enclosing_Instance.payloadMultiField1));
}
else
{
- nextToken.SetPayload(new _Payload(Enclosing_Instance.payloadMultiField2));
+ payloadAtt.SetPayload(new Payload(Enclosing_Instance.payloadMultiField2));
}
numSeen++;
}
+ return true;
+ }
+ else
+ {
+ return false;
}
- return nextToken;
}
}
@@ -160,7 +161,7 @@
{
Document doc = new Document();
Field noPayloadField = new Field(PayloadHelper.NO_PAYLOAD_FIELD, English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED);
- //noPayloadField.SetBoost(0);
+ //noPayloadField.setBoost(0);
doc.Add(noPayloadField);
doc.Add(new Field("field", English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field("multiField", English.IntToEnglish(i) + " " + English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
@@ -194,12 +195,12 @@
Lucene.Net.Search.Spans.Spans spans = query.GetSpans(searcher.GetIndexReader());
Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
Assert.IsTrue(spans is TermSpans, "spans is not an instanceof " + typeof(TermSpans));
- /*float score = hits.score(0);
- for (int i =1; i < hits.length(); i++)
- {
- Assert.IsTrue(score == hits.score(i), "scores are not equal and they should be");
- }*/
- }
+ /*float score = hits.score(0);
+ for (int i =1; i < hits.length(); i++)
+ {
+ Assert.IsTrue(score == hits.score(i), "scores are not equal and they should be");
+ }*/
+ }
[Test]
public virtual void TestMultipleMatchesPerDoc()
@@ -257,8 +258,8 @@
[Test]
public virtual void TestNoPayload()
{
- BoostingTermQuery q1 = new BoostingTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "zero"));
- BoostingTermQuery q2 = new BoostingTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "foo"));
+ BoostingTermQuery q1 = new BoostingTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "zero"));
+ BoostingTermQuery q2 = new BoostingTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "foo"));
BooleanClause c1 = new BooleanClause(q1, BooleanClause.Occur.MUST);
BooleanClause c2 = new BooleanClause(q2, BooleanClause.Occur.MUST_NOT);
BooleanQuery query = new BooleanQuery();
@@ -269,21 +270,21 @@
Assert.IsTrue(hits.totalHits == 1, "hits Size: " + hits.totalHits + " is not: " + 1);
int[] results = new int[1];
results[0] = 0; //hits.scoreDocs[0].doc;
- CheckHits.CheckHitCollector(query, PayloadHelper.NO_PAYLOAD_FIELD, searcher, results);
+ CheckHits.CheckHitCollector(query, PayloadHelper.NO_PAYLOAD_FIELD, searcher, results);
}
- // must be static for weight serialization tests
+ // must be static for weight serialization tests
[Serializable]
- internal class BoostingSimilarity : DefaultSimilarity
+ internal class BoostingSimilarity:DefaultSimilarity
{
-
// TODO: Remove warning after API has been finalized
- public override float ScorePayload(System.String fieldName, byte[] payload, int offset, int length)
+ public override float ScorePayload(int docId, System.String fieldName, int start, int end, byte[] payload, int offset, int length)
{
//we know it is size 4 here, so ignore the offset/length
return payload[0];
}
+
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//Make everything else 1 so we see the effect of the payload
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!