· 1 min read
Screencast: ElasticSearch Teil 1
Downloads in verschiedenen Formaten:
Resourcen:
- elasticsearch
- Tire
- Tire Annotated Source
- Episode 120: Thinking Sphinx (revised)
- Episode 278: Searching with Sunspot
- Episode 307: ElasticSearch Part 2 (pro)
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]