lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From si...@apache.org
Subject svn commit: r1381031 - in /incubator/lucene.net/branches/3.0.3: src/contrib/FastVectorHighlighter/ test/contrib/FastVectorHighlighter/
Date Wed, 05 Sep 2012 07:00:49 GMT
Author: sisve
Date: Wed Sep  5 07:00:49 2012
New Revision: 1381031

URL: http://svn.apache.org/viewvc?rev=1381031&view=rev
Log:
LUCENENET-504 and LUCENENET-506

Added:
    incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/StringUtils.cs 
 (with props)
    incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/StringUtilsTest.cs
  (with props)
Modified:
    incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.csproj
    incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/FieldQuery.cs
    incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/FieldTermStack.cs
    incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/VectorHighlightMapper.cs
    incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/AbstractTestCase.cs
    incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.Test.csproj
    incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/FieldQueryTest.cs
    incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/FieldTermStackTest.cs

Modified: incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.csproj?rev=1381031&r1=1381030&r2=1381031&view=diff
==============================================================================
--- incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.csproj
(original)
+++ incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.csproj
Wed Sep  5 07:00:49 2012
@@ -28,12 +28,8 @@
     <ProjectGuid>{9D2E3153-076F-49C5-B83D-FB2573536B5F}</ProjectGuid>
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Lucene.Net.Search.Vectorhighlight</RootNamespace>
-    <AssemblyName>Lucene.Net.Contrib.FastVectorHighlighter</AssemblyName>
-    <FileUpgradeFlags>
-    </FileUpgradeFlags>
+    <AssemblyName>Lucene.Net.FastVectorHighlighter</AssemblyName>
     <OldToolsVersion>3.5</OldToolsVersion>
-    <UpgradeBackupLocation>
-    </UpgradeBackupLocation>
     <IsWebBootstrapper>false</IsWebBootstrapper>
     <PublishUrl>publish\</PublishUrl>
     <Install>true</Install>
@@ -60,8 +56,6 @@
     <DefineConstants>TRACE;DEBUG;LUCENENET_350;$(Framework)</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
-    <DocumentationFile>
-    </DocumentationFile>
     <NoWarn>618</NoWarn>
     <OutputType>Library</OutputType>
   </PropertyGroup>
@@ -75,8 +69,6 @@
     <DefineConstants>TRACE;DEBUG;LUCENENET_350;$(Framework)</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
-    <DocumentationFile>
-    </DocumentationFile>
     <NoWarn>618</NoWarn>
     <OutputType>Library</OutputType>
   </PropertyGroup>
@@ -89,7 +81,7 @@
     <DefineConstants>TRACE;LUCENENET_350;$(Framework)</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
-    <DocumentationFile>..\..\..\build\bin\contrib\FastVectorHighlighter\Release\NET40\Lucene.Net.Contrib.FastVectorHighlighter.xml</DocumentationFile>
+    <DocumentationFile>..\..\..\build\bin\contrib\FastVectorHighlighter\$(Configuration.Replace("35",
""))\$(Framework)\Lucene.Net.FastVectorHighlighter.XML</DocumentationFile>
     <NoWarn>618</NoWarn>
     <DebugSymbols>true</DebugSymbols>
     <OutputType>Library</OutputType>
@@ -103,7 +95,7 @@
     <DefineConstants>TRACE;LUCENENET_350;$(Framework)</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
-    <DocumentationFile>..\..\..\build\bin\contrib\FastVectorHighlighter\Release\NET35\Lucene.Net.Contrib.FastVectorHighlighter.xml</DocumentationFile>
+    <DocumentationFile>..\..\..\build\bin\contrib\FastVectorHighlighter\$(Configuration.Replace("35",
""))\$(Framework)\Lucene.Net.FastVectorHighlighter.XML</DocumentationFile>
     <NoWarn>618</NoWarn>
     <DebugSymbols>true</DebugSymbols>
     <OutputType>Library</OutputType>
@@ -131,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/branches/3.0.3/src/contrib/FastVectorHighlighter/FieldQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/FieldQuery.cs?rev=1381031&r1=1381030&r2=1381031&view=diff
==============================================================================
--- incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/FieldQuery.cs (original)
+++ incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/FieldQuery.cs Wed
Sep  5 07:00:49 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/branches/3.0.3/src/contrib/FastVectorHighlighter/FieldTermStack.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/FieldTermStack.cs?rev=1381031&r1=1381030&r2=1381031&view=diff
==============================================================================
--- incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/FieldTermStack.cs
(original)
+++ incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/FieldTermStack.cs
Wed Sep  5 07:00:49 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/branches/3.0.3/src/contrib/FastVectorHighlighter/StringUtils.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/StringUtils.cs?rev=1381031&view=auto
==============================================================================
--- incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/StringUtils.cs (added)
+++ incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/StringUtils.cs Wed
Sep  5 07:00:49 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/branches/3.0.3/src/contrib/FastVectorHighlighter/StringUtils.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/VectorHighlightMapper.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/VectorHighlightMapper.cs?rev=1381031&r1=1381030&r2=1381031&view=diff
==============================================================================
--- incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/VectorHighlightMapper.cs
(original)
+++ incubator/lucene.net/branches/3.0.3/src/contrib/FastVectorHighlighter/VectorHighlightMapper.cs
Wed Sep  5 07:00:49 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/branches/3.0.3/test/contrib/FastVectorHighlighter/AbstractTestCase.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/AbstractTestCase.cs?rev=1381031&r1=1381030&r2=1381031&view=diff
==============================================================================
--- incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/AbstractTestCase.cs
(original)
+++ incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/AbstractTestCase.cs
Wed Sep  5 07:00:49 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/branches/3.0.3/test/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.Test.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.Test.csproj?rev=1381031&r1=1381030&r2=1381031&view=diff
==============================================================================
--- incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.Test.csproj
(original)
+++ incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/Contrib.FastVectorHighlighter.Test.csproj
Wed Sep  5 07:00:49 2012
@@ -27,13 +27,9 @@
     <SchemaVersion>2.0</SchemaVersion>
     <ProjectGuid>{33ED01FD-A87C-4208-BA49-2586EFE32974}</ProjectGuid>
     <AppDesignerFolder>Properties</AppDesignerFolder>
-    <RootNamespace>Lucene.Net.Search.Vectorhighlight.Test</RootNamespace>
+    <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>
@@ -60,8 +56,6 @@
     <DefineConstants>DEBUG;TRACE;$(Framework)</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
-    <DocumentationFile>
-    </DocumentationFile>
     <NoWarn>618</NoWarn>
     <OutputType>Library</OutputType>
   </PropertyGroup>
@@ -75,8 +69,6 @@
     <DefineConstants>DEBUG;TRACE;$(Framework)</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
-    <DocumentationFile>
-    </DocumentationFile>
     <NoWarn>618</NoWarn>
     <OutputType>Library</OutputType>
   </PropertyGroup>
@@ -89,8 +81,6 @@
     <DefineConstants>TRACE;$(Framework)</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
-    <DocumentationFile>
-    </DocumentationFile>
     <NoWarn>618</NoWarn>
     <DebugSymbols>true</DebugSymbols>
     <OutputType>Library</OutputType>
@@ -104,8 +94,6 @@
     <DefineConstants>TRACE;$(Framework)</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
-    <DocumentationFile>
-    </DocumentationFile>
     <NoWarn>618</NoWarn>
     <DebugSymbols>true</DebugSymbols>
     <OutputType>Library</OutputType>
@@ -127,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/branches/3.0.3/test/contrib/FastVectorHighlighter/FieldQueryTest.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/FieldQueryTest.cs?rev=1381031&r1=1381030&r2=1381031&view=diff
==============================================================================
--- incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/FieldQueryTest.cs
(original)
+++ incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/FieldQueryTest.cs
Wed Sep  5 07:00:49 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/branches/3.0.3/test/contrib/FastVectorHighlighter/FieldTermStackTest.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/FieldTermStackTest.cs?rev=1381031&r1=1381030&r2=1381031&view=diff
==============================================================================
--- incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/FieldTermStackTest.cs
(original)
+++ incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/FieldTermStackTest.cs
Wed Sep  5 07:00:49 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/branches/3.0.3/test/contrib/FastVectorHighlighter/StringUtilsTest.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/StringUtilsTest.cs?rev=1381031&view=auto
==============================================================================
--- incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/StringUtilsTest.cs
(added)
+++ incubator/lucene.net/branches/3.0.3/test/contrib/FastVectorHighlighter/StringUtilsTest.cs
Wed Sep  5 07:00:49 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/branches/3.0.3/test/contrib/FastVectorHighlighter/StringUtilsTest.cs
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message