Created
April 27, 2011 11:44
-
-
Save floere/944113 to your computer and use it in GitHub Desktop.
An example of how to search an RSS feed in Picky.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RssSearch < Application | |
| # Indexing and searching however you need it. | |
| # | |
| indexing removes_characters: /[^a-zA-Z0-9\s\/\-\_\:\"\&\.\|]/i, | |
| stopwords: /\b(and|the|or|on|of|in|is|to|from|as|at|an)\b/i, | |
| splits_text_on: /[\s\/\-\_\:\"\&\/]/, | |
| removes_characters_after_splitting: /[\.]/ | |
| searching removes_characters: /[^a-zA-Z0-9\s\/\-\_\,\&\.\"\~\*\:]/i, | |
| stopwords: /\b(and|the|or|on|of|in|is|to|from|as|at|an)\b/i, | |
| splits_text_on: /[\s\/\,\&\/]/ | |
| # This proxy is only needed as we don't | |
| # want to have the RSS lib load the stream | |
| # every time app/application.rb is | |
| # loaded. | |
| # | |
| class EachRSSItemProxy | |
| def each &block | |
| require 'rss' | |
| require 'open-uri' | |
| rss_feed = "http://florianhanke.com/blog/atom.xml" | |
| rss_content = "" | |
| open rss_feed do |f| | |
| rss_content = f.read | |
| end | |
| rss = RSS::Parser.parse rss_content, true | |
| rss.items.each &block | |
| end | |
| end | |
| # We then create an index with a new #each proxy. | |
| # | |
| # Since the ids are strings, we need to tell | |
| # Picky to use :to_s as key formatter. | |
| # | |
| # Add categories and customize as you wish. | |
| # | |
| rss_index = Index::Memory.new :rss do | |
| source EachRSSItemProxy.new | |
| key_format :to_s | |
| category :title | |
| # etc... | |
| end | |
| route %r{\A/rss\Z} => Search.new(rss_index) | |
| end |
An ElasticSearch example: https://gist.github.com/947437
Thanks a lot :) The one file approach is very appealing to me, a la Sinatra.
On another note I looked at the Slingshot code yesterday evening, and made
a few changes that I thought were beneficial to the code. First accidentally
to the master, then to the activemodel branch (I just merged the master
changes in). The commits are very small, and usually correspond to changes
in a single file, so should be easy to cherry-pick should you just want
certain ones.
Note that those are all suggestions.
…On 29 April 2011 08:30, karmi < ***@***.***>wrote:
An ElasticSearch example: https://gist.github.com/947437
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/944113
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Testing using e.g. RSpec: