@@ -86,69 +86,20 @@ func (handler *SearchHandler) toSearchResponse(ctx context.Context, results []mo
8686 return nil , fmt .Errorf ("typeRepository.GetByName: %q: %v" , result .TypeName , err )
8787 }
8888
89- rv := newRecordView (result .Record )
90-
91- description , _ := getStringFromGenericMap (result .Record , recordType .Fields .Description )
9289 res := SearchResponse {
93- ID : rv .GetString (recordType .Fields .ID ),
94- Title : rv .GetString (recordType .Fields .Title ),
95- Description : description ,
90+ ID : result .Record .Urn ,
91+ Title : result .Record .Name ,
92+ Description : result .Record .Description ,
93+ Labels : result .Record .Labels ,
9694 Type : recordType .Name ,
9795 Classification : string (recordType .Classification ),
98- Labels : make (map [string ]string ),
99- }
100-
101- if err := rv .Error (); err != nil {
102- handler .log .
103- WithField ("record" , result .Record ).
104- Errorf ("dropping record from search result: missing mandatory field: %v" , err )
105- continue
106- }
107-
108- for _ , label := range recordType .Fields .Labels {
109- value , err := getStringFromGenericMap (result .Record , label )
110- if err != nil {
111- continue
112- }
113- res .Labels [label ] = value
11496 }
11597
11698 response = append (response , res )
11799 }
118100 return
119101}
120102
121- // recordView is a helper for querying record fields.
122- // It provides a fail-through interface for obtaining
123- // string fields from a record. If an error is encountered,
124- // all subsequent GetString operations will return immediately
125- // with an empty string, while the Error method will return
126- // the error that was encountered
127- type recordView struct {
128- err error
129- Record models.Record
130- }
131-
132- func newRecordView (record models.Record ) * recordView {
133- return & recordView {Record : record }
134- }
135-
136- func (view * recordView ) GetString (name string ) string {
137- if view .err != nil {
138- return ""
139- }
140- var val string
141- val , view .err = getStringFromGenericMap (view .Record , name )
142- if view .err != nil {
143- return ""
144- }
145- return val
146- }
147-
148- func (view * recordView ) Error () error {
149- return view .err
150- }
151-
152103// cachingTypeRepo is a decorator over a models.TypeRepository
153104// that caches results of previous read-only operations
154105type cachingTypeRepo struct {
@@ -184,18 +135,6 @@ func newCachingTypeRepo(repo models.TypeRepository) *cachingTypeRepo {
184135 }
185136}
186137
187- func getStringFromGenericMap (m map [string ]interface {}, key string ) (string , error ) {
188- val , exists := m [key ]
189- if ! exists {
190- return "" , fmt .Errorf ("no such key: %q" , key )
191- }
192- stringVal , ok := val .(string )
193- if ! ok {
194- return "" , fmt .Errorf ("not a string field: %q" , key )
195- }
196- return stringVal , nil
197- }
198-
199138func filterConfigFromValues (values url.Values ) map [string ][]string {
200139 var filter = make (map [string ][]string )
201140 for key , fields := range values {
0 commit comments