lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From si...@apache.org
Subject svn commit: r1410304 - in /lucene.net/trunk: src/core/QueryParser/MultiFieldQueryParser.cs test/core/QueryParser/TestMultiFieldQueryParser.cs
Date Fri, 16 Nov 2012 11:09:46 GMT
Author: sisve
Date: Fri Nov 16 11:09:46 2012
New Revision: 1410304

URL: http://svn.apache.org/viewvc?rev=1410304&view=rev
Log:
LUCENENET-513

Modified:
    lucene.net/trunk/src/core/QueryParser/MultiFieldQueryParser.cs
    lucene.net/trunk/test/core/QueryParser/TestMultiFieldQueryParser.cs

Modified: lucene.net/trunk/src/core/QueryParser/MultiFieldQueryParser.cs
URL: http://svn.apache.org/viewvc/lucene.net/trunk/src/core/QueryParser/MultiFieldQueryParser.cs?rev=1410304&r1=1410303&r2=1410304&view=diff
==============================================================================
--- lucene.net/trunk/src/core/QueryParser/MultiFieldQueryParser.cs (original)
+++ lucene.net/trunk/src/core/QueryParser/MultiFieldQueryParser.cs Fri Nov 16 11:09:46 2012
@@ -123,9 +123,10 @@ namespace Lucene.Net.QueryParsers
                         //If the user passes a map of boosts
                         if (boosts != null)
                         {
-                            //Get the boost from the map and apply them
-                            Single boost = boosts[fields[i]];
-                            q.Boost = boost;
+                            //Get the boost and apply them if exists
+                            Single boost;
+                            if (boosts.TryGetValue(fields[i], out boost))
+                                q.Boost = boost;
                         }
                         ApplySlop(q, slop);
                         clauses.Add(new BooleanClause(q, Occur.SHOULD));

Modified: lucene.net/trunk/test/core/QueryParser/TestMultiFieldQueryParser.cs
URL: http://svn.apache.org/viewvc/lucene.net/trunk/test/core/QueryParser/TestMultiFieldQueryParser.cs?rev=1410304&r1=1410303&r2=1410304&view=diff
==============================================================================
--- lucene.net/trunk/test/core/QueryParser/TestMultiFieldQueryParser.cs (original)
+++ lucene.net/trunk/test/core/QueryParser/TestMultiFieldQueryParser.cs Fri Nov 16 11:09:46
2012
@@ -305,6 +305,23 @@ namespace Lucene.Net.QueryParsers
 			Assert.AreEqual(1, hits.Length);
 			is_Renamed.Close();
 		}
+
+        [Test(Description = "LUCENENET-513")]
+        public virtual void TestParsingQueryWithoutBoosts()
+        {
+            var analyzer = new StandardAnalyzer(Util.Version.LUCENE_CURRENT);
+            var fields = new[] {"f1", "f2"};
+            var boosts = new Dictionary<String, Single>
+                {
+                    {"f1", 2}
+                    // missing f2 intentional
+                };
+
+            var parser = new MultiFieldQueryParser(Util.Version.LUCENE_CURRENT, fields, analyzer,
boosts);
+            var query = parser.Parse("bazinga");
+
+            Assert.AreEqual("f1:bazinga^2.0 f2:bazinga", query.ToString());
+        }
 		
 		/// <summary> Return empty tokens for field "f1".</summary>
 		private class AnalyzerReturningNull:Analyzer



Mime
View raw message