@@ -501,3 +501,106 @@ func TestEnsureZKDIndexWithOptions(t *testing.T) {
501
501
err = idx .Remove (nil )
502
502
require .NoError (t , err )
503
503
}
504
+
505
+ // TestEnsureInvertedIndex creates a collection with an inverted index
506
+ func TestEnsureInvertedIndex (t * testing.T ) {
507
+ ctx := context .Background ()
508
+
509
+ c := createClientFromEnv (t , true )
510
+ EnsureVersion (t , ctx , c ).CheckVersion (MinimumVersion ("3.10.0" ))
511
+
512
+ db := ensureDatabase (ctx , c , "index_test" , nil , t )
513
+ col := ensureCollection (ctx , db , fmt .Sprintf ("inverted_index_opt_test" ), nil , t )
514
+
515
+ type testCase struct {
516
+ IsEE bool
517
+ Options driver.InvertedIndexOptions
518
+ }
519
+ testCases := []testCase {
520
+ {
521
+ IsEE : false ,
522
+ Options : driver.InvertedIndexOptions {
523
+ Name : "inverted-opt" ,
524
+ PrimarySort : driver.InvertedIndexPrimarySort {
525
+ Fields : []driver.ArangoSearchPrimarySortEntry {
526
+ {Field : "test1" , Ascending : newBool (true )},
527
+ {Field : "test2" , Ascending : newBool (false )},
528
+ },
529
+ Compression : driver .PrimarySortCompressionLz4 ,
530
+ },
531
+ Features : []driver.ArangoSearchAnalyzerFeature {},
532
+ StoredValues : []driver.StoredValue {},
533
+ Fields : []driver.InvertedIndexField {
534
+ {Name : "field1" , Features : []driver.ArangoSearchAnalyzerFeature {driver .ArangoSearchAnalyzerFeatureFrequency }, Nested : nil },
535
+ {Name : "field2" , Features : []driver.ArangoSearchAnalyzerFeature {driver .ArangoSearchAnalyzerFeaturePosition }, TrackListPositions : false , Nested : nil },
536
+ },
537
+ },
538
+ },
539
+ {
540
+ IsEE : true ,
541
+ Options : driver.InvertedIndexOptions {
542
+ Name : "inverted-opt-nested" ,
543
+ PrimarySort : driver.InvertedIndexPrimarySort {
544
+ Fields : []driver.ArangoSearchPrimarySortEntry {
545
+ {Field : "test1" , Ascending : newBool (true )},
546
+ {Field : "test2" , Ascending : newBool (false )},
547
+ },
548
+ Compression : driver .PrimarySortCompressionLz4 ,
549
+ },
550
+ Features : []driver.ArangoSearchAnalyzerFeature {},
551
+ StoredValues : []driver.StoredValue {},
552
+ Fields : []driver.InvertedIndexField {
553
+ {Name : "field1" , Features : []driver.ArangoSearchAnalyzerFeature {driver .ArangoSearchAnalyzerFeatureFrequency }, Nested : nil },
554
+ {Name : "field2" , Features : []driver.ArangoSearchAnalyzerFeature {driver .ArangoSearchAnalyzerFeaturePosition }, TrackListPositions : false ,
555
+ Nested : []driver.InvertedIndexField {
556
+ {
557
+ Name : "some-nested-field" ,
558
+ Nested : []driver.InvertedIndexField {
559
+ {Name : "test" },
560
+ {Name : "bas" , Nested : []driver.InvertedIndexField {
561
+ {Name : "a" , Features : nil },
562
+ }},
563
+ {Name : "kas" , Nested : []driver.InvertedIndexField {
564
+ {Name : "b" , TrackListPositions : true },
565
+ {Name : "c" },
566
+ }},
567
+ },
568
+ },
569
+ },
570
+ },
571
+ },
572
+ },
573
+ },
574
+ }
575
+
576
+ for _ , tc := range testCases {
577
+ t .Run (tc .Options .Name , func (t * testing.T ) {
578
+ if tc .IsEE {
579
+ skipNoEnterprise (t )
580
+ }
581
+
582
+ idx , created , err := col .EnsureInvertedIndex (ctx , & tc .Options )
583
+ require .NoError (t , err )
584
+ require .True (t , created )
585
+
586
+ tc .Options .IsNewlyCreated = true
587
+ tc .Options .Analyzer = driver .ArangoSearchAnalyzerTypeIdentity // default value for analyzer
588
+
589
+ requireIdxEquality := func (invertedIdx driver.Index ) {
590
+ require .Equal (t , driver .InvertedIndex , idx .Type ())
591
+ require .Equal (t , tc .Options .Name , idx .UserName ())
592
+ require .Equal (t , tc .Options , idx .InvertedIndexOptions ())
593
+ }
594
+ requireIdxEquality (idx )
595
+
596
+ indexes , err := col .Indexes (ctx )
597
+ require .NoError (t , err )
598
+ require .NotEmpty (t , indexes )
599
+
600
+ requireIdxEquality (indexes [0 ])
601
+
602
+ err = idx .Remove (nil )
603
+ require .NoError (t , err )
604
+ })
605
+ }
606
+ }
0 commit comments