+/**
+ * Manual validation script for BooleanQueryBuilder
+ * This tests the new fluent API functionality
+ */
+
+try {
+ // Get the SearchBuilder instance (this should work if the module is properly configured)
+ searchBuilder = new cbelasticsearch.models.SearchBuilder();
+
+ writeOutput("BooleanQueryBuilder Manual Validation
");
+
+ // Test 1: Basic fluent must() method
+ writeOutput("Test 1: Basic must().term() fluent API
");
+ testBuilder1 = new cbelasticsearch.models.SearchBuilder();
+ testBuilder1.new( "test_index", "test_type" );
+
+ // This should work: must().term()
+ testBuilder1.must().term( "status", "active" );
+ query1 = testBuilder1.getQuery();
+
+ writeOutput("Query Structure:
");
+ writeOutput("" & serializeJSON( query1, false, true ) & "
");
+
+ // Verify structure
+ hasCorrectStructure1 = structKeyExists( query1, "bool" )
+ && structKeyExists( query1.bool, "must" )
+ && isArray( query1.bool.must )
+ && arrayLen( query1.bool.must ) == 1
+ && structKeyExists( query1.bool.must[1], "term" )
+ && structKeyExists( query1.bool.must[1].term, "status" )
+ && query1.bool.must[1].term.status == "active";
+
+ writeOutput("Validation: " & (hasCorrectStructure1 ? "PASS" : "FAIL") & "
");
+
+ // Test 2: Nested fluent API - bool().filter().bool().must()
+ writeOutput("Test 2: Nested bool().filter().bool().must().wildcard() API
");
+ testBuilder2 = new cbelasticsearch.models.SearchBuilder();
+ testBuilder2.new( "test_index", "test_type" );
+
+ // This tests the original issue case
+ testBuilder2.bool().filter().bool().must().wildcard( "title", "*test*" );
+ query2 = testBuilder2.getQuery();
+
+ writeOutput("Query Structure:
");
+ writeOutput("" & serializeJSON( query2, false, true ) & "
");
+
+ // Verify nested structure
+ hasCorrectStructure2 = structKeyExists( query2, "bool" )
+ && structKeyExists( query2.bool, "filter" )
+ && structKeyExists( query2.bool.filter, "bool" )
+ && structKeyExists( query2.bool.filter.bool, "must" )
+ && isArray( query2.bool.filter.bool.must )
+ && arrayLen( query2.bool.filter.bool.must ) == 1
+ && structKeyExists( query2.bool.filter.bool.must[1], "wildcard" )
+ && structKeyExists( query2.bool.filter.bool.must[1].wildcard, "title" );
+
+ writeOutput("Validation: " & (hasCorrectStructure2 ? "PASS" : "FAIL") & "
");
+
+ // Test 3: Multiple chained operations
+ writeOutput("Test 3: Multiple chained operations
");
+ testBuilder3 = new cbelasticsearch.models.SearchBuilder();
+ testBuilder3.new( "test_index", "test_type" );
+
+ // Chain multiple operations
+ testBuilder3
+ .must().term( "status", "active" )
+ .should().match( "title", "elasticsearch" )
+ .filter().range( "price", gte = 10, lte = 100 );
+
+ query3 = testBuilder3.getQuery();
+
+ writeOutput("Query Structure:
");
+ writeOutput("" & serializeJSON( query3, false, true ) & "
");
+
+ // Verify multiple structures
+ hasCorrectStructure3 = structKeyExists( query3, "bool" )
+ && structKeyExists( query3.bool, "must" )
+ && structKeyExists( query3.bool, "should" )
+ && structKeyExists( query3.bool, "filter" )
+ && isArray( query3.bool.must )
+ && isArray( query3.bool.should )
+ && structKeyExists( query3.bool.filter, "range" );
+
+ writeOutput("Validation: " & (hasCorrectStructure3 ? "PASS" : "FAIL") & "
");
+
+ // Test 4: Comparison with original manual approach
+ writeOutput("Test 4: Comparison with Manual Approach
");
+
+ // Manual approach (what we're replacing)
+ manualBuilder = new cbelasticsearch.models.SearchBuilder();
+ manualBuilder.new( "test_index", "test_type" );
+ var q = manualBuilder.getQuery();
+ param q.bool = {};
+ param q.bool.filter = {};
+ param q.bool.filter.bool.must = [];
+ arrayAppend( q.bool.filter.bool.must, {
+ "wildcard" : {
+ "title" : {
+ "value" : "*test*"
+ }
+ }
+ } );
+
+ writeOutput("Manual Query Structure:
");
+ writeOutput("" & serializeJSON( manualBuilder.getQuery(), false, true ) & "
");
+
+ writeOutput("Fluent Query Structure (from Test 2):
");
+ writeOutput("" & serializeJSON( query2, false, true ) & "
");
+
+ // Compare structures
+ manualJSON = serializeJSON( manualBuilder.getQuery(), false, false );
+ fluentJSON = serializeJSON( query2, false, false );
+ structuresMatch = manualJSON == fluentJSON;
+
+ writeOutput("Structures Match: " & (structuresMatch ? "PASS" : "FAIL") & "
");
+
+ if (!structuresMatch) {
+ writeOutput("Manual JSON:
" & manualJSON & "
");
+ writeOutput("Fluent JSON:
" & fluentJSON & "
");
+ }
+
+ // Test 5: Backward compatibility
+ writeOutput("Test 5: Backward Compatibility
");
+ testBuilder4 = new cbelasticsearch.models.SearchBuilder();
+ testBuilder4.new( "test_index", "test_type" );
+
+ // Mix old and new APIs
+ testBuilder4.mustMatch( "title", "elasticsearch" ); // Old API
+ testBuilder4.must().term( "status", "active" ); // New API
+
+ query4 = testBuilder4.getQuery();
+ writeOutput("Mixed API Query Structure:
");
+ writeOutput("" & serializeJSON( query4, false, true ) & "
");
+
+ // Should have 2 items in must array
+ backwardCompatible = structKeyExists( query4, "bool" )
+ && structKeyExists( query4.bool, "must" )
+ && isArray( query4.bool.must )
+ && arrayLen( query4.bool.must ) == 2;
+
+ writeOutput("Backward Compatibility: " & (backwardCompatible ? "PASS" : "FAIL") & "
");
+
+ // Summary
+ writeOutput("Summary
");
+ allTestsPass = hasCorrectStructure1 && hasCorrectStructure2 && hasCorrectStructure3 && structuresMatch && backwardCompatible;
+ writeOutput("Overall Result: " & (allTestsPass ? "ALL TESTS PASS" : "SOME TESTS FAILED") & "
");
+
+ if (allTestsPass) {
+ writeOutput("✓ BooleanQueryBuilder implementation is working correctly!
");
+ writeOutput("The fluent API successfully replaces manual query structure manipulation.
");
+ }
+
+} catch (any e) {
+ writeOutput("Error in Manual Validation
");
+ writeOutput("Error Details:
");
+ writeOutput("" & serializeJSON( e, false, true ) & "
");
+
+ writeOutput("Troubleshooting:
");
+ writeOutput("");
+ writeOutput("- Check if BooleanQueryBuilder.cfc exists in models/ directory
");
+ writeOutput("- Verify SearchBuilder.cfc has the new fluent methods
");
+ writeOutput("- Ensure module mapping is correct
");
+ writeOutput("
");
+}
+
\ No newline at end of file
From 61e7b04dc60f49a7ca1e6b44a95ed7f6e55846be Mon Sep 17 00:00:00 2001
From: Copilot