Return-Path: X-Original-To: apmail-lucenenet-commits-archive@www.apache.org Delivered-To: apmail-lucenenet-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EC845D9EE for ; Tue, 28 Aug 2012 18:48:54 +0000 (UTC) Received: (qmail 25573 invoked by uid 500); 28 Aug 2012 18:48:54 -0000 Delivered-To: apmail-lucenenet-commits-archive@lucenenet.apache.org Received: (qmail 25516 invoked by uid 500); 28 Aug 2012 18:48:54 -0000 Mailing-List: contact commits-help@lucenenet.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@lucenenet.apache.org Delivered-To: mailing list commits@lucenenet.apache.org Received: (qmail 25502 invoked by uid 500); 28 Aug 2012 18:48:54 -0000 Delivered-To: apmail-lucene-lucene-net-commits@lucene.apache.org Received: (qmail 25498 invoked by uid 99); 28 Aug 2012 18:48:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Aug 2012 18:48:54 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Aug 2012 18:48:48 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 4155623888EA; Tue, 28 Aug 2012 18:48:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1378266 - in /incubator/lucene.net/trunk: src/contrib/FastVectorHighlighter/ test/contrib/FastVectorHighlighter/ Date: Tue, 28 Aug 2012 18:48:03 -0000 To: lucene-net-commits@lucene.apache.org From: sisve@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120828184804.4155623888EA@eris.apache.org> 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 @@ Properties Lucene.Net.Search.Vectorhighlight Lucene.Net.FastVectorHighlighter - 3.5 - false publish\ true @@ -58,7 +56,6 @@ TRACE;DEBUG;LUCENENET_350;$(Framework) prompt 4 - 618 Library @@ -72,7 +69,6 @@ TRACE;DEBUG;LUCENENET_350;$(Framework) prompt 4 - 618 Library @@ -127,6 +123,7 @@ + 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 flatQueries) + public void flatten(Query sourceQuery, Dictionary 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 terms = new HashSet(); + 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 expand(Dictionary flatQueries) + public Dictionary expand(Dictionary flatQueries) { Dictionary expandQueries = new Dictionary(); - foreach(Query query in new Dictionary(flatQueries).Keys) + foreach (Query query in new Dictionary(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 expandQueries, PhraseQuery a, PhraseQuery b) + private void CheckOverlap(Dictionary 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 expandQueries, Term[] src, Term[] dest, int slop, float boost) + private void CheckOverlap(Dictionary 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> */ - void SaveTerms(Dictionary flatQueries) + void SaveTerms(Dictionary flatQueries) { foreach (Query query in flatQueries.Keys) { List 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(); - termSetMap.Put(key,set); + termSetMap.Put(key, set); } return set; } @@ -289,10 +317,20 @@ namespace Lucene.Net.Search.Vectorhighli * * QueryPhraseMap */ - 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 + { + /// + /// Check if the termToMatch is a match for the term, considering the use of a wildcards. + /// + 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 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 @@ Properties Lucene.Net.Search.Vectorhighlight Lucene.Net.FastVectorHighlighter.Test - 3.5 - publish\ true Disk @@ -58,7 +56,6 @@ DEBUG;TRACE;$(Framework) prompt 4 - 618 Library @@ -72,7 +69,6 @@ DEBUG;TRACE;$(Framework) prompt 4 - 618 Library @@ -85,7 +81,6 @@ TRACE;$(Framework) prompt 4 - 618 true Library @@ -99,7 +94,6 @@ TRACE;$(Framework) prompt 4 - 618 true Library @@ -121,6 +115,7 @@ + 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 flatQueries = new HashSet(); 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 flatQueries = new HashSet(); 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(); + 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(); + fieldQuery.flatten(query, flatQueries); + AssertCollectionQueries(flatQueries, Tq("a"), Tq("b"), Tq("c")); + } + + /// + /// Being able to search for prefix query. + /// + [Test] + public void TestFlattenPrefixQuery() + { + Query query = paW.Parse("Ter*"); + FieldQuery fq = new FieldQuery(query, true, true); + HashSet flatQueries = new HashSet(); + 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 flatQueries = new HashSet(); + 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