@@ -506,6 +506,104 @@ func TestUseArangoSearchView(t *testing.T) {
506506 }
507507}
508508
509+ // TestUseArangoSearchViewWithPipelineAnalyzer tries to create a view and analyzer and then actually use it in an AQL query.
510+ func TestUseArangoSearchViewWithPipelineAnalyzer (t * testing.T ) {
511+ ctx := context .Background ()
512+ // don't use disallowUnknownFields in this test - we have here custom structs defined
513+ c := createClient (t , true , false )
514+ skipBelowVersion (c , "3.8" , t )
515+ db := ensureDatabase (nil , c , "view_with_pipeline_test" , nil , t )
516+ col := ensureCollection (ctx , db , "some_collection_with_analyzer" , nil , t )
517+
518+ analyzer := driver.ArangoSearchAnalyzerDefinition {
519+ Name : "custom_analyzer" ,
520+ Type : driver .ArangoSearchAnalyzerTypePipeline ,
521+ Properties : driver.ArangoSearchAnalyzerProperties {
522+ Pipeline : []driver.ArangoSearchAnalyzerPipeline {
523+ {
524+ Type : driver .ArangoSearchAnalyzerTypeNGram ,
525+ Properties : driver.ArangoSearchAnalyzerProperties {
526+ Min : newInt64 (2 ),
527+ Max : newInt64 (2 ),
528+ PreserveOriginal : newBool (false ),
529+ StreamType : newArangoSearchNGramStreamType (driver .ArangoSearchNGramStreamUTF8 ),
530+ },
531+ },
532+ {
533+ Type : driver .ArangoSearchAnalyzerTypeNorm ,
534+ Properties : driver.ArangoSearchAnalyzerProperties {
535+ Locale : "en" ,
536+ Case : driver .ArangoSearchCaseLower ,
537+ },
538+ },
539+ },
540+ },
541+ Features : []driver.ArangoSearchAnalyzerFeature {
542+ driver .ArangoSearchAnalyzerFeatureFrequency ,
543+ driver .ArangoSearchAnalyzerFeaturePosition ,
544+ driver .ArangoSearchAnalyzerFeatureNorm ,
545+ },
546+ }
547+ existed , _ , err := db .EnsureAnalyzer (ctx , analyzer )
548+ require .NoError (t , err )
549+ require .False (t , existed )
550+
551+ ensureArangoSearchView (ctx , db , "some_view_with_analyzer" , & driver.ArangoSearchViewProperties {
552+ Links : driver.ArangoSearchLinks {
553+ "some_collection_with_analyzer" : driver.ArangoSearchElementProperties {
554+ Fields : driver.ArangoSearchFields {
555+ "name" : driver.ArangoSearchElementProperties {
556+ Analyzers : []string {"custom_analyzer" },
557+ },
558+ },
559+ },
560+ },
561+ }, t )
562+
563+ docs := []UserDoc {
564+ UserDoc {
565+ "John" ,
566+ 23 ,
567+ },
568+ UserDoc {
569+ "Alice" ,
570+ 12 ,
571+ },
572+ UserDoc {
573+ "Helmut" ,
574+ 17 ,
575+ },
576+ }
577+
578+ _ , errs , err := col .CreateDocuments (ctx , docs )
579+ if err != nil {
580+ t .Fatalf ("Failed to create new documents: %s" , describe (err ))
581+ } else if err := errs .FirstNonNil (); err != nil {
582+ t .Fatalf ("Expected no errors, got first: %s" , describe (err ))
583+ }
584+
585+ // now access it via AQL with waitForSync
586+ {
587+ cur , err := db .Query (driver .WithQueryCount (ctx ), `FOR doc IN some_view_with_analyzer SEARCH NGRAM_MATCH(doc.name, 'john', 0.75, 'custom_analyzer') OPTIONS {waitForSync:true} RETURN doc` , nil )
588+
589+ if err != nil {
590+ t .Fatalf ("Failed to query data using arangodsearch: %s" , describe (err ))
591+ } else if cur .Count () != 1 || ! cur .HasMore () {
592+ t .Fatalf ("Wrong number of return values: expected 1, found %d" , cur .Count ())
593+ }
594+
595+ var doc UserDoc
596+ _ , err = cur .ReadDocument (ctx , & doc )
597+ if err != nil {
598+ t .Fatalf ("Failed to read document: %s" , describe (err ))
599+ }
600+
601+ if doc .Name != "John" {
602+ t .Fatalf ("Expected result `John`, found `%s`" , doc .Name )
603+ }
604+ }
605+ }
606+
509607// TestGetArangoSearchView creates an arangosearch view and then gets it again.
510608func TestArangoSearchViewProperties35 (t * testing.T ) {
511609 ctx := context .Background ()
0 commit comments