about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--internal/search/search.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/internal/search/search.go b/internal/search/search.go
index 596c1fb..da5865c 100644
--- a/internal/search/search.go
+++ b/internal/search/search.go
@@ -159,14 +159,17 @@ func (index *Index[T]) Search(ctx context.Context, keyword string, from uint64)
 		}
 
 		results := make([]T, min(ResultsPerPage, bleveResult.Total))
+		var buf bytes.Buffer
 		for i, result := range bleveResult.Hits {
-			data := result.Fields["data"]
-			byt := bytes.NewBuffer([]byte(data.(string)))
-			dec := gob.NewDecoder(byt)
-			err := dec.Decode(&results[i])
+			_, err = buf.WriteString(result.Fields["data"].(string))
 			if err != nil {
-				return nil, errors.WithMessagef(err, "error decoding gob data: %s", byt.String())
+				return nil, errors.WithMessage(err, "error fetching result data")
 			}
+			err = gob.NewDecoder(&buf).Decode(&results[i])
+			if err != nil {
+				return nil, errors.WithMessagef(err, "error decoding gob data: %s", buf.String())
+			}
+			buf.Reset()
 		}
 
 		return &Result[T]{