Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Litesearch POC #58

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/controllers/talks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ class TalksController < ApplicationController
def index
session[:talks_page] = params[:page] || 1
if params[:q].present?
talks = Talk.includes(:speakers, :event).pagy_search(params[:q])
@pagy, @talks = pagy_meilisearch(talks, items: 9, page: session[:talks_page]&.to_i || 1)
@pagy, @talks = pagy(Talk.search(params[:q]).all.order(date: :desc).includes(:speakers, :event), items: 9, page: session[:talks_page]&.to_i || 1)
else
@pagy, @talks = pagy(Talk.all.order(date: :desc).includes(:speakers, :event), items: 9, page: session[:talks_page]&.to_i || 1)
end
Expand Down
31 changes: 5 additions & 26 deletions app/models/talk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ class Talk < ApplicationRecord
include Sluggable
include Suggestable
slug_from :title
include MeiliSearch::Rails
ActiveRecord_Relation.include Pagy::Meilisearch
extend Pagy::Meilisearch
include Litesearch::Model

# associations
belongs_to :event, optional: true
Expand All @@ -43,32 +41,13 @@ class Talk < ApplicationRecord
delegate :name, to: :event, prefix: true, allow_nil: true

# search
meilisearch do
attribute :title
attribute :description
attribute :slug
attribute :video_id
attribute :video_provider
attribute :thumbnail_sm
attribute :thumbnail_md
attribute :thumbnail_lg
attribute :speaker_names do
speakers.pluck(:name)
end
attribute :event_name do
event_name
end
searchable_attributes [:title, :description, :speaker_names, :event_name]
sortable_attributes [:title]

attributes_to_highlight ["*"]
litesearch do |schema|
schema.field :title, weight: 3
schema.field :description
schema.tokenizer :trigram
end

meilisearch enqueue: true

# ensure that during the reindex process the associated records are eager loaded
scope :meilisearch_import, -> { includes(:speakers, :event) }

def to_meta_tags
{
title: title,
Expand Down