You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by di...@apache.org on 2010/02/25 17:32:11 UTC
svn commit: r916340 [3/3] - in
/lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net: ./
FastVectorHighlighter.Net/ FastVectorHighlighter.Net/Properties/ Test/
Test/Properties/
Added: lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/IndexTimeSynonymTest.cs
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/FastVectorHighlighter.Net/Test/IndexTimeSynonymTest.cs?rev=916340&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/IndexTimeSynonymTest.cs (added)
+++ lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/IndexTimeSynonymTest.cs Thu Feb 25 16:32:11 2010
@@ -0,0 +1,378 @@
+/**
+ * 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 System.Collections.Generic;
+using System.Text;
+
+
+using Lucene.Net.Analysis;
+using Lucene.Net.Analysis.Tokenattributes;
+using Lucene.Net.Search;
+using Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.Util;
+
+using NUnit.Framework;
+
+namespace Lucene.Net.Search.Vectorhighlight
+{
+ [TestFixture]
+ public class IndexTimeSynonymTest : AbstractTestCase
+ {
+ [Test]
+ public void TestFieldTermStackIndex1wSearch1term()
+ {
+ MakeIndex1w();
+
+ FieldQuery fq = new FieldQuery(Tq("Mac"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ Assert.AreEqual(1, stack.termList.Count);
+ Assert.AreEqual("Mac(11,20,3)", stack.Pop().ToString());
+ }
+
+ [Test]
+ public void TestFieldTermStackIndex1wSearch2terms()
+ {
+ MakeIndex1w();
+
+ BooleanQuery bq = new BooleanQuery();
+ bq.Add(Tq("Mac"), Lucene.Net.Search.BooleanClause.Occur.SHOULD);
+ bq.Add(Tq("MacBook"), Lucene.Net.Search.BooleanClause.Occur.SHOULD);
+ FieldQuery fq = new FieldQuery(bq, true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ Assert.AreEqual(2, stack.termList.Count);
+ Dictionary<String, String> expectedSet = new Dictionary<String, String>();
+ expectedSet.Add("Mac(11,20,3)","");
+ expectedSet.Add("MacBook(11,20,3)","");
+ Assert.IsTrue(expectedSet.ContainsKey(stack.Pop().ToString()));
+ Assert.IsTrue(expectedSet.ContainsKey(stack.Pop().ToString()));
+ }
+
+ [Test]
+ public void TestFieldTermStackIndex1w2wSearch1term()
+ {
+ MakeIndex1w2w();
+
+ FieldQuery fq = new FieldQuery(Tq("pc"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ Assert.AreEqual(1, stack.termList.Count);
+ Assert.AreEqual("pc(3,5,1)", stack.Pop().ToString());
+ }
+
+ [Test]
+ public void TestFieldTermStackIndex1w2wSearch1phrase()
+ {
+ MakeIndex1w2w();
+
+ FieldQuery fq = new FieldQuery(PqF("personal", "computer"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ Assert.AreEqual(2, stack.termList.Count);
+ Assert.AreEqual("personal(3,5,1)", stack.Pop().ToString());
+ Assert.AreEqual("computer(3,5,2)", stack.Pop().ToString());
+ }
+
+ [Test]
+ public void TestFieldTermStackIndex1w2wSearch1partial()
+ {
+ MakeIndex1w2w();
+
+ FieldQuery fq = new FieldQuery(Tq("computer"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ Assert.AreEqual(1, stack.termList.Count);
+ Assert.AreEqual("computer(3,5,2)", stack.Pop().ToString());
+ }
+
+ [Test]
+ public void TestFieldTermStackIndex1w2wSearch1term1phrase()
+ {
+ MakeIndex1w2w();
+
+ BooleanQuery bq = new BooleanQuery();
+ bq.Add(Tq("pc"), Lucene.Net.Search.BooleanClause.Occur.SHOULD);
+ bq.Add(PqF("personal", "computer"), Lucene.Net.Search.BooleanClause.Occur.SHOULD);
+ FieldQuery fq = new FieldQuery(bq, true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ Assert.AreEqual(3, stack.termList.Count);
+ Dictionary<String, String> expectedSet = new Dictionary<String, String>();
+ expectedSet.Add("pc(3,5,1)","");
+ expectedSet.Add("personal(3,5,1)","");
+ Assert.IsTrue(expectedSet.ContainsKey(stack.Pop().ToString()));
+ Assert.IsTrue(expectedSet.ContainsKey(stack.Pop().ToString()));
+ Assert.AreEqual("computer(3,5,2)", stack.Pop().ToString());
+ }
+
+ [Test]
+ public void TestFieldTermStackIndex2w1wSearch1term()
+ {
+ MakeIndex2w1w();
+
+ FieldQuery fq = new FieldQuery(Tq("pc"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ Assert.AreEqual(1, stack.termList.Count);
+ Assert.AreEqual("pc(3,20,1)", stack.Pop().ToString());
+ }
+
+ [Test]
+ public void TestFieldTermStackIndex2w1wSearch1phrase()
+ {
+ MakeIndex2w1w();
+
+ FieldQuery fq = new FieldQuery(PqF("personal", "computer"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ Assert.AreEqual(2, stack.termList.Count);
+ Assert.AreEqual("personal(3,20,1)", stack.Pop().ToString());
+ Assert.AreEqual("computer(3,20,2)", stack.Pop().ToString());
+ }
+
+ [Test]
+ public void TestFieldTermStackIndex2w1wSearch1partial()
+ {
+ MakeIndex2w1w();
+
+ FieldQuery fq = new FieldQuery(Tq("computer"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ Assert.AreEqual(1, stack.termList.Count);
+ Assert.AreEqual("computer(3,20,2)", stack.Pop().ToString());
+ }
+
+ [Test]
+ public void TestFieldTermStackIndex2w1wSearch1term1phrase()
+ {
+ MakeIndex2w1w();
+
+ BooleanQuery bq = new BooleanQuery();
+ bq.Add(Tq("pc"), Lucene.Net.Search.BooleanClause.Occur.SHOULD);
+ bq.Add(PqF("personal", "computer"), Lucene.Net.Search.BooleanClause.Occur.SHOULD);
+ FieldQuery fq = new FieldQuery(bq, true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ Assert.AreEqual(3, stack.termList.Count);
+ Dictionary<String, String> expectedSet = new Dictionary<String, String>();
+ expectedSet.Add("pc(3,20,1)","");
+ expectedSet.Add("personal(3,20,1)","");
+ Assert.IsTrue(expectedSet.ContainsKey(stack.Pop().ToString()));
+ Assert.IsTrue(expectedSet.ContainsKey(stack.Pop().ToString()));
+ Assert.AreEqual("computer(3,20,2)", stack.Pop().ToString());
+ }
+
+ [Test]
+ public void TestFieldPhraseListIndex1w2wSearch1phrase()
+ {
+ MakeIndex1w2w();
+
+ FieldQuery fq = new FieldQuery(PqF("personal", "computer"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ FieldPhraseList fpl = new FieldPhraseList(stack, fq);
+ Assert.AreEqual(1, fpl.phraseList.Count);
+ Assert.AreEqual("personalcomputer(1.0)((3,5))", fpl.phraseList.First.Value.ToString());
+ Assert.AreEqual(3, fpl.phraseList.First.Value.GetStartOffset());
+ Assert.AreEqual(5, fpl.phraseList.First.Value.GetEndOffset());
+ }
+
+ [Test]
+ public void TestFieldPhraseListIndex1w2wSearch1partial()
+ {
+ MakeIndex1w2w();
+
+ FieldQuery fq = new FieldQuery(Tq("computer"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ FieldPhraseList fpl = new FieldPhraseList(stack, fq);
+ Assert.AreEqual(1, fpl.phraseList.Count);
+ Assert.AreEqual("computer(1.0)((3,5))", fpl.phraseList.First.Value.ToString());
+ Assert.AreEqual(3, fpl.phraseList.First.Value.GetStartOffset());
+ Assert.AreEqual(5, fpl.phraseList.First.Value.GetEndOffset());
+ }
+
+ [Test]
+ public void TestFieldPhraseListIndex1w2wSearch1term1phrase()
+ {
+ MakeIndex1w2w();
+
+ BooleanQuery bq = new BooleanQuery();
+ bq.Add(Tq("pc"), Lucene.Net.Search.BooleanClause.Occur.SHOULD);
+ bq.Add(PqF("personal", "computer"), Lucene.Net.Search.BooleanClause.Occur.SHOULD);
+ FieldQuery fq = new FieldQuery(bq, true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ FieldPhraseList fpl = new FieldPhraseList(stack, fq);
+ Assert.AreEqual(1, fpl.phraseList.Count);
+ Assert.IsTrue(fpl.phraseList.First.Value.ToString().IndexOf("(1.0)((3,5))") > 0);
+ Assert.AreEqual(3, fpl.phraseList.First.Value.GetStartOffset());
+ Assert.AreEqual(5, fpl.phraseList.First.Value.GetEndOffset());
+ }
+
+ [Test]
+ public void TestFieldPhraseListIndex2w1wSearch1term()
+ {
+ MakeIndex2w1w();
+
+ FieldQuery fq = new FieldQuery(Tq("pc"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ FieldPhraseList fpl = new FieldPhraseList(stack, fq);
+ Assert.AreEqual(1, fpl.phraseList.Count);
+ Assert.AreEqual("pc(1.0)((3,20))", fpl.phraseList.First.Value.ToString());
+ Assert.AreEqual(3, fpl.phraseList.First.Value.GetStartOffset());
+ Assert.AreEqual(20, fpl.phraseList.First.Value.GetEndOffset());
+ }
+
+ [Test]
+ public void TestFieldPhraseListIndex2w1wSearch1phrase()
+ {
+ MakeIndex2w1w();
+
+ FieldQuery fq = new FieldQuery(PqF("personal", "computer"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ FieldPhraseList fpl = new FieldPhraseList(stack, fq);
+ Assert.AreEqual(1, fpl.phraseList.Count);
+ Assert.AreEqual("personalcomputer(1.0)((3,20))", fpl.phraseList.First.Value.ToString());
+ Assert.AreEqual(3, fpl.phraseList.First.Value.GetStartOffset());
+ Assert.AreEqual(20, fpl.phraseList.First.Value.GetEndOffset());
+ }
+
+ [Test]
+ public void TestFieldPhraseListIndex2w1wSearch1partial()
+ {
+ MakeIndex2w1w();
+
+ FieldQuery fq = new FieldQuery(Tq("computer"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ FieldPhraseList fpl = new FieldPhraseList(stack, fq);
+ Assert.AreEqual(1, fpl.phraseList.Count);
+ Assert.AreEqual("computer(1.0)((3,20))", fpl.phraseList.First.Value.ToString());
+ Assert.AreEqual(3, fpl.phraseList.First.Value.GetStartOffset());
+ Assert.AreEqual(20, fpl.phraseList.First.Value.GetEndOffset());
+ }
+
+ [Test]
+ public void TestFieldPhraseListIndex2w1wSearch1term1phrase()
+ {
+ MakeIndex2w1w();
+
+ BooleanQuery bq = new BooleanQuery();
+ bq.Add(Tq("pc"), Lucene.Net.Search.BooleanClause.Occur.SHOULD);
+ bq.Add(PqF("personal", "computer"), Lucene.Net.Search.BooleanClause.Occur.SHOULD);
+ FieldQuery fq = new FieldQuery(bq, true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ FieldPhraseList fpl = new FieldPhraseList(stack, fq);
+ Assert.AreEqual(1, fpl.phraseList.Count);
+ Assert.IsTrue(fpl.phraseList.First.Value.ToString().IndexOf("(1.0)((3,20))") > 0);
+ Assert.AreEqual(3, fpl.phraseList.First.Value.GetStartOffset());
+ Assert.AreEqual(20, fpl.phraseList.First.Value.GetEndOffset());
+ }
+
+ private void MakeIndex1w()
+ {
+ // 11111111112
+ // 012345678901234567890
+ // I'll buy a Macintosh
+ // Mac
+ // MacBook
+ // 0 1 2 3
+ MakeSynonymIndex("I'll buy a Macintosh",
+ t("I'll", 0, 4),
+ t("buy", 5, 8),
+ t("a", 9, 10),
+ t("Macintosh", 11, 20), t("Mac", 11, 20, 0), t("MacBook", 11, 20, 0));
+ }
+
+ private void MakeIndex1w2w()
+ {
+ // 1111111
+ // 01234567890123456
+ // My pc was broken
+ // personal computer
+ // 0 1 2 3
+ MakeSynonymIndex("My pc was broken",
+ t("My", 0, 2),
+ t("pc", 3, 5), t("personal", 3, 5, 0), t("computer", 3, 5),
+ t("was", 6, 9),
+ t("broken", 10, 16));
+ }
+
+ private void MakeIndex2w1w()
+ {
+ // 1111111111222222222233
+ // 01234567890123456789012345678901
+ // My personal computer was broken
+ // pc
+ // 0 1 2 3 4
+ MakeSynonymIndex("My personal computer was broken",
+ t("My", 0, 2),
+ t("personal", 3, 20), t("pc", 3, 20, 0), t("computer", 3, 20),
+ t("was", 21, 24),
+ t("broken", 25, 31));
+ }
+
+ void MakeSynonymIndex(String value, params Token[] tokens)
+ {
+ Analyzer analyzer = new TokenArrayAnalyzer(tokens);
+ Make1dmfIndex(analyzer, value );
+ }
+
+ public static Token t(String text, int startOffset, int endOffset)
+ {
+ return t(text, startOffset, endOffset, 1);
+ }
+
+ public static Token t(String text, int startOffset, int endOffset, int positionIncrement)
+ {
+ Token token = new Token(text, startOffset, endOffset);
+ token.SetPositionIncrement(positionIncrement);
+ return token;
+ }
+
+ public class TokenArrayAnalyzer : Analyzer
+ {
+ Token[] tokens;
+ public TokenArrayAnalyzer(Token[] tokens)
+ {
+ this.tokens = tokens;
+ }
+
+ public override TokenStream TokenStream(String fieldName, System.IO.TextReader reader)
+ {
+ Token reusableToken = new Token();
+
+ Lucene.Net.Analysis.TokenStream.SetOnlyUseNewAPI(true);
+ TokenStream ts = new AnonymousTokenStream(this, reusableToken);
+
+ ts.AddAttributeImpl(reusableToken);
+ return ts;
+ }
+
+ class AnonymousTokenStream : TokenStream
+ {
+ TokenArrayAnalyzer parent = null;
+ Token reusableToken = null;
+
+ public AnonymousTokenStream(TokenArrayAnalyzer parent,Token reusableToken)
+ {
+ this.parent = parent;
+ this.reusableToken = reusableToken;
+ }
+
+ int p = 0;
+ public override bool IncrementToken()
+ {
+ if (p >= parent.tokens.Length) return false;
+ parent.tokens[p++].CopyTo(reusableToken);
+ return true;
+ }
+ }
+ }
+ }
+}
Added: lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/Properties/AssemblyInfo.cs
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/FastVectorHighlighter.Net/Test/Properties/AssemblyInfo.cs?rev=916340&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/Properties/AssemblyInfo.cs (added)
+++ lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/Properties/AssemblyInfo.cs Thu Feb 25 16:32:11 2010
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Test for FastVectorHighlighter.Net")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("The Apache Software Foundation")]
+[assembly: AssemblyProduct("Test for FastVectorHighlighter.Net")]
+[assembly: AssemblyCopyright("Copyright 2006 - 2010 The Apache Software Foundation")]
+[assembly: AssemblyTrademark("Copyright 2006 - 2010 The Apache Software Foundation")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("f62bffe2-677c-421f-8976-2190ba8a3c57")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("2.9.2")]
+[assembly: AssemblyFileVersion("2.9.2")]
Added: lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/ScoreOrderFragmentsBuilderTest.cs
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/FastVectorHighlighter.Net/Test/ScoreOrderFragmentsBuilderTest.cs?rev=916340&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/ScoreOrderFragmentsBuilderTest.cs (added)
+++ lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/ScoreOrderFragmentsBuilderTest.cs Thu Feb 25 16:32:11 2010
@@ -0,0 +1,55 @@
+/**
+ * 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 System.Collections.Generic;
+using System.Text;
+
+using Lucene.Net.Search;
+using NUnit.Framework;
+
+namespace Lucene.Net.Search.Vectorhighlight
+{
+ [TestFixture]
+ public class ScoreOrderFragmentsBuilderTest : AbstractTestCase
+ {
+
+ [Test]
+ public void Test3Frags()
+ {
+ FieldFragList ffl = this.Ffl("a c", "a b b b b b b b b b b b a b a b b b b b c a a b b");
+ ScoreOrderFragmentsBuilder sofb = new ScoreOrderFragmentsBuilder();
+ String[] f = sofb.CreateFragments(reader, 0, F, ffl, 3);
+ Assert.AreEqual(3, f.Length);
+ // check score order
+ Assert.AreEqual("<b>c</b> <b>a</b> <b>a</b> b b", f[0]);
+ Assert.AreEqual("b b <b>a</b> b <b>a</b> b b b b b ", f[1]);
+ Assert.AreEqual("<b>a</b> b b b b b b b b b ", f[2]);
+ }
+
+ private FieldFragList Ffl(String queryValue, String indexValue)
+ {
+ Make1d1fIndex(indexValue);
+ Query query = paW.Parse(queryValue);
+ FieldQuery fq = new FieldQuery(query, true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ FieldPhraseList fpl = new FieldPhraseList(stack, fq);
+ return new SimpleFragListBuilder().CreateFieldFragList(fpl, 20);
+ }
+ }
+}
Added: lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/SimpleFragListBuilderTest.cs
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/FastVectorHighlighter.Net/Test/SimpleFragListBuilderTest.cs?rev=916340&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/SimpleFragListBuilderTest.cs (added)
+++ lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/SimpleFragListBuilderTest.cs Thu Feb 25 16:32:11 2010
@@ -0,0 +1,211 @@
+/**
+ * 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 System.Collections.Generic;
+using System.Text;
+
+
+using Lucene.Net.Search;
+
+using NUnit.Framework;
+
+namespace Lucene.Net.Search.Vectorhighlight
+{
+ [TestFixture]
+ public class SimpleFragListBuilderTest : AbstractTestCase
+ {
+
+ [Test]
+ public void TestNullFieldFragList()
+ {
+ SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+ FieldFragList ffl = sflb.CreateFieldFragList(fpl("a", "b c d"), 100);
+ Assert.AreEqual(0, ffl.fragInfos.Count);
+ }
+
+ [Test]
+ public void TestTooSmallFragSize()
+ {
+ try
+ {
+ SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+ sflb.CreateFieldFragList(fpl("a", "b c d"), SimpleFragListBuilder.MIN_FRAG_CHAR_SIZE - 1);
+ Assert.Fail("IllegalArgumentException must be thrown");
+ }
+ catch (ArgumentException)
+ {
+ }
+ }
+
+ [Test]
+ public void TestSmallerFragSizeThanTermQuery()
+ {
+ SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+ FieldFragList ffl = sflb.CreateFieldFragList(fpl("abcdefghijklmnopqrs", "abcdefghijklmnopqrs"), SimpleFragListBuilder.MIN_FRAG_CHAR_SIZE);
+ Assert.AreEqual(1, ffl.fragInfos.Count);
+ Assert.AreEqual("subInfos=(abcdefghijklmnopqrs((0,19)))/1.0(0,19)", ffl.fragInfos[0].ToString());
+ }
+
+ [Test]
+ public void TestSmallerFragSizeThanPhraseQuery() {
+ SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+ FieldFragList ffl = sflb.CreateFieldFragList( fpl( "\"abcdefgh jklmnopqrs\"", "abcdefgh jklmnopqrs" ), SimpleFragListBuilder.MIN_FRAG_CHAR_SIZE );
+ Assert.AreEqual( 1, ffl.fragInfos.Count );
+ Console.WriteLine( ffl.fragInfos[ 0 ].ToString() );
+ Assert.AreEqual( "subInfos=(abcdefghjklmnopqrs((0,21)))/1.0(0,21)", ffl.fragInfos[0] .ToString() );
+ }
+
+ [Test]
+ public void Test1TermIndex()
+ {
+ SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+ FieldFragList ffl = sflb.CreateFieldFragList(fpl("a", "a"), 100);
+ Assert.AreEqual(1, ffl.fragInfos.Count);
+ Assert.AreEqual("subInfos=(a((0,1)))/1.0(0,100)", ffl.fragInfos[0].ToString());
+ }
+
+ [Test]
+ public void Test2TermsIndex1Frag()
+ {
+ SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+ FieldFragList ffl = sflb.CreateFieldFragList(fpl("a", "a a"), 100);
+ Assert.AreEqual(1, ffl.fragInfos.Count);
+ Assert.AreEqual("subInfos=(a((0,1))a((2,3)))/2.0(0,100)", ffl.fragInfos[0].ToString());
+
+ ffl = sflb.CreateFieldFragList(fpl("a", "a b b b b b b b b a"), 20);
+ Assert.AreEqual(1, ffl.fragInfos.Count);
+ Assert.AreEqual("subInfos=(a((0,1))a((18,19)))/2.0(0,20)", ffl.fragInfos[0].ToString());
+
+ ffl = sflb.CreateFieldFragList(fpl("a", "b b b b a b b b b a"), 20);
+ Assert.AreEqual(1, ffl.fragInfos.Count);
+ Assert.AreEqual("subInfos=(a((8,9))a((18,19)))/2.0(2,22)", ffl.fragInfos[0].ToString());
+ }
+
+ [Test]
+ public void Test2TermsIndex2Frags()
+ {
+ SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+ FieldFragList ffl = sflb.CreateFieldFragList(fpl("a", "a b b b b b b b b b b b b b a"), 20);
+ Assert.AreEqual(2, ffl.fragInfos.Count);
+ Assert.AreEqual("subInfos=(a((0,1)))/1.0(0,20)", ffl.fragInfos[0].ToString());
+ Assert.AreEqual("subInfos=(a((28,29)))/1.0(22,42)", ffl.fragInfos[1].ToString());
+
+ ffl = sflb.CreateFieldFragList(fpl("a", "a b b b b b b b b b b b b a"), 20);
+ Assert.AreEqual(2, ffl.fragInfos.Count);
+ Assert.AreEqual("subInfos=(a((0,1)))/1.0(0,20)", ffl.fragInfos[0].ToString());
+ Assert.AreEqual("subInfos=(a((26,27)))/1.0(20,40)", ffl.fragInfos[1].ToString());
+
+ ffl = sflb.CreateFieldFragList(fpl("a", "a b b b b b b b b b a"), 20);
+ Assert.AreEqual(2, ffl.fragInfos.Count);
+ Assert.AreEqual("subInfos=(a((0,1)))/1.0(0,20)", ffl.fragInfos[0].ToString());
+ Assert.AreEqual("subInfos=(a((20,21)))/1.0(20,40)", ffl.fragInfos[1].ToString());
+ }
+
+ [Test]
+ public void Test2TermsQuery()
+ {
+ SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+ FieldFragList ffl = sflb.CreateFieldFragList(fpl("a b", "c d e"), 20);
+ Assert.AreEqual(0, ffl.fragInfos.Count);
+
+ ffl = sflb.CreateFieldFragList(fpl("a b", "d b c"), 20);
+ Assert.AreEqual(1, ffl.fragInfos.Count);
+ Assert.AreEqual("subInfos=(b((2,3)))/1.0(0,20)", ffl.fragInfos[0].ToString());
+
+ ffl = sflb.CreateFieldFragList(fpl("a b", "a b c"), 20);
+ Assert.AreEqual(1, ffl.fragInfos.Count);
+ Assert.AreEqual("subInfos=(a((0,1))b((2,3)))/2.0(0,20)", ffl.fragInfos[0].ToString());
+ }
+
+ [Test]
+ public void TestPhraseQuery()
+ {
+ SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+ FieldFragList ffl = sflb.CreateFieldFragList(fpl("\"a b\"", "c d e"), 20);
+ Assert.AreEqual(0, ffl.fragInfos.Count);
+
+ ffl = sflb.CreateFieldFragList(fpl("\"a b\"", "a c b"), 20);
+ Assert.AreEqual(0, ffl.fragInfos.Count);
+
+ ffl = sflb.CreateFieldFragList(fpl("\"a b\"", "a b c"), 20);
+ Assert.AreEqual(1, ffl.fragInfos.Count);
+ Assert.AreEqual("subInfos=(ab((0,3)))/1.0(0,20)", ffl.fragInfos[0].ToString());
+ }
+
+ [Test]
+ public void TestPhraseQuerySlop()
+ {
+ SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+ FieldFragList ffl = sflb.CreateFieldFragList(fpl("\"a b\"~1", "a c b"), 20);
+ Assert.AreEqual(1, ffl.fragInfos.Count);
+ Assert.AreEqual("subInfos=(ab((0,1)(4,5)))/1.0(0,20)", ffl.fragInfos[0].ToString());
+ }
+
+
+ private FieldPhraseList fpl(String queryValue, String indexValue)
+ {
+ Make1d1fIndex(indexValue);
+ Query query = paW.Parse(queryValue);
+ FieldQuery fq = new FieldQuery(query, true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ return new FieldPhraseList(stack, fq);
+ }
+
+ [Test]
+ public void Test1PhraseShortMV()
+ {
+ MakeIndexShortMV();
+
+ FieldQuery fq = new FieldQuery(Tq("d"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ FieldPhraseList fpl = new FieldPhraseList(stack, fq);
+ SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+ FieldFragList ffl = sflb.CreateFieldFragList(fpl, 100);
+ Assert.AreEqual(1, ffl.fragInfos.Count);
+ Assert.AreEqual("subInfos=(d((6,7)))/1.0(0,100)", ffl.fragInfos[0].ToString());
+ }
+
+ [Test]
+ public void Test1PhraseLongMV()
+ {
+ MakeIndexLongMV();
+
+ FieldQuery fq = new FieldQuery(PqF("search", "engines"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ FieldPhraseList fpl = new FieldPhraseList(stack, fq);
+ SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+ FieldFragList ffl = sflb.CreateFieldFragList(fpl, 100);
+ Assert.AreEqual(1, ffl.fragInfos.Count);
+ Assert.AreEqual("subInfos=(searchengines((102,116))searchengines((157,171)))/2.0(96,196)", ffl.fragInfos[0].ToString());
+ }
+
+ [Test]
+ public void Test1PhraseLongMVB()
+ {
+ MakeIndexLongMVB();
+
+ FieldQuery fq = new FieldQuery(PqF("sp", "pe", "ee", "ed"), true, true); // "speed" -(2gram)-> "sp","pe","ee","ed"
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ FieldPhraseList fpl = new FieldPhraseList(stack, fq);
+ SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+ FieldFragList ffl = sflb.CreateFieldFragList(fpl, 100);
+ Assert.AreEqual(1, ffl.fragInfos.Count);
+ Assert.AreEqual("subInfos=(sppeeeed((88,93)))/1.0(82,182)", ffl.fragInfos[0].ToString());
+ }
+ }
+}
Added: lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/SimpleFragmentsBuilderTest.cs
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/FastVectorHighlighter.Net/Test/SimpleFragmentsBuilderTest.cs?rev=916340&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/SimpleFragmentsBuilderTest.cs (added)
+++ lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/SimpleFragmentsBuilderTest.cs Thu Feb 25 16:32:11 2010
@@ -0,0 +1,153 @@
+/**
+ * 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 System.Collections.Generic;
+using System.Text;
+
+using Lucene.Net.Analysis;
+using Lucene.Net.Analysis.Tokenattributes;
+using Lucene.Net.Search;
+using Lucene.Net.Documents;
+using Lucene.Net.QueryParsers;
+using Lucene.Net.Store;
+using Lucene.Net.Index;
+using Lucene.Net.Util;
+
+using NUnit.Framework;
+
+namespace Lucene.Net.Search.Vectorhighlight
+{
+ [TestFixture]
+ public class SimpleFragmentsBuilderTest : AbstractTestCase
+ {
+ [Test]
+ public void Test1TermIndex()
+ {
+ FieldFragList ffl = this.ffl("a", "a");
+ SimpleFragmentsBuilder sfb = new SimpleFragmentsBuilder();
+ Assert.AreEqual("<b>a</b>", sfb.CreateFragment(reader, 0, F, ffl));
+
+ // change tags
+ sfb = new SimpleFragmentsBuilder(new String[] { "[" }, new String[] { "]" });
+ Assert.AreEqual("[a]", sfb.CreateFragment(reader, 0, F, ffl));
+ }
+
+ [Test]
+ public void Test2Frags()
+ {
+ FieldFragList ffl = this.ffl("a", "a b b b b b b b b b b b a b a b");
+ SimpleFragmentsBuilder sfb = new SimpleFragmentsBuilder();
+ String[] f = sfb.CreateFragments(reader, 0, F, ffl, 3);
+ // 3 snippets requested, but should be 2
+ Assert.AreEqual(2, f.Length);
+ Assert.AreEqual("<b>a</b> b b b b b b b b b ", f[0]);
+ Assert.AreEqual("b b <b>a</b> b <b>a</b> b", f[1]);
+ }
+
+ [Test]
+ public void Test3Frags()
+ {
+ FieldFragList ffl = this.ffl("a c", "a b b b b b b b b b b b a b a b b b b b c a a b b");
+ SimpleFragmentsBuilder sfb = new SimpleFragmentsBuilder();
+ String[] f = sfb.CreateFragments(reader, 0, F, ffl, 3);
+ Assert.AreEqual(3, f.Length);
+ Assert.AreEqual("<b>a</b> b b b b b b b b b ", f[0]);
+ Assert.AreEqual("b b <b>a</b> b <b>a</b> b b b b b ", f[1]);
+ Assert.AreEqual("<b>c</b> <b>a</b> <b>a</b> b b", f[2]);
+ }
+
+
+ private FieldFragList ffl(String queryValue, String indexValue)
+ {
+ Make1d1fIndex(indexValue);
+ Query query = paW.Parse(queryValue);
+ FieldQuery fq = new FieldQuery(query, true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ FieldPhraseList fpl = new FieldPhraseList(stack, fq);
+ return new SimpleFragListBuilder().CreateFieldFragList(fpl, 20);
+ }
+
+ [Test]
+ public void Test1PhraseShortMV()
+ {
+ MakeIndexShortMV();
+
+ FieldQuery fq = new FieldQuery(Tq("d"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ FieldPhraseList fpl = new FieldPhraseList(stack, fq);
+ SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+ FieldFragList ffl = sflb.CreateFieldFragList(fpl, 100);
+ SimpleFragmentsBuilder sfb = new SimpleFragmentsBuilder();
+ Assert.AreEqual("a b c <b>d</b> e", sfb.CreateFragment(reader, 0, F, ffl));
+ }
+
+ [Test]
+ public void Test1PhraseLongMV()
+ {
+ MakeIndexLongMV();
+
+ FieldQuery fq = new FieldQuery(PqF("search", "engines"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ FieldPhraseList fpl = new FieldPhraseList(stack, fq);
+ SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+ FieldFragList ffl = sflb.CreateFieldFragList(fpl, 100);
+ SimpleFragmentsBuilder sfb = new SimpleFragmentsBuilder();
+ Assert.AreEqual(" most <b>search engines</b> use only one of these methods. Even the <b>search engines</b> that says they can use t",
+ sfb.CreateFragment(reader, 0, F, ffl));
+ }
+
+ [Test]
+ public void Test1PhraseLongMVB()
+ {
+ MakeIndexLongMVB();
+
+ FieldQuery fq = new FieldQuery(PqF("sp", "pe", "ee", "ed"), true, true); // "speed" -(2gram)-> "sp","pe","ee","ed"
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ FieldPhraseList fpl = new FieldPhraseList(stack, fq);
+ SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+ FieldFragList ffl = sflb.CreateFieldFragList(fpl, 100);
+ SimpleFragmentsBuilder sfb = new SimpleFragmentsBuilder();
+ Assert.AreEqual("ssing <b>speed</b>, the", sfb.CreateFragment(reader, 0, F, ffl));
+ }
+
+ [Test]
+ public void TestUnstoredField()
+ {
+ MakeUnstoredIndex();
+
+ FieldQuery fq = new FieldQuery(Tq("aaa"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ FieldPhraseList fpl = new FieldPhraseList(stack, fq);
+ SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+ FieldFragList ffl = sflb.CreateFieldFragList(fpl, 100);
+ SimpleFragmentsBuilder sfb = new SimpleFragmentsBuilder();
+ Assert.IsNull(sfb.CreateFragment(reader, 0, F, ffl));
+ }
+
+ protected void MakeUnstoredIndex()
+ {
+ IndexWriter writer = new IndexWriter(dir, analyzerW, true, IndexWriter.MaxFieldLength.LIMITED);
+ Document doc = new Document();
+ doc.Add(new Field(F, "aaa", Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
+ writer.AddDocument(doc);
+ writer.Close();
+
+ reader = IndexReader.Open(dir);
+ }
+ }
+}
Added: lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/Support.cs
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/FastVectorHighlighter.Net/Test/Support.cs?rev=916340&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/Support.cs (added)
+++ lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/Support.cs Thu Feb 25 16:32:11 2010
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Lucene.Net.Search.Vectorhighlight
+{
+ static class Extensions
+ {
+ public static V Get<K, V>(this Dictionary<K, V> list, K key)
+ {
+ if (key == null) return default(V);
+ V v = default(V);
+ list.TryGetValue(key, out v);
+ return v;
+ }
+ }
+
+ public class HashSet<T> : Dictionary<T, T>
+ {
+ public void Add(T key)
+ {
+ base.Add(key, key);
+ }
+ }
+}
+
+namespace System.Runtime.CompilerServices
+{
+ [AttributeUsage(AttributeTargets.Method)]
+ public sealed class ExtensionAttribute : Attribute
+ {
+ public ExtensionAttribute() { }
+ }
+}
Added: lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/Test.csproj
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/FastVectorHighlighter.Net/Test/Test.csproj?rev=916340&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/Test.csproj (added)
+++ lucene/lucene.net/trunk/C#/contrib/FastVectorHighlighter.Net/Test/Test.csproj Thu Feb 25 16:32:11 2010
@@ -0,0 +1,75 @@
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.21022</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{33ED01FD-A87C-4208-BA49-2586EFE32974}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Lucene.Net.Search.Vectorhighlight</RootNamespace>
+ <AssemblyName>Test</AssemblyName>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <OldToolsVersion>2.0</OldToolsVersion>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <UpgradeBackupLocation>
+ </UpgradeBackupLocation>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Lucene.Net, Version=2.9.2.1, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\FastVectorHighlighter\bin\Release\Lucene.Net.dll</HintPath>
+ </Reference>
+ <Reference Include="nunit.framework, Version=2.5.2.9222, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\src\Test\bin\Release\nunit.framework.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="AbstractTestCase.cs" />
+ <Compile Include="FieldPhraseListTest.cs" />
+ <Compile Include="FieldQueryTest.cs" />
+ <Compile Include="FieldTermStackTest.cs" />
+ <Compile Include="IndexTimeSynonymTest.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="ScoreOrderFragmentsBuilderTest.cs" />
+ <Compile Include="SimpleFragListBuilderTest.cs" />
+ <Compile Include="SimpleFragmentsBuilderTest.cs" />
+ <Compile Include="Support.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\FastVectorHighlighter.Net\FastVectorHighlighter.Net.csproj">
+ <Project>{9D2E3153-076F-49C5-B83D-FB2573536B5F}</Project>
+ <Name>FastVectorHighlighter.Net</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
\ No newline at end of file