paulirwin commented on code in PR #1167:
URL: https://github.com/apache/lucenenet/pull/1167#discussion_r2299681551


##########
src/Lucene.Net.Tests.QueryParser/Classic/TestMultiFieldQueryParser.cs:
##########
@@ -385,5 +386,164 @@ public virtual void TestSimpleRegex()
             bq.Add(new RegexpQuery(new Term("b", "[a-z][123]")), Occur.SHOULD);
             assertEquals(bq, mfqp.Parse("/[a-z][123]/"));
         }
+
+        [Test]
+        [LuceneNetSpecific] // LUCENENET specific - Issue #1157
+        public virtual void TestFieldBoostsWithPartialBoostMap()
+        {
+            string[] fields = { "title", "keyword", "description" };
+            MockAnalyzer analyzer = new MockAnalyzer(Random);
+
+            // Create a boost map that only contains boosts for some fields, 
not all
+            // This tests that the TryGetValue fix prevents 
KeyNotFoundException
+            var boosts = new Dictionary<string, float>
+            {
+                { "title", 2.0f },
+                // Intentionally omitting "keyword" and "description" from 
boost map
+            };
+
+            MultiFieldQueryParser parser = new 
MultiFieldQueryParser(TEST_VERSION_CURRENT, fields, analyzer, boosts);
+            Query q = parser.Parse("test");
+
+            // The query should successfully parse without throwing 
KeyNotFoundException
+            string queryString = q.toString();
+            assertTrue("Query should contain boosted title field", 
queryString.Contains("title:test^2.0"));
+            assertTrue("Query should contain keyword field without boost", 
queryString.Contains("keyword:test"));
+            assertTrue("Query should contain description field without boost", 
queryString.Contains("description:test"));
+
+            // Ensure no boost notation for fields not in the boost map
+            assertFalse("Keyword should not have boost notation", 
queryString.Contains("keyword:test^"));
+            assertFalse("Description should not have boost notation", 
queryString.Contains("description:test^"));
+        }
+
+        [Test]
+        [LuceneNetSpecific] // LUCENENET specific - Issue #1157
+        public virtual void TestFieldBoosts()
+        {
+            string[] fields = { "title", "keyword" };
+            MockAnalyzer analyzer = new MockAnalyzer(Random);
+
+            // Test 1: Verify boosts are applied to the query string 
representation
+            var boosts = new Dictionary<string, float>
+            {
+                { "title", 2.0f },
+                { "keyword", 1.0f }
+            };
+
+            MultiFieldQueryParser parser = new 
MultiFieldQueryParser(TEST_VERSION_CURRENT, fields, analyzer, boosts);
+            Query q = parser.Parse("ldqk");
+
+            // The query should have different boosts for each field
+            string queryString = q.toString();
+            assertTrue("Query should contain boosted title field", 
queryString.Contains("title:ldqk^2.0"));
+            assertFalse("Keyword field should not have boost notation when 
boost is 1.0", queryString.Contains("keyword:ldqk^"));

Review Comment:
   I don't believe this is an implementation detail, per se. It is expected 
that a boost is not specified if it is 1.0.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to