Permalink
Browse files

faceted search

  • Loading branch information...
1 parent b42c3ee commit ac3f592aa5859322a97388fefd0d0f92d8d5854e @jlgeering jlgeering committed Mar 17, 2012
Showing with 46 additions and 9 deletions.
  1. +3 −2 Gemfile
  2. +9 −2 Gemfile.lock
  3. +4 −3 app/controllers/articles_controller.rb
  4. +14 −2 app/models/article.rb
  5. +16 −0 app/views/articles/index.html.erb
View
@@ -55,7 +55,8 @@ gem "authlogic"
gem "high_voltage"
# elasticsearch
-gem 'tire'
+gem 'tire', '~> 0.4.0.pre'
+
# pagination
#gem 'will_paginate'
-gem 'kaminari'
+gem 'kaminari'
View
@@ -57,6 +57,7 @@ GEM
rake (>= 0.9.2)
rdoc (~> 3.8)
sax-machine (~> 0.0.20)
+ hashr (0.0.19)
high_voltage (1.1.1)
hike (1.2.1)
i18n (0.6.0)
@@ -65,6 +66,10 @@ GEM
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.6.5)
+ kaminari (0.13.0)
+ actionpack (>= 3.0.0)
+ activesupport (>= 3.0.0)
+ railties (>= 3.0.0)
less (2.0.11)
commonjs (~> 0.2.0)
therubyracer (~> 0.9.9)
@@ -130,8 +135,9 @@ GEM
rack (>= 1.0.0)
thor (0.14.6)
tilt (1.3.3)
- tire (0.3.12)
+ tire (0.4.0.pre)
activemodel (~> 3.0)
+ hashr (~> 0.0.16)
multi_json (~> 1.0)
rake
rest-client (~> 1.6.0)
@@ -157,12 +163,13 @@ DEPENDENCIES
high_voltage
jquery-rails
json
+ kaminari
less-rails
pg
rails (= 3.2.2)
sass-rails (~> 3.2.3)
sqlite3
thin
- tire
+ tire (~> 0.4.0.pre)
twitter-bootstrap-rails
uglifier (>= 1.0.3)
@@ -3,9 +3,10 @@ class ArticlesController < ApplicationController
# GET /articles
# GET /articles.json
def index
- @articles = Article.includes(:feed, :user_articles).where("`user_articles`.user_id = ?", current_user.id).page(params[:page]).per(10)
-
- #@articles = Article.search(params)
+ #@articles = Article.includes(:feed, :user_articles).where("`user_articles`.user_id = ?", current_user.id).page(params[:page]).per(10)
+
+ params[:user_feeds] = current_user.feeds.collect { |item| item.id }
+ @articles = Article.search(params)
respond_to do |format|
format.html # index.html.erb
View
@@ -7,9 +7,21 @@ class Article < ActiveRecord::Base
include Tire::Model::Callbacks
def self.search(params)
- tire.search(load: true) do
- query { string params[:query], default_operator: "AND" } if params[:query].present?
+ tire.search(load: true, page: params[:page], per_page: 10) do
+ #query { string params[:query], default_operator: "AND" } if params[:query].present?
#filter :range, published_at: {lte: Time.zone.now}
+ query do
+ boolean do
+ must { terms :feed_id, params[:user_feeds] } if params[:user_feeds].present?
+ must { string params[:query], default_operator: "AND" } if params[:query].present?
+ #must { range :published_at, lte: Time.zone.now }
+ must { term :feed_id, params[:feed_id] } if params[:feed_id].present?
+ end
+ end if params[:query].present? or params[:feed_id].present? or params[:user_feeds].present?
+ facet "feeds" do
+ terms :feed_id
+ end
+ #raise to_curl
end
end
@@ -5,6 +5,22 @@
</p>
<% end %>
+<div id="facets">
+ <h3>Feeds (Faceted Search)</h3>
+ <ul>
+ <% @articles.facets['feeds']['terms'].each do |facet| %>
+ <li>
+ <%= link_to_unless_current Feed.find(facet['term']).name, params.merge(feed_id: facet['term']) %>
+ <% if params[:feed_id] == facet['term'].to_s %>
+ (<%= link_to "remove", feed_id: nil %>)
+ <% else %>
+ (<%= facet['count'] %>)
+ <% end %>
+ </li>
+ <% end %>
+ </ul>
+</div>
+
<% @articles.each do |article| %>
<div class="article row <%= is_read(article.id,current_user.id) %>" data-article-id="<%= article.id %>">
<div class="article-header" id="<%= article.id %>_header" >

0 comments on commit ac3f592

Please sign in to comment.