@@ -87,17 +87,19 @@ func Retrieve(uri string, document *Document) error {
8787}
8888
8989// Search looks at the document for the specified search term.
90- func Search (document Document , searchTerm string , searchResults * []SearchResult ) error {
90+ func Search (document Document , searchTerm string ) ([]SearchResult , error ) {
91+ var searchResults []SearchResult
92+
9193 for _ , item := range document .Channel .Item {
9294 // Check the title for the search term.
9395 matched , err := regexp .MatchString (searchTerm , item .Title )
9496 if err != nil {
95- return err
97+ return nil , err
9698 }
9799
98- // If we found as match save the result.
100+ // If we found a match save the result.
99101 if matched {
100- * searchResults = append (* searchResults , SearchResult {
102+ searchResults = append (searchResults , SearchResult {
101103 Field : "Title" ,
102104 Document : item ,
103105 })
@@ -106,17 +108,17 @@ func Search(document Document, searchTerm string, searchResults *[]SearchResult)
106108 // Check the description for the search term.
107109 matched , err = regexp .MatchString (searchTerm , item .Description )
108110 if err != nil {
109- return err
111+ return nil , err
110112 }
111113
112- // If we found a match so save the result.
114+ // If we found a match save the result.
113115 if matched {
114- * searchResults = append (* searchResults , SearchResult {
116+ searchResults = append (searchResults , SearchResult {
115117 Field : "Description" ,
116118 Document : item ,
117119 })
118120 }
119121 }
120122
121- return nil
123+ return searchResults , nil
122124}
0 commit comments