· 1 min read

Screencast: ElasticSearch Teil 1

Downloads in verschiedenen Formaten:

mp4 m4v webm ogg

Resourcen:

bash

[bash] brew install elasticsearch elasticsearch -f -D es.config=/usr/local/Cellar/elasticsearch/0.18.5/config/elasticsearch.yml rake db:setup [/bash]

Gemfile

[ruby] gem ‘tire’ [/ruby]

articles_controller.rb

[ruby] def index @articles = Article.search(params) end [/ruby]

models/article.rb

[ruby] include Tire::Model::Search include Tire::Model::Callbacks

def self.search(params) tire.search(load: true) do query { string params[:query], default_operator: “AND” } if params[:query].present? filter :range, published_at: {lte: Time.zone.now} end end [/ruby]

articles/index.html.erb

[html] <%= form_tag articles_path, method: :get do %>

<%= text_field_tag :query, params[:query] %> <%= submit_tag “Search”, name: nil %>

<% end %> [/html]

Back to Blog