Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/algolia/facebook-search
Facebook Feed Search powered by Algolia
https://github.com/algolia/facebook-search
Last synced: about 2 months ago
JSON representation
Facebook Feed Search powered by Algolia
- Host: GitHub
- URL: https://github.com/algolia/facebook-search
- Owner: algolia
- Archived: true
- Created: 2014-04-06T06:02:35.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-21T09:22:50.000Z (over 9 years ago)
- Last Synced: 2024-06-14T21:43:09.393Z (3 months ago)
- Language: Ruby
- Homepage: http://facebooksearch.algolia.com
- Size: 340 KB
- Stars: 12
- Watchers: 89
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
Facebook Search
===============This is the Rails 4 application providing [Facebook Search](http://facebook.algolia.com). It's based on [algoliasearch-client-ruby](https://github.com/algolia/algoliasearch-client-ruby), [omniauth-facebook](https://github.com/mkdynamic/omniauth-facebook) and [koala](https://github.com/arsduo/koala).
Index settings
----------------------```ruby
Algolia.init application_id: ENV['ALGOLIA_APPLICATION_ID'], api_key: ENV['ALGOLIA_API_KEY']
INDEX = Algolia::Index.new("facebook_#{Rails.env}")
INDEX.set_settings({
attributesToIndex: ['unordered(description)', 'unordered(name)', 'unordered(message)', 'unordered(comments.data.message)', 'unordered(story)'],
customRanking: ['desc(likes_count)']
})
```Record definition
------------------```ruby
BATCH_SIZE = 1000
def crawl_feed!(token)
@graph = Koala::Facebook::API.new(token)
objects = []
feed = @graph.get_connections("me", "feed")
loop do
feed.each do |f|
objects << build_algolia_object(f)
if objects.length == BATCH_SIZE
INDEX.add_objects(objects)
objects = []
end
end
feed = feed.next_page
break if feed.nil? || feed.empty?
end
INDEX.add_objects(objects) unless objects.empty?
endprivate
def build_algolia_object(f)
f.merge objectID: "#{uid}_#{f['id']}",
_tags: [ uid, f['type'] ],
created_time: DateTime.parse(f['created_time']).to_i,
likes_count: f['likes'].try(:[], 'data').try(:length).to_i
end
```Secure indexing
----------------Each record (item) is tagged with its owner id (Your Facebook UID) and we use a per-user [generated secured API key](http://www.algolia.com/doc#SecurityUser) to call Algolia's REST API.
```ruby
@secured_api_key = Algolia.generate_secured_api_key(ENV['ALGOLIA_API_KEY_SEARCH_ONLY'], current_user.uid)
``````js
var algolia = new AlgoliaSearch('#{ENV['ALGOLIA_APPLICATION_ID']}', '#{@secured_api_key}');
algolia.setSecurityTags('#{current_user.uid}');
```