diff --git a/models/elasticsearch.go b/models/elasticsearch.go index c97dcb40..697679fd 100644 --- a/models/elasticsearch.go +++ b/models/elasticsearch.go @@ -54,12 +54,12 @@ type ESSourceDocument struct { } type ESHighlight struct { - DescriptionTitle *[]string `json:"description.title"` - DescriptionEdition *[]string `json:"description.edition"` - DescriptionSummary *[]string `json:"description.summary"` - DescriptionMeta *[]string `json:"description.metaDescription"` - DescriptionKeywords *[]string `json:"description.keywords"` - DescriptionDatasetID *[]string `json:"description.datasetId"` + DescriptionTitle []*string `json:"description.title"` + DescriptionEdition []*string `json:"description.edition"` + DescriptionSummary []*string `json:"description.summary"` + DescriptionMeta []*string `json:"description.metaDescription"` + DescriptionKeywords []*string `json:"description.keywords"` + DescriptionDatasetID []*string `json:"description.datasetId"` } // ******************************************************** diff --git a/models/esmodels.go b/models/esmodels.go index 38cf157b..d91043bd 100644 --- a/models/esmodels.go +++ b/models/esmodels.go @@ -29,7 +29,7 @@ type DescriptionLegacy struct { Headline2 string `json:"headline2,omitempty"` Headline3 string `json:"headline3,omitempty"` Highlight *HighlightObjLegacy `json:"highlight,omitempty"` - Keywords *[]string `json:"keywords,omitempty"` + Keywords []*string `json:"keywords,omitempty"` LatestRelease *bool `json:"latest_release,omitempty"` Language string `json:"language,omitempty"` MetaDescription string `json:"meta_description,omitempty"` @@ -52,7 +52,7 @@ type contactLegacy struct { type HighlightObjLegacy struct { DatasetID string `json:"dataset_id,omitempty"` Edition string `json:"edition,omitempty"` - Keywords *[]string `json:"keywords,omitempty"` + Keywords []*string `json:"keywords,omitempty"` MetaDescription string `json:"meta_description,omitempty"` Summary string `json:"summary,omitempty"` Title string `json:"title,omitempty"` @@ -86,7 +86,7 @@ type ESSourceDocumentLegacy struct { Summary string `json:"summary"` NextRelease string `json:"nextRelease,omitempty"` Unit string `json:"unit,omitempty"` - Keywords *[]string `json:"keywords,omitempty"` + Keywords []*string `json:"keywords,omitempty"` ReleaseDate string `json:"releaseDate,omitempty"` Edition string `json:"edition,omitempty"` LatestRelease *bool `json:"latestRelease,omitempty"` @@ -107,12 +107,12 @@ type ESSourceDocumentLegacy struct { } type ESHighlightLegacy struct { - DescriptionTitle *[]string `json:"description.title"` - DescriptionEdition *[]string `json:"description.edition"` - DescriptionSummary *[]string `json:"description.summary"` - DescriptionMeta *[]string `json:"description.metaDescription"` - DescriptionKeywords *[]string `json:"description.keywords"` - DescriptionDatasetID *[]string `json:"description.datasetId"` + DescriptionTitle []*string `json:"description.title"` + DescriptionEdition []*string `json:"description.edition"` + DescriptionSummary []*string `json:"description.summary"` + DescriptionMeta []*string `json:"description.metaDescription"` + DescriptionKeywords []*string `json:"description.keywords"` + DescriptionDatasetID []*string `json:"description.datasetId"` } type ESResponseAggregationsLegacy struct { diff --git a/transformer/transformer.go b/transformer/transformer.go index 184974cd..a817fd80 100644 --- a/transformer/transformer.go +++ b/transformer/transformer.go @@ -138,32 +138,32 @@ func (t *LegacyTransformer) buildDescription(doc models.ESResponseHitLegacy, hig return des } -func (t *LegacyTransformer) overlaySingleItem(hl *[]string, def string, highlight bool) (overlaid string) { - if highlight && hl != nil && len(*hl) > 0 { - overlaid = (*hl)[0] +func (t *LegacyTransformer) overlaySingleItem(hl []*string, def string, highlight bool) (overlaid string) { + if highlight && hl != nil && len(hl) > 0 { + overlaid = *(hl)[0] } return } -func (t *LegacyTransformer) overlayItemList(hlList, defaultList *[]string, highlight bool) *[]string { +func (t *LegacyTransformer) overlayItemList(hlList, defaultList []*string, highlight bool) []*string { if defaultList == nil || hlList == nil { return nil } - overlaid := make([]string, len(*defaultList)) - copy(overlaid, *defaultList) + overlaid := make([]*string, len(defaultList)) + copy(overlaid, defaultList) if highlight { - for _, hl := range *hlList { - unformatted := t.higlightReplacer.Replace(hl) + for _, hl := range hlList { + unformatted := t.higlightReplacer.Replace(*hl) for i, defItem := range overlaid { - if defItem == unformatted { + if *defItem == unformatted { overlaid[i] = hl } } } } - return &overlaid + return overlaid } func buildContentTypes(bucket models.ESBucketLegacy) models.ContentTypeLegacy { diff --git a/transformer/transformer_test.go b/transformer/transformer_test.go index 04043245..d5b7e391 100644 --- a/transformer/transformer_test.go +++ b/transformer/transformer_test.go @@ -11,6 +11,7 @@ import ( ) func TestLegacyTransformer(t *testing.T) { + t.Parallel() Convey("Transforms unmarshalled search responses successfully", t, func() { transformer := NewLegacy() Convey("Zero suggestions creates empty array", func() { @@ -79,6 +80,7 @@ func TestLegacyTransformer(t *testing.T) { } func TestLegacyBuildAdditionalSuggestionsList(t *testing.T) { + t.Parallel() Convey("buildAdditionalSuggestionList successfully", t, func() { Convey("returns array of strings", func() { query1 := buildAdditionalSuggestionList("test-query") @@ -100,6 +102,7 @@ func TestLegacyBuildAdditionalSuggestionsList(t *testing.T) { } func TestLegacyTransformSearchResponse(t *testing.T) { + t.Parallel() Convey("With a transformer initialised", t, func() { ctx := context.Background() transformer := NewLegacy() @@ -167,6 +170,7 @@ func TestLegacyTransformSearchResponse(t *testing.T) { } func TestTransform(t *testing.T) { + t.Parallel() expectedESDocument1 := models.ESSourceDocument{ DataType: "anyDataType1", JobID: "",