17. HTTP CODES
200 OK
201 Created
202 Accepted
400 Bad Request
401 Unauthorized
402 Payment Required
404 Not Found
409 Conflict
422 Unprocessable Entity
500 Internal Server Error
503 Service Unavailable
44. Solr:
SolrTM is the popular, blazing fast open
source enterprise search platform from
the Apache LuceneTMproject. Its major
features include powerful full-text
search, hit highlighting, faceted
search, near real-time indexing,
dynamic clustering, database
integration, rich document (e.g., Word,
PDF) handling, and geospatial search.
45. Sunspot - Solr
• Solr powerful interface
• Expressive DSL
• Easily pluggable in to any ORM
46. Sunspot - Solr
class Post < ActiveRecord::Base
searchable do
text :title, :body
text :comments do
comments.map { |comment| comment.body }
end
boolean :featured
integer :blog_id
integer :expensive_operation
integer :category_ids, :multiple => true
double :average_rating
time :published_at
time :expired_at
string :sort_title do
title.downcase.gsub(/^(an?|the)/, '')
end
end
end
47. Sunspot - Solr
class Post < ActiveRecord::Base
searchable do
text :title, :body
text :comments do
comments.map { |comment| comment.body }
end
boolean :featured
integer :blog_id
integer :expensive_operation
integer :category_ids, :multiple => true
double :average_rating
time :published_at
time :expired_at
string :sort_title do
title.downcase.gsub(/^(an?|the)/, '')
end
end
end
48. Sunspot - Solr
class Post < ActiveRecord::Base
searchable(auto_index: false) do
text :title, :body
text :comments do
comments.map { |comment| comment.body }
end
boolean :featured
integer :blog_id
integer :expensive_operation
integer :category_ids, :multiple => true
double :average_rating
time :published_at
time :expired_at
string :sort_title do
title.downcase.gsub(/^(an?|the)/, '')
end
end
end
49. Sunspot - Solr
Post.search do
fulltext 'best pizza'
with :blog_id, 1
with(:published_at).less_than Time.now
order_by :published_at, :desc
paginate :page => 2, :per_page => 15
facet :category_ids, :author_id
end
50. Sunspot - Solr
• Results
• Contains AR instances
• ‘Lazy’ loading
• Hits
• Solr indexed data
• super fast access
results vs hits
51. Sunspot - Solr
results vs hits
class ResultProxy < ResultHit
def method_missing(method, *args, &block)
begin
hit.instance.send(method)
rescue
hit.stored(method)
end
end
end
52. Sunspot - Solr
results vs hits
class ResultProxy < ResultHit
def method_missing(method, *args, &block)
begin
if setup.stored_fields(method).empty?
hit.instance.send(method)
else
hit.stored(method)
end
rescue
hit.instance.send(sym, *args)
end
end
end
53. Sunspot - Solr
results vs hits
class ResultProxy < ResultHit
def value(of)
hit.stored(of)
end
def has_property? name
!setup.stored_fields(name).empty?
end
end
54. Sunspot - Solr
Associations?
def method_missing method, *args
@solr_instance ||= Search::Collection.new(Program.search { with(:id, id)}).first
if @solr_instance && @solr_instance.has_property?(method)
@solr_instance.value(method)
else
super method, *args
end
end
$ model_active_record = Model.find(id)
$ model_active_record.association.value_stored_in_solr
64. Serializers
#index.rabl
object false
node(:style_search) do
[{
page: @search_results.results.current_page,
total_pages: @search_results.results.total_pages,
per_page: @search_results.results.per_page,
}]
end
node :products do
@search_results.results
end
node :suppliers do
@suppliers
end
node :properties do
@properties
end
GET /api/products #List
Ideal for real world
67. Modern Web 2.0
Problems
Logo Login Info
Profile Info
Login Info
Menu
List of items with edit options
FooterFooterFooter
68. Modern Web 2.0
Problems
Logo Currently selected Login Info
Profile Info
Login Info
Menu
List of items with edit options TopViewed
FooterFooterFooter
81. EmberJS - Router
• EmberJS way to manage states
• Each state is represented by a URL
• User interaction causes URL to change
• redirected to a new URL
• Updates controller
• Change template screen
85. EmberJS - Controllers
• Designed to decorate models
• display logic
• Properties frontend specific
• they don’t need to be saved
• Decorates data
• Bridge between your data and your
86. EmberJS - Controllers
App.ApplicationController = Ember.Controller.extend({
// the initial value of the `search` property
search: '',
query: function() {
// the current value of the text field
var query = this.get('search');
this.transitionToRoute('search', { query: query });
}
});
94. EmberJS - Templates
• Handlebars is used as template engine
• regular HTML with embedded handlebar
expressions
• Minimal Templating on Steroids
• Emblem.js if you are haml lover