paulirwin commented on code in PR #1167:
URL: https://github.com/apache/lucenenet/pull/1167#discussion_r2299682264
##########
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^"));
Review Comment:
See other response; this is effectively a serialization.
--
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]