-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this thing is way too fast! only downside is that indexing takes a bit longer, and the search indexes are big (16Gi for 2.7 million records) i have no idea how to properly integrate it in the UI, but it seems promising :^)
- Loading branch information
Showing
8 changed files
with
62 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,3 +119,4 @@ gem "mail", "~> 2.7.1" | |
|
||
gem "prometheus-client", "~> 4.2" | ||
|
||
gem "meilisearch-rails", "~> 0.10.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,35 @@ | ||
class SearchController < ApplicationController | ||
def index | ||
@results = [] | ||
query = params[:q] | ||
return if query.blank? | ||
@query = params[:q] | ||
return if @query.blank? | ||
|
||
@results = [] | ||
@results = if params[:multi_search] == "1" | ||
multi_search_experiment | ||
else | ||
[*Answer.search(@query), *Question.search(@query)] | ||
end | ||
end | ||
|
||
private | ||
|
||
def multi_search_experiment | ||
MeiliSearch::Rails.client.multi_search( | ||
[Answer, Question].map do |klass| | ||
{ | ||
q: @query, | ||
index_uid: klass.name.to_s, | ||
show_ranking_score: true, | ||
} | ||
end | ||
)["results"].flat_map do |h| | ||
model = h["indexUid"].constantize # bad practice! | ||
results = model.find(h["hits"].pluck("id")).map { |r| [r.id.to_s, r] }.to_h | ||
h["hits"].map { |hit| [hit["_rankingScore"], results[hit["id"]]] } | ||
end | ||
.sort_by(&:first) | ||
.reverse | ||
.tap { |results| Rails.logger.debug(results) } | ||
.map(&:last) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
return unless ENV["SEARCH_ENABLED"] == "true" | ||
|
||
MeiliSearch::Rails.configuration = { | ||
meilisearch_url: ENV.fetch("MEILISEARCH_HOST", "http://localhost:7700"), | ||
meilisearch_api_key: ENV.fetch("MEILISEARCH_API_KEY", "justfordev42069e621") | ||
} |