Search looks at the document for the specified search term.
(feed *search.Feed, searchTerm string)
| 68 | |
| 69 | // Search looks at the document for the specified search term. |
| 70 | func (m rssMatcher) Search(feed *search.Feed, searchTerm string) ([]*search.Result, error) { |
| 71 | var results []*search.Result |
| 72 | |
| 73 | log.Printf("Search Feed Type[%s] Site[%s] For URI[%s]\n", feed.Type, feed.Name, feed.URI) |
| 74 | |
| 75 | // Retrieve the data to search. |
| 76 | document, err := m.retrieve(feed) |
| 77 | if err != nil { |
| 78 | return nil, err |
| 79 | } |
| 80 | |
| 81 | for _, channelItem := range document.Channel.Item { |
| 82 | // Check the title for the search term. |
| 83 | matched, err := regexp.MatchString(searchTerm, channelItem.Title) |
| 84 | if err != nil { |
| 85 | return nil, err |
| 86 | } |
| 87 | |
| 88 | // If we found a match save the result. |
| 89 | if matched { |
| 90 | results = append(results, &search.Result{ |
| 91 | Field: "Title", |
| 92 | Content: channelItem.Title, |
| 93 | }) |
| 94 | } |
| 95 | |
| 96 | // Check the description for the search term. |
| 97 | matched, err = regexp.MatchString(searchTerm, channelItem.Description) |
| 98 | if err != nil { |
| 99 | return nil, err |
| 100 | } |
| 101 | |
| 102 | // If we found a match save the result. |
| 103 | if matched { |
| 104 | results = append(results, &search.Result{ |
| 105 | Field: "Description", |
| 106 | Content: channelItem.Description, |
| 107 | }) |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return results, nil |
| 112 | } |
| 113 | |
| 114 | // retrieve performs a HTTP Get request for the rss feed and decodes the results. |
| 115 | func (m rssMatcher) retrieve(feed *search.Feed) (*rssDocument, error) { |