Skip to content

Commit fa19f30

Browse files
authored
support for geo_s2 analyzers (#492)
1 parent c38ae22 commit fa19f30

File tree

3 files changed

+60
-8
lines changed

3 files changed

+60
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [V2] Support for Collection Documents removal
77
- [V2] Fix: Plain Connection doesn't work with JWT authentication
88
- Support for new error codes if write concern is not fulfilled
9+
- Support for geo_s2 analyzers
910

1011
## [1.5.2](https://github.com/arangodb/go-driver/tree/v1.5.2) (2023-03-01)
1112
- Bump `DRIVER_VERSION`

test/arangosearch_analyzers_test.go

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2018-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
1717
//
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
20-
// Author Ewout Prangsma
21-
//
2220

2321
package test
2422

@@ -29,7 +27,7 @@ import (
2927

3028
"github.com/stretchr/testify/require"
3129

32-
driver "github.com/arangodb/go-driver"
30+
"github.com/arangodb/go-driver"
3331
)
3432

3533
func newInt(v int) *int {
@@ -95,7 +93,6 @@ func TestArangoSearchAnalyzerEnsureAnalyzer(t *testing.T) {
9593
HasError bool
9694
EnterpriseOnly bool
9795
}{
98-
9996
{
10097
Name: "create-my-identity",
10198
Definition: driver.ArangoSearchAnalyzerDefinition{
@@ -261,6 +258,37 @@ func TestArangoSearchAnalyzerEnsureAnalyzer(t *testing.T) {
261258
},
262259
},
263260
},
261+
{
262+
Name: "create-geo_s2",
263+
MinVersion: newVersion("3.10.5"),
264+
Definition: driver.ArangoSearchAnalyzerDefinition{
265+
Name: "my-geo_s2",
266+
Type: driver.ArangoSearchAnalyzerTypeGeoS2,
267+
Properties: driver.ArangoSearchAnalyzerProperties{
268+
Format: driver.FormatLatLngInt.New(),
269+
Options: &driver.ArangoSearchAnalyzerGeoOptions{
270+
MaxCells: newInt(20),
271+
MinLevel: newInt(4),
272+
MaxLevel: newInt(23),
273+
},
274+
Type: driver.ArangoSearchAnalyzerGeoJSONTypeShape.New(),
275+
},
276+
},
277+
ExpectedDefinition: &driver.ArangoSearchAnalyzerDefinition{
278+
Name: "my-geo_s2",
279+
Type: driver.ArangoSearchAnalyzerTypeGeoS2,
280+
Properties: driver.ArangoSearchAnalyzerProperties{
281+
Format: driver.FormatLatLngInt.New(),
282+
Options: &driver.ArangoSearchAnalyzerGeoOptions{
283+
MaxCells: newInt(20),
284+
MinLevel: newInt(4),
285+
MaxLevel: newInt(23),
286+
},
287+
Type: driver.ArangoSearchAnalyzerGeoJSONTypeShape.New(),
288+
},
289+
},
290+
EnterpriseOnly: true,
291+
},
264292
{
265293
Name: "create-segmentation",
266294
MinVersion: newVersion("3.9"),

view_arangosearch.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2018-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
1717
//
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
20-
// Author Ewout Prangsma
21-
//
2220

2321
package driver
2422

@@ -63,6 +61,10 @@ const (
6361
ArangoSearchAnalyzerTypeStopwords ArangoSearchAnalyzerType = "stopwords"
6462
// ArangoSearchAnalyzerTypeGeoJSON an Analyzer capable of breaking up a GeoJSON object into a set of indexable tokens for further usage with ArangoSearch Geo functions.
6563
ArangoSearchAnalyzerTypeGeoJSON ArangoSearchAnalyzerType = "geojson"
64+
// ArangoSearchAnalyzerTypeGeoS2 an Analyzer capable of index GeoJSON data with inverted indexes or Views similar
65+
// to the existing `geojson` Analyzer, but it internally uses a format for storing the geo-spatial data.
66+
// that is more efficient.
67+
ArangoSearchAnalyzerTypeGeoS2 ArangoSearchAnalyzerType = "geo_s2"
6668
// ArangoSearchAnalyzerTypeGeoPoint an Analyzer capable of breaking up JSON object describing a coordinate into a set of indexable tokens for further usage with ArangoSearch Geo functions.
6769
ArangoSearchAnalyzerTypeGeoPoint ArangoSearchAnalyzerType = "geopoint"
6870
// ArangoSearchAnalyzerTypeSegmentation an Analyzer capable of breaking up the input text into tokens in a language-agnostic manner
@@ -133,6 +135,24 @@ type ArangoSearchEdgeNGram struct {
133135
PreserveOriginal *bool `json:"preserveOriginal,omitempty"`
134136
}
135137

138+
type ArangoSearchFormat string
139+
140+
const (
141+
// FormatLatLngDouble stores each latitude and longitude value as an 8-byte floating-point value (16 bytes per coordinate pair).
142+
// It is default value.
143+
FormatLatLngDouble ArangoSearchFormat = "latLngDouble"
144+
// FormatLatLngInt stores each latitude and longitude value as an 4-byte integer value (8 bytes per coordinate pair).
145+
// This is the most compact format but the precision is limited to approximately 1 to 10 centimeters.
146+
FormatLatLngInt ArangoSearchFormat = "latLngInt"
147+
// FormatS2Point store each longitude-latitude pair in the native format of Google S2 which is used for geo-spatial
148+
// calculations (24 bytes per coordinate pair).
149+
FormatS2Point ArangoSearchFormat = "s2Point"
150+
)
151+
152+
func (a ArangoSearchFormat) New() *ArangoSearchFormat {
153+
return &a
154+
}
155+
136156
// ArangoSearchAnalyzerProperties specifies options for the analyzer. Which fields are required and
137157
// respected depends on the analyzer type.
138158
// more information can be found here: https://www.arangodb.com/docs/stable/arangosearch-analyzers.html#analyzer-properties
@@ -223,6 +243,9 @@ type ArangoSearchAnalyzerProperties struct {
223243
// NumHashes used by Minhash
224244
// Size of min hash signature. Must be greater or equal to 1.
225245
NumHashes *uint64 `json:"numHashes,omitempty"`
246+
247+
// Format is the internal binary representation to use for storing the geo-spatial data in an index.
248+
Format *ArangoSearchFormat `json:"format,omitempty"`
226249
}
227250

228251
// ArangoSearchAnalyzerGeoJSONType GeoJSON Type parameter.

0 commit comments

Comments
 (0)