Temporarily wire up filtering on the form
This commit is contained in:
@@ -5,6 +5,11 @@ class BubblesController < ApplicationController
|
||||
|
||||
def index
|
||||
@bubbles = @bucket.bubbles.not_popped.reverse_chronologically
|
||||
|
||||
if params[:filter].present?
|
||||
@bubbles = @bubbles.mentioning(params[:filter])
|
||||
end
|
||||
|
||||
@most_active_bubbles = @bubbles.ordered_by_activity.limit(10)
|
||||
|
||||
if params[:tag_id]
|
||||
|
||||
@@ -13,4 +13,13 @@ class Bubble < ApplicationRecord
|
||||
scope :ordered_by_activity, -> { left_joins(:comments, :boosts).group(:id).order(Arel.sql("COUNT(comments.id) + COUNT(boosts.id) DESC")) }
|
||||
|
||||
searchable_by :title, using: :bubbles_search_index
|
||||
|
||||
scope :mentioning, ->(query) do
|
||||
bubbles = search(query).select(:id).to_sql
|
||||
comments = Comment.search(query).select(:bubble_id).to_sql
|
||||
|
||||
left_joins(:comments)
|
||||
.where("bubbles.id in (#{bubbles}) or comments.bubble_id in (#{comments})")
|
||||
.distinct
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ module Searchable
|
||||
after_update_commit :update_in_search_index
|
||||
after_destroy_commit :remove_from_search_index
|
||||
|
||||
scope :search, ->(query) { joins("join #{using} idx on id = idx.rowid").where("idx.#{field} match ?", query) }
|
||||
scope :search, ->(query) { joins("join #{using} idx on #{table_name}.id = idx.rowid").where("idx.#{field} match ?", query) }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -105,7 +105,9 @@
|
||||
|
||||
<section class="bubbles-list unpad-inline center margin-block-start">
|
||||
<header class="flex-inline align-center center gap txt-small">
|
||||
<input type="search" class="input center flex-inline" placeholder="Type to filter…">
|
||||
<form>
|
||||
<input type="search" name="filter" class="input center flex-inline" placeholder="Type to filter…" value="<%= params[:filter] %>">
|
||||
</form>
|
||||
</header>
|
||||
<ul class="unpad margin-none flex flex-column txt-align-start center">
|
||||
<%= render partial: "bubbles/list/bubble", collection: @bubbles %>
|
||||
|
||||
@@ -6,4 +6,12 @@ class BubbleTest < ActiveSupport::TestCase
|
||||
|
||||
assert_includes Bubble.search("haggis"), bubble
|
||||
end
|
||||
|
||||
test "mentioning" do
|
||||
bubble = buckets(:writebook).bubbles.create! title: "Insufficient haggis", creator: users(:kevin)
|
||||
bubbles(:logo).comments.create! body: "I hate haggis", creator: users(:kevin)
|
||||
bubbles(:text).comments.create! body: "I love haggis", creator: users(:kevin)
|
||||
|
||||
assert_equal [ bubble, bubbles(:logo), bubbles(:text) ].sort, Bubble.mentioning("haggis").sort
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user