@@ -512,6 +512,74 @@ func TestUseArangoSearchView(t *testing.T) {
512512 }
513513}
514514
515+ // TestUseArangoSearchViewWithNested tries to create a view with nested fields and actually use it in an AQL query.
516+ func TestUseArangoSearchViewWithNested (t * testing.T ) {
517+ ctx := context .Background ()
518+ // don't use disallowUnknownFields in this test - we have here custom structs defined
519+ c := createClient (t , true , false )
520+ skipBelowVersion (c , "3.10" , t )
521+ skipNoEnterprise (t )
522+ db := ensureDatabase (nil , c , "view_nested_test" , nil , t )
523+ col := ensureCollection (ctx , db , "some_collection" , nil , t )
524+
525+ ensureArangoSearchView (ctx , db , "some_nested_view" , & driver.ArangoSearchViewProperties {
526+ Links : driver.ArangoSearchLinks {
527+ "some_collection" : driver.ArangoSearchElementProperties {
528+ Fields : driver.ArangoSearchFields {
529+ "dimensions" : driver.ArangoSearchElementProperties {
530+ Nested : driver.ArangoSearchFields {
531+ "type" : driver.ArangoSearchElementProperties {},
532+ "value" : driver.ArangoSearchElementProperties {},
533+ },
534+ },
535+ },
536+ },
537+ },
538+ }, t )
539+
540+ docs := []NestedFieldsDoc {
541+ {
542+ Name : "John" ,
543+ Dimensions : []Dimension {
544+ {"height" , 10 },
545+ {"weight" , 80 },
546+ },
547+ },
548+ {
549+ Name : "Jakub" ,
550+ Dimensions : []Dimension {
551+ {"height" , 25 },
552+ {"weight" , 80 },
553+ },
554+ },
555+ {
556+ Name : "Marek" ,
557+ Dimensions : []Dimension {
558+ {"height" , 30 },
559+ {"weight" , 80 },
560+ },
561+ },
562+ }
563+
564+ _ , errs , err := col .CreateDocuments (ctx , docs )
565+ if err != nil {
566+ t .Fatalf ("Failed to create new documents: %s" , describe (err ))
567+ } else if err := errs .FirstNonNil (); err != nil {
568+ t .Fatalf ("Expected no errors, got first: %s" , describe (err ))
569+ }
570+
571+ // now access it via AQL with waitForSync
572+ {
573+ query := "FOR doc IN some_nested_view SEARCH doc.dimensions[? FILTER CURRENT.type == \" height\" AND CURRENT.value > 20] OPTIONS {waitForSync:true} RETURN doc"
574+ cur , err := db .Query (driver .WithQueryCount (ctx ), query , nil )
575+ if err != nil {
576+ t .Fatalf ("Failed to query data using arangodsearch: %s" , describe (err ))
577+ } else if cur .Count () != 2 || ! cur .HasMore () {
578+ t .Fatalf ("Wrong number of return values: expected 1, found %d" , cur .Count ())
579+ }
580+ }
581+ }
582+
515583// TestUseArangoSearchViewWithPipelineAnalyzer tries to create a view and analyzer and then actually use it in an AQL query.
516584func TestUseArangoSearchViewWithPipelineAnalyzer (t * testing.T ) {
517585 ctx := context .Background ()
0 commit comments