You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by si...@apache.org on 2012/08/28 20:48:03 UTC
svn commit: r1378266 - in /incubator/lucene.net/trunk:
src/contrib/FastVectorHighlighter/ test/contrib/FastVectorHighlighter/
Author: sisve
Date: Tue Aug 28 18:48:03 2012
New Revision: 1378266
URL: http://svn.apache.org/viewvc?rev=1378266&view=rev
Log:
LUCENENET-504 Support for PrefixQuery in FastVectorHighlighter
LUCENE-3332 Support for MultiPhraseQuery (and others) in FastVectorHighlighter
Added:
incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/StringUtils.cs (with props)
incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/StringUtilsTest.cs (with props)
Modified:
incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.csproj
incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/FieldQuery.cs
incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/FieldTermStack.cs
incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/VectorHighlightMapper.cs
incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/AbstractTestCase.cs
incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.Test.csproj
incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/FieldQueryTest.cs
incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/FieldTermStackTest.cs
Modified: incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.csproj?rev=1378266&r1=1378265&r2=1378266&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.csproj (original)
+++ incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.csproj Tue Aug 28 18:48:03 2012
@@ -29,9 +29,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Lucene.Net.Search.Vectorhighlight</RootNamespace>
<AssemblyName>Lucene.Net.FastVectorHighlighter</AssemblyName>
- <FileUpgradeFlags></FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
- <UpgradeBackupLocation></UpgradeBackupLocation>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
@@ -58,7 +56,6 @@
<DefineConstants>TRACE;DEBUG;LUCENENET_350;$(Framework)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
- <DocumentationFile></DocumentationFile>
<NoWarn>618</NoWarn>
<OutputType>Library</OutputType>
</PropertyGroup>
@@ -72,7 +69,6 @@
<DefineConstants>TRACE;DEBUG;LUCENENET_350;$(Framework)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
- <DocumentationFile></DocumentationFile>
<NoWarn>618</NoWarn>
<OutputType>Library</OutputType>
</PropertyGroup>
@@ -127,6 +123,7 @@
<Compile Include="ScoreOrderFragmentsBuilder.cs" />
<Compile Include="SimpleFragListBuilder.cs" />
<Compile Include="SimpleFragmentsBuilder.cs" />
+ <Compile Include="StringUtils.cs" />
<Compile Include="Support.cs" />
<Compile Include="VectorHighlightMapper.cs" />
</ItemGroup>
Modified: incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/FieldQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/FieldQuery.cs?rev=1378266&r1=1378265&r2=1378266&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/FieldQuery.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/FieldQuery.cs Tue Aug 28 18:48:03 2012
@@ -58,13 +58,13 @@ namespace Lucene.Net.Search.Vectorhighli
if (pq.GetTerms().Length > 1)
{
foreach (Term term in pq.GetTerms())
- rootMap.AddTerm(term, flatQuery.Boost);
+ rootMap.AddTerm(term.Text, flatQuery.Boost);
}
}
}
}
- public void flatten(Query sourceQuery, Dictionary<Query,Query> flatQueries)
+ public void flatten(Query sourceQuery, Dictionary<Query, Query> flatQueries)
{
if (sourceQuery is BooleanQuery)
{
@@ -75,10 +75,15 @@ namespace Lucene.Net.Search.Vectorhighli
flatten(clause.Query, flatQueries);
}
}
+ else if (sourceQuery is PrefixQuery)
+ {
+ if (!flatQueries.ContainsKey(sourceQuery))
+ flatQueries.Add(sourceQuery, sourceQuery);
+ }
else if (sourceQuery is DisjunctionMaxQuery)
{
DisjunctionMaxQuery dmq = (DisjunctionMaxQuery)sourceQuery;
- foreach(Query query in dmq)
+ foreach (Query query in dmq)
{
flatten(query, flatQueries);
}
@@ -102,7 +107,24 @@ namespace Lucene.Net.Search.Vectorhighli
}
}
}
- // else discard queries
+ else
+ {
+ // Fallback to using extracted terms
+ ISet<Term> terms = new HashSet<Term>();
+ try
+ {
+ sourceQuery.ExtractTerms(terms);
+ }
+ catch (NotSupportedException)
+ { // thrown by default impl
+ return; // ignore error and discard query
+ }
+
+ foreach (var term in terms)
+ {
+ flatten(new TermQuery(term), flatQueries);
+ }
+ }
}
/*
@@ -115,16 +137,16 @@ namespace Lucene.Net.Search.Vectorhighli
* ex2) flatQueries={a,"b c","c d"}
* => expandQueries={a,"b c","c d","b c d"}
*/
- public Dictionary<Query, Query> expand(Dictionary<Query,Query> flatQueries)
+ public Dictionary<Query, Query> expand(Dictionary<Query, Query> flatQueries)
{
Dictionary<Query, Query> expandQueries = new Dictionary<Query, Query>();
- foreach(Query query in new Dictionary<Query,Query>(flatQueries).Keys)
+ foreach (Query query in new Dictionary<Query, Query>(flatQueries).Keys)
{
//Query query = i.next();
flatQueries.Remove(query);
- expandQueries.Add(query,query);
+ expandQueries.Add(query, query);
if (!(query is PhraseQuery)) continue;
- foreach(Query qj in flatQueries.Keys)
+ foreach (Query qj in flatQueries.Keys)
{
if (!(qj is PhraseQuery)) continue;
CheckOverlap(expandQueries, (PhraseQuery)query, (PhraseQuery)qj);
@@ -140,7 +162,7 @@ namespace Lucene.Net.Search.Vectorhighli
* ex2) A="b c", B="a b" => overlap; expandQueries={"a b c"}
* ex3) A="a b", B="c d" => no overlap; expandQueries={}
*/
- private void CheckOverlap(Dictionary<Query,Query> expandQueries, PhraseQuery a, PhraseQuery b)
+ private void CheckOverlap(Dictionary<Query, Query> expandQueries, PhraseQuery a, PhraseQuery b)
{
if (a.Slop != b.Slop) return;
Term[] ats = a.GetTerms();
@@ -163,7 +185,7 @@ namespace Lucene.Net.Search.Vectorhighli
* expandQueries={"a a a a a","a a a a a a"}
* ex8) src="a b c d", dest="b c" => no overlap
*/
- private void CheckOverlap(Dictionary<Query,Query> expandQueries, Term[] src, Term[] dest, int slop, float boost)
+ private void CheckOverlap(Dictionary<Query, Query> expandQueries, Term[] src, Term[] dest, int slop, float boost)
{
// beginning from 1 (not 0) is safe because that the PhraseQuery has multiple terms
// is guaranteed in flatten() method (if PhraseQuery has only one term, flatten()
@@ -191,7 +213,7 @@ namespace Lucene.Net.Search.Vectorhighli
pq.Slop = slop;
pq.Boost = boost;
if (!expandQueries.ContainsKey(pq))
- expandQueries.Add(pq,pq);
+ expandQueries.Add(pq, pq);
}
}
}
@@ -199,11 +221,11 @@ namespace Lucene.Net.Search.Vectorhighli
public QueryPhraseMap getRootMap(Query query)
{
String key = GetKey(query);
- QueryPhraseMap map=rootMaps.Get(key);
+ QueryPhraseMap map = rootMaps.Get(key);
if (map == null)
{
map = new QueryPhraseMap(this);
- rootMaps.Put(key,map);
+ rootMaps.Put(key, map);
}
return map;
}
@@ -217,14 +239,18 @@ namespace Lucene.Net.Search.Vectorhighli
if (!fieldMatch) return null;
if (query is TermQuery)
return ((TermQuery)query).Term.Field;
- else if (query is PhraseQuery)
+
+ if (query is PrefixQuery)
+ return ((PrefixQuery)query).Prefix.Field;
+
+ if (query is PhraseQuery)
{
PhraseQuery pq = (PhraseQuery)query;
Term[] terms = pq.GetTerms();
return terms[0].Field;
}
- else
- throw new System.ApplicationException("query \"" + query.ToString() + "\" must be flatten first.");
+
+ throw new ApplicationException("query \"" + query + "\" must be flatten first.");
}
/*
@@ -249,13 +275,15 @@ namespace Lucene.Net.Search.Vectorhighli
* - fieldMatch==false
* termSetMap=Map<null,Set<"john","lennon">>
*/
- void SaveTerms(Dictionary<Query,Query> flatQueries)
+ void SaveTerms(Dictionary<Query, Query> flatQueries)
{
foreach (Query query in flatQueries.Keys)
{
List<String> termSet = GetTermSet(query);
if (query is TermQuery)
termSet.Add(((TermQuery)query).Term.Text);
+ else if (query is PrefixQuery)
+ termSet.Add(((PrefixQuery)query).Prefix.Text + "*");
else if (query is PhraseQuery)
{
foreach (Term term in ((PhraseQuery)query).GetTerms())
@@ -273,7 +301,7 @@ namespace Lucene.Net.Search.Vectorhighli
if (set == null)
{
set = new List<String>();
- termSetMap.Put(key,set);
+ termSetMap.Put(key, set);
}
return set;
}
@@ -289,10 +317,20 @@ namespace Lucene.Net.Search.Vectorhighli
* <param name="term"></param>
* <returns>QueryPhraseMap</returns>
*/
- public QueryPhraseMap GetFieldTermMap(String fieldName, String term)
+ public QueryPhraseMap GetFieldTermMap(String fieldName, String term)
{
QueryPhraseMap rootMap = GetRootMap(fieldName);
- return rootMap == null ? null : rootMap.subMap.Get(term);
+ return rootMap == null ? null : RetrieveQueryFromSubMap(rootMap, term);
+ }
+
+ public QueryPhraseMap RetrieveQueryFromSubMap(QueryPhraseMap rootMap, String term)
+ {
+ foreach (var kvp in rootMap.subMap)
+ {
+ if (StringUtils.TermStringMatch(kvp.Key, term))
+ return kvp.Value;
+ }
+ return null;
}
/**
@@ -333,9 +371,9 @@ namespace Lucene.Net.Search.Vectorhighli
this.fieldQuery = fieldQuery;
}
- public void AddTerm(Term term, float boost)
+ public void AddTerm(String termText, float boost)
{
- QueryPhraseMap map = GetOrNewMap(subMap, term.Text);
+ QueryPhraseMap map = GetOrNewMap(subMap, termText);
map.MarkTerminal(boost);
}
@@ -345,7 +383,7 @@ namespace Lucene.Net.Search.Vectorhighli
if (map == null)
{
map = new QueryPhraseMap(fieldQuery);
- subMap.Put(term,map);
+ subMap.Put(term, map);
}
return map;
}
@@ -354,7 +392,11 @@ namespace Lucene.Net.Search.Vectorhighli
{
if (query is TermQuery)
{
- AddTerm(((TermQuery)query).Term, query.Boost);
+ AddTerm(((TermQuery)query).Term.Text, query.Boost);
+ }
+ else if (query is PrefixQuery)
+ {
+ AddTerm(((PrefixQuery)query).Prefix.Text + "*", query.Boost);
}
else if (query is PhraseQuery)
{
Modified: incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/FieldTermStack.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/FieldTermStack.cs?rev=1378266&r1=1378265&r2=1378266&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/FieldTermStack.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/FieldTermStack.cs Tue Aug 28 18:48:03 2012
@@ -79,13 +79,13 @@ namespace Lucene.Net.Search.Vectorhighli
//TermFreqVector tfv = reader.GetTermFreqVector(docId, fieldName);
VectorHighlightMapper tfv = new VectorHighlightMapper(termSet);
reader.GetTermFreqVector(docId, fieldName, tfv);
-
+
if (tfv.Size==0) return; // just return to make null snippets
string[] terms = tfv.GetTerms();
foreach (String term in terms)
{
- if (!termSet.Contains(term)) continue;
+ if (!StringUtils.AnyTermMatch(termSet, term)) continue;
int index = tfv.IndexOf(term);
TermVectorOffsetInfo[] tvois = tfv.GetOffsets(index);
if (tvois == null) return; // just return to make null snippets
Added: incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/StringUtils.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/StringUtils.cs?rev=1378266&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/StringUtils.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/StringUtils.cs Tue Aug 28 18:48:03 2012
@@ -0,0 +1,56 @@
+/*
+ * 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;
+
+namespace Lucene.Net.Search.Vectorhighlight
+{
+ public static class StringUtils
+ {
+ /// <summary>
+ /// Check if the termToMatch is a match for the term, considering the use of a wildcards.
+ /// </summary>
+ public static Boolean TermStringMatch(String term, String termToMatch)
+ {
+ if (term[0] == '*' || term[0] == '?')
+ throw new NotSupportedException("Unable to do matching with wildcard at the beginning");
+
+ if (term[term.Length - 1] == '*')
+ {
+ //Wildcard at the end
+ if (termToMatch.Length < term.Length - 1) return false;
+ for (int i = 0; i < term.Length - 1; i++)
+ {
+ if (termToMatch[i] != term[i]) return false;
+ }
+ return true;
+ }
+ return term.Equals(termToMatch);
+ }
+
+ public static Boolean AnyTermMatch(IList<String> terms, String term)
+ {
+ for (int i = 0; i < terms.Count; i++)
+ {
+ if (StringUtils.TermStringMatch(terms[i], term))
+ return true;
+ }
+ return false;
+ }
+ }
+}
Propchange: incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/StringUtils.cs
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/VectorHighlightMapper.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/VectorHighlightMapper.cs?rev=1378266&r1=1378265&r2=1378266&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/VectorHighlightMapper.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/FastVectorHighlighter/VectorHighlightMapper.cs Tue Aug 28 18:48:03 2012
@@ -58,7 +58,7 @@ namespace Lucene.Net.Search.Vectorhighli
public override void Map(string term, int frequency, TermVectorOffsetInfo[] offsets, int[] positions)
{
- if (_terms.Contains(term))
+ if (StringUtils.AnyTermMatch(_terms, term))
{
_indexMap.Add(term);
if (_storeOffsets)
Modified: incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/AbstractTestCase.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/AbstractTestCase.cs?rev=1378266&r1=1378265&r2=1378266&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/AbstractTestCase.cs (original)
+++ incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/AbstractTestCase.cs Tue Aug 28 18:48:03 2012
@@ -114,6 +114,28 @@ namespace Lucene.Net.Search.Vectorhighli
return query;
}
+ protected Query Preq(String text)
+ {
+ return Preq(1F, text);
+ }
+
+ protected Query Preq(float boost, String text)
+ {
+ return Preq(boost, F, text);
+ }
+
+ protected Query Preq(String field, String text)
+ {
+ return Preq(1F, field, text);
+ }
+
+ protected Query Preq(float boost, String field, String text)
+ {
+ Query query = new PrefixQuery(new Term(field, text));
+ query.Boost = boost;
+ return query;
+ }
+
protected Query PqF(params String[] texts)
{
return PqF(1F, texts);
Modified: incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.Test.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.Test.csproj?rev=1378266&r1=1378265&r2=1378266&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.Test.csproj (original)
+++ incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.Test.csproj Tue Aug 28 18:48:03 2012
@@ -29,9 +29,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Lucene.Net.Search.Vectorhighlight</RootNamespace>
<AssemblyName>Lucene.Net.FastVectorHighlighter.Test</AssemblyName>
- <FileUpgradeFlags></FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
- <UpgradeBackupLocation></UpgradeBackupLocation>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
@@ -58,7 +56,6 @@
<DefineConstants>DEBUG;TRACE;$(Framework)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
- <DocumentationFile></DocumentationFile>
<NoWarn>618</NoWarn>
<OutputType>Library</OutputType>
</PropertyGroup>
@@ -72,7 +69,6 @@
<DefineConstants>DEBUG;TRACE;$(Framework)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
- <DocumentationFile></DocumentationFile>
<NoWarn>618</NoWarn>
<OutputType>Library</OutputType>
</PropertyGroup>
@@ -85,7 +81,6 @@
<DefineConstants>TRACE;$(Framework)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
- <DocumentationFile></DocumentationFile>
<NoWarn>618</NoWarn>
<DebugSymbols>true</DebugSymbols>
<OutputType>Library</OutputType>
@@ -99,7 +94,6 @@
<DefineConstants>TRACE;$(Framework)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
- <DocumentationFile></DocumentationFile>
<NoWarn>618</NoWarn>
<DebugSymbols>true</DebugSymbols>
<OutputType>Library</OutputType>
@@ -121,6 +115,7 @@
<Compile Include="ScoreOrderFragmentsBuilderTest.cs" />
<Compile Include="SimpleFragListBuilderTest.cs" />
<Compile Include="SimpleFragmentsBuilderTest.cs" />
+ <Compile Include="StringUtilsTest.cs" />
<Compile Include="Support.cs" />
</ItemGroup>
<ItemGroup>
Modified: incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/FieldQueryTest.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/FieldQueryTest.cs?rev=1378266&r1=1378265&r2=1378266&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/FieldQueryTest.cs (original)
+++ incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/FieldQueryTest.cs Tue Aug 28 18:48:03 2012
@@ -18,8 +18,9 @@
using System;
using System.Collections.Generic;
using System.Text;
-
+using Lucene.Net.Index;
using Lucene.Net.Search;
+using Lucene.Net.Search.Spans;
using Occur = Lucene.Net.Search.Occur;
using QueryPhraseMap = Lucene.Net.Search.Vectorhighlight.FieldQuery.QueryPhraseMap;
@@ -69,7 +70,7 @@ namespace Lucene.Net.Search.Vectorhighli
FieldQuery fq = new FieldQuery(query, true, true);
HashSet<Query> flatQueries = new HashSet<Query>();
fq.flatten(query, flatQueries);
- AssertCollectionQueries(flatQueries, Tq("AA"), PqF("BC", "CD" ), PqF("EF", "FG", "GH"));
+ AssertCollectionQueries(flatQueries, Tq("AA"), PqF("BC", "CD"), PqF("EF", "FG", "GH"));
}
[Test]
@@ -91,7 +92,7 @@ namespace Lucene.Net.Search.Vectorhighli
// "a b","b c" => "a b","b c","a b c"
HashSet<Query> flatQueries = new HashSet<Query>();
flatQueries.Add(PqF("a", "b"));
- flatQueries.Add(PqF( "b", "c" ));
+ flatQueries.Add(PqF("b", "c"));
AssertCollectionQueries(fq.expand(flatQueries),
PqF("a", "b"), PqF("b", "c"), PqF("a", "b", "c"));
@@ -358,7 +359,7 @@ namespace Lucene.Net.Search.Vectorhighli
// phraseHighlight = true, fieldMatch = false
fq = new FieldQuery(query, true, false);
map = fq.rootMaps;
- Assert.AreEqual(1, map.Count);
+ Assert.AreEqual(1, map.Count);
Assert.Null(map.Get(F));
Assert.NotNull(map.Get(null));
qpm = map.Get(null);
@@ -884,6 +885,59 @@ namespace Lucene.Net.Search.Vectorhighli
phraseCandidate.Add(new TermInfo("c", 4, 5, 6));
Assert.Null(fq.SearchPhrase(F, phraseCandidate));
}
+
+ [Test]
+ public void TestFlattenMultiPhraseQuery()
+ {
+ var query = new MultiPhraseQuery();
+ query.Add(new[] { new Term(F, "a1"), new Term(F, "a2") });
+ query.Add(new[] { new Term(F, "b1"), new Term(F, "b2") });
+
+ var fieldQuery = new FieldQuery(query, true, true);
+ var flatQueries = new HashSet<Query>();
+ fieldQuery.flatten(query, flatQueries);
+ AssertCollectionQueries(flatQueries, Tq("a1"), Tq("a2"), Tq("b1"), Tq("b2"));
+ }
+
+ [Test]
+ public void TestFlattenSpanQuery()
+ {
+ var clauses = new SpanQuery[]
+ {
+ new SpanTermQuery(new Term(F, "a")),
+ new SpanTermQuery(new Term(F, "b")),
+ new SpanTermQuery(new Term(F, "c")),
+ };
+
+ var query = new SpanNearQuery(clauses, 3, true);
+ var fieldQuery = new FieldQuery(query, true, true);
+ var flatQueries = new HashSet<Query>();
+ fieldQuery.flatten(query, flatQueries);
+ AssertCollectionQueries(flatQueries, Tq("a"), Tq("b"), Tq("c"));
+ }
+
+ /// <summary>
+ /// Being able to search for prefix query.
+ /// </summary>
+ [Test]
+ public void TestFlattenPrefixQuery()
+ {
+ Query query = paW.Parse("Ter*");
+ FieldQuery fq = new FieldQuery(query, true, true);
+ HashSet<Query> flatQueries = new HashSet<Query>();
+ fq.flatten(query, flatQueries);
+ AssertCollectionQueries(flatQueries, Preq("ter"));
+ }
+
+ [Test]
+ public void TestFlattenPrefixQueryWithAnd()
+ {
+ Query query = paW.Parse("Ter* AND Pre*");
+ FieldQuery fq = new FieldQuery(query, true, true);
+ HashSet<Query> flatQueries = new HashSet<Query>();
+ fq.flatten(query, flatQueries);
+ AssertCollectionQueries(flatQueries, Preq("ter"), Preq("pre"));
+ }
}
}
Modified: incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/FieldTermStackTest.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/FieldTermStackTest.cs?rev=1378266&r1=1378265&r2=1378266&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/FieldTermStackTest.cs (original)
+++ incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/FieldTermStackTest.cs Tue Aug 28 18:48:03 2012
@@ -187,5 +187,42 @@ namespace Lucene.Net.Search.Vectorhighli
Assert.AreEqual("ee(90,92,63)", stack.Pop().ToString());
Assert.AreEqual("ed(91,93,64)", stack.Pop().ToString());
}
+
+ [Test]
+ public void TestFieldTermStackWithNoNeededAsterisk()
+ {
+ MakeIndexLongMV();
+
+ FieldQuery fq = new FieldQuery(Preq("engines"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ Assert.AreEqual(2, stack.termList.Count);
+ Assert.AreEqual("engines(109,116,15)", stack.Pop().ToString());
+ Assert.AreEqual("engines(164,171,25)", stack.Pop().ToString());
+ }
+
+ [Test]
+ public void TestFieldTermStack()
+ {
+ MakeIndexLongMV();
+
+ FieldQuery fq = new FieldQuery(Preq("engin"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ Assert.AreEqual(2, stack.termList.Count);
+ Assert.AreEqual("engines(109,116,15)", stack.Pop().ToString());
+ Assert.AreEqual("engines(164,171,25)", stack.Pop().ToString());
+ }
+
+ [Test]
+ public void TestCompleteSearchInLongMV()
+ {
+ MakeIndexLongMV();
+
+ FieldQuery fq = new FieldQuery(Preq("engin"), true, true);
+ FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
+ FieldPhraseList fpl = new FieldPhraseList(stack, fq);
+ Assert.AreEqual(2, fpl.phraseList.Count);
+ Assert.AreEqual("engines(1.0)((109,116))", fpl.phraseList.First.Value.ToString());
+ Assert.AreEqual("engines(1.0)((164,171))", fpl.phraseList.First.Next.Value.ToString());
+ }
}
}
Added: incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/StringUtilsTest.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/StringUtilsTest.cs?rev=1378266&view=auto
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/StringUtilsTest.cs (added)
+++ incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/StringUtilsTest.cs Tue Aug 28 18:48:03 2012
@@ -0,0 +1,43 @@
+/*
+ * 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 NUnit.Framework;
+
+namespace Lucene.Net.Search.Vectorhighlight
+{
+ [TestFixture]
+ public class StringUtilsTest
+ {
+ [Test]
+ public void TestTermEqualityWithEqualsTerms()
+ {
+ Assert.That(StringUtils.TermStringMatch("test", "test"));
+ }
+
+ [Test]
+ public void TestTermEqualityWithNotEqualsTerms()
+ {
+ Assert.IsFalse(StringUtils.TermStringMatch("testa", "testb"));
+ }
+
+ [Test]
+ public void TestTermEqualityWithPrefixTerm()
+ {
+ Assert.That(StringUtils.TermStringMatch("test*", "testing"));
+ }
+ }
+}
Propchange: incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/StringUtilsTest.cs
------------------------------------------------------------------------------
svn:eol-style = native