Skip to content

Commit

Permalink
peer review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bpathak-ons committed Apr 21, 2022
1 parent 553c0e0 commit af0ef4a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
12 changes: 6 additions & 6 deletions models/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

// ********************************************************
Expand Down
18 changes: 9 additions & 9 deletions models/esmodels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
Expand Down Expand Up @@ -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"`
Expand All @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions transformer/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions transformer/transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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")
Expand All @@ -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()
Expand Down Expand Up @@ -167,6 +170,7 @@ func TestLegacyTransformSearchResponse(t *testing.T) {
}

func TestTransform(t *testing.T) {
t.Parallel()
expectedESDocument1 := models.ESSourceDocument{
DataType: "anyDataType1",
JobID: "",
Expand Down

0 comments on commit af0ef4a

Please sign in to comment.