Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## [master](https://github.com/arangodb/go-driver/tree/master) (N/A)
- Use Go 1.19.4
- Add `IsExternalStorageError` to check for [external storage errors](https://www.arangodb.com/docs/stable/appendix-error-codes.html#external-arangodb-storage-errors).
- Add `IsExternalStorageError` to check for [external storage errors](https://www.arangodb.com/docs/stable/appendix-error-codes.html#external-arangodb-storage-errors)
- `nested` field in arangosearch type View

## [1.4.1](https://github.com/arangodb/go-driver/tree/v1.4.1) (2022-12-14)
- Add support for `checksum` in Collections
Expand Down
10 changes: 10 additions & 0 deletions test/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ type UserDocWithKeyWithOmit struct {
Age int `json:"age,omitempty"`
}

type NestedFieldsDoc struct {
Name string `json:"name"`
Dimensions []Dimension `json:"dimensions,omitempty"`
}

type Dimension struct {
Type string `json:"type"`
Value int `json:"value"`
}

type Account struct {
ID string `json:"id"`
User *UserDoc `json:"user"`
Expand Down
68 changes: 68 additions & 0 deletions test/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,74 @@ func TestUseArangoSearchView(t *testing.T) {
}
}

// TestUseArangoSearchViewWithNested tries to create a view with nested fields and actually use it in an AQL query.
func TestUseArangoSearchViewWithNested(t *testing.T) {
ctx := context.Background()
// don't use disallowUnknownFields in this test - we have here custom structs defined
c := createClient(t, true, false)
skipBelowVersion(c, "3.10", t)
skipNoEnterprise(t)
db := ensureDatabase(nil, c, "view_nested_test", nil, t)
col := ensureCollection(ctx, db, "some_collection", nil, t)

ensureArangoSearchView(ctx, db, "some_nested_view", &driver.ArangoSearchViewProperties{
Links: driver.ArangoSearchLinks{
"some_collection": driver.ArangoSearchElementProperties{
Fields: driver.ArangoSearchFields{
"dimensions": driver.ArangoSearchElementProperties{
Nested: driver.ArangoSearchFields{
"type": driver.ArangoSearchElementProperties{},
"value": driver.ArangoSearchElementProperties{},
},
},
},
},
},
}, t)

docs := []NestedFieldsDoc{
{
Name: "John",
Dimensions: []Dimension{
{"height", 10},
{"weight", 80},
},
},
{
Name: "Jakub",
Dimensions: []Dimension{
{"height", 25},
{"weight", 80},
},
},
{
Name: "Marek",
Dimensions: []Dimension{
{"height", 30},
{"weight", 80},
},
},
}

_, errs, err := col.CreateDocuments(ctx, docs)
if err != nil {
t.Fatalf("Failed to create new documents: %s", describe(err))
} else if err := errs.FirstNonNil(); err != nil {
t.Fatalf("Expected no errors, got first: %s", describe(err))
}

// now access it via AQL with waitForSync
{
query := "FOR doc IN some_nested_view SEARCH doc.dimensions[? FILTER CURRENT.type == \"height\" AND CURRENT.value > 20] OPTIONS {waitForSync:true} RETURN doc"
cur, err := db.Query(driver.WithQueryCount(ctx), query, nil)
if err != nil {
t.Fatalf("Failed to query data using arangodsearch: %s", describe(err))
} else if cur.Count() != 2 || !cur.HasMore() {
t.Fatalf("Wrong number of return values: expected 1, found %d", cur.Count())
}
}
}

// TestUseArangoSearchViewWithPipelineAnalyzer tries to create a view and analyzer and then actually use it in an AQL query.
func TestUseArangoSearchViewWithPipelineAnalyzer(t *testing.T) {
ctx := context.Background()
Expand Down
3 changes: 3 additions & 0 deletions view_arangosearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,9 @@ type ArangoSearchElementProperties struct {
// so that it remains basically available. inBackground is an option that can be set when adding links.
// It does not get persisted as it is not a View property, but only a one-off option
InBackground *bool `json:"inBackground,omitempty"`
// Nested contains the properties for nested fields (sub-objects) of the element
// Enterprise Edition only
Nested ArangoSearchFields `json:"nested,omitempty"`
// Cache If you enable this option, then field normalization values are always cached in memory.
// Introduced in v3.9.5, Enterprise Edition only
Cache *bool `json:"cache,omitempty"`
Expand Down