1
0
Fork 0

Use Elasticsearch

This commit is contained in:
Alex Kotov 2020-01-04 07:23:52 +05:00
parent ce8a7ffb20
commit 086f728d04
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
7 changed files with 65 additions and 0 deletions

View file

@ -115,6 +115,12 @@ gem 'kaminari', '~> 1.1'
# This gem is part of the AWS SDK for Ruby. # This gem is part of the AWS SDK for Ruby.
gem 'aws-sdk-s3', require: false gem 'aws-sdk-s3', require: false
# ActiveModel/Record integrations for Elasticsearch.
gem 'elasticsearch-model', '~> 7.0'
# Ruby on Rails integrations for Elasticsearch.
gem 'elasticsearch-rails', '~> 7.0'
group :development, :test do group :development, :test do
# factory_bot provides a framework and DSL for defining and using factories. # factory_bot provides a framework and DSL for defining and using factories.
gem 'factory_bot_rails', '~> 4.10' gem 'factory_bot_rails', '~> 4.10'

View file

@ -168,6 +168,19 @@ GEM
docile (1.3.2) docile (1.3.2)
domain_name (0.5.20190701) domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0) unf (>= 0.0.5, < 1.0.0)
elasticsearch (7.4.0)
elasticsearch-api (= 7.4.0)
elasticsearch-transport (= 7.4.0)
elasticsearch-api (7.4.0)
multi_json
elasticsearch-model (7.0.0)
activesupport (> 3)
elasticsearch (> 1)
hashie
elasticsearch-rails (7.0.0)
elasticsearch-transport (7.4.0)
faraday
multi_json
erubi (1.9.0) erubi (1.9.0)
execjs (2.7.0) execjs (2.7.0)
factory_bot (4.11.1) factory_bot (4.11.1)
@ -476,6 +489,8 @@ DEPENDENCIES
database_cleaner (~> 1.7) database_cleaner (~> 1.7)
devise (~> 4.7) devise (~> 4.7)
devise-i18n (~> 1.8) devise-i18n (~> 1.8)
elasticsearch-model (~> 7.0)
elasticsearch-rails (~> 7.0)
factory_bot_rails (~> 4.10) factory_bot_rails (~> 4.10)
faker (~> 1.8) faker (~> 1.8)
font-awesome-sass (~> 5.5.0) font-awesome-sass (~> 5.5.0)

View file

@ -0,0 +1,10 @@
# frozen_string_literal: true
module Searchable
extend ActiveSupport::Concern
included do
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
end
end

View file

@ -2,9 +2,19 @@
class Person < ApplicationRecord class Person < ApplicationRecord
include Nameable include Nameable
include Searchable
ACCOUNT_CONNECTION_TOKEN_RE = /\A\w+\z/.freeze ACCOUNT_CONNECTION_TOKEN_RE = /\A\w+\z/.freeze
settings index: { number_of_shards: 1 } do
mapping dynamic: false do
indexes :first_name, analyzer: 'russian'
indexes :middle_name, analyzer: 'russian'
indexes :last_name, analyzer: 'russian'
indexes :place_of_birth, analyzer: 'russian'
end
end
################ ################
# Associations # # Associations #
################ ################

View file

@ -17,6 +17,8 @@ require 'sprockets/railtie'
# you've limited to :test, :development, :staging, or :production. # you've limited to :test, :development, :staging, or :production.
Bundler.require(*Rails.groups) Bundler.require(*Rails.groups)
require 'elasticsearch/rails/instrumentation'
require 'csv' require 'csv'
module Partynest module Partynest

View file

@ -0,0 +1,16 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
Elasticsearch::Model.client = Elasticsearch::Client.new(
scheme: :http,
host: '127.0.0.1',
port: 9200,
user: 'elastic',
password: 'changeme',
transport_options: {
request: { timeout: 5 },
ssl: { ca_file: nil },
},
)

View file

@ -0,0 +1,6 @@
# frozen_string_literal: true
require 'elasticsearch/rails/tasks/import'
Rake::Task['elasticsearch:import:all'].prerequisites << :environment
Rake::Task['elasticsearch:import:model'].prerequisites << :environment