enable elasticsearch && add elasticsearch config

dev_forum
p31729568 5 years ago
parent e132593ce7
commit 4e8f18a30b

1
.gitignore vendored

@ -44,6 +44,7 @@
/config/secrets.yml /config/secrets.yml
/config/redis.yml /config/redis.yml
/config/elasticsearch.yml
public/upload.html public/upload.html
/config/configuration.yml /config/configuration.yml

@ -90,4 +90,4 @@ gem 'sinatra'
gem 'bulk_insert' gem 'bulk_insert'
# elasticsearch # elasticsearch
# gem 'searchkick' gem 'searchkick'

@ -90,6 +90,14 @@ GEM
connection_pool (2.2.2) connection_pool (2.2.2)
crass (1.0.4) crass (1.0.4)
diff-lcs (1.3) diff-lcs (1.3)
elasticsearch (7.2.0)
elasticsearch-api (= 7.2.0)
elasticsearch-transport (= 7.2.0)
elasticsearch-api (7.2.0)
multi_json
elasticsearch-transport (7.2.0)
faraday
multi_json
erubi (1.7.1) erubi (1.7.1)
execjs (2.7.0) execjs (2.7.0)
faraday (0.15.4) faraday (0.15.4)
@ -100,6 +108,7 @@ GEM
grape-entity (0.7.1) grape-entity (0.7.1)
activesupport (>= 4.0) activesupport (>= 4.0)
multi_json (>= 1.3.2) multi_json (>= 1.3.2)
hashie (3.6.0)
htmlentities (4.3.4) htmlentities (4.3.4)
httparty (0.16.2) httparty (0.16.2)
multi_xml (>= 0.5.2) multi_xml (>= 0.5.2)
@ -255,6 +264,10 @@ GEM
sprockets (>= 2.8, < 4.0) sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0) sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3) tilt (>= 1.1, < 3)
searchkick (3.1.3)
activemodel (>= 4.2)
elasticsearch (>= 5)
hashie
selenium-webdriver (3.14.0) selenium-webdriver (3.14.0)
childprocess (~> 0.5) childprocess (~> 0.5)
rubyzip (~> 1.2) rubyzip (~> 1.2)
@ -344,6 +357,7 @@ DEPENDENCIES
ruby-ole ruby-ole
rubyzip rubyzip
sass-rails (~> 5.0) sass-rails (~> 5.0)
searchkick
selenium-webdriver selenium-webdriver
sidekiq sidekiq
simple_xlsx_reader simple_xlsx_reader

@ -1,6 +1,5 @@
class ChallengeTag < ApplicationRecord class ChallengeTag < ApplicationRecord
# TODO: ES feature include Searchable::Dependents::ChallengeTag
# include Searchable::Dependents::ChallengeTag
belongs_to :challenge, counter_cache: true belongs_to :challenge, counter_cache: true
belongs_to :challenge_choose, optional: true belongs_to :challenge_choose, optional: true

@ -1,6 +1,5 @@
class Course < ApplicationRecord class Course < ApplicationRecord
# TODO: ES feature include Searchable::Course
# include Searchable::Course
has_many :boards, dependent: :destroy has_many :boards, dependent: :destroy

@ -1,6 +1,5 @@
class Memo < ApplicationRecord class Memo < ApplicationRecord
# TODO: ES feature include Searchable::Memo
# include Searchable::Memo
has_many :memo_tag_repertoires, :dependent => :destroy has_many :memo_tag_repertoires, :dependent => :destroy
has_many :tag_repertoires, :through => :memo_tag_repertoires has_many :tag_repertoires, :through => :memo_tag_repertoires

@ -26,6 +26,7 @@ module Searchable::Memo
{ {
descendants_contents: Util.map_or_pluck(descendants, :content) descendants_contents: Util.map_or_pluck(descendants, :content)
.map { |content| Util.extract_content(content)[0..Searchable::MAXIMUM_LENGTH] } .map { |content| Util.extract_content(content)[0..Searchable::MAXIMUM_LENGTH] }
.join('<br/>')
} }
end end

@ -31,7 +31,7 @@ module Searchable::Shixun
.each_with_index.map { |subject, index| "#{index + 1}#{subject}" } .each_with_index.map { |subject, index| "#{index + 1}#{subject}" }
{ {
challenge_names: challenge_names, challenge_names: challenge_names.join(' '),
challenge_tag_names: Util.map_or_pluck(challenge_tags, :name).uniq.join(' ') challenge_tag_names: Util.map_or_pluck(challenge_tags, :name).uniq.join(' ')
} }
end end

@ -31,15 +31,9 @@ module Searchable::Subject
end end
def searchable_stages_data def searchable_stages_data
subject_stages = subject_stages = stages.map { |stage| "#{stage.name} #{Util.extract_content(stage.description)}"[0..Searchable::MAXIMUM_LENGTH] }
stages.map do |stage|
{
name: stage.name,
description: Util.extract_content(stage.description)[0..Searchable::MAXIMUM_LENGTH]
}
end
{ subject_stages: subject_stages} { subject_stages: subject_stages.join('<br/>') }
end end
def to_searchable_json def to_searchable_json

@ -1,6 +1,5 @@
class Shixun < ApplicationRecord class Shixun < ApplicationRecord
# TODO: ES feature include Searchable::Shixun
# include Searchable::Shixun
# status: 0编辑 1申请发布 2正式发布 3关闭 -1软删除 # status: 0编辑 1申请发布 2正式发布 3关闭 -1软删除
# hide_code 隐藏代码窗口 # hide_code 隐藏代码窗口

@ -1,6 +1,5 @@
class Stage < ApplicationRecord class Stage < ApplicationRecord
# TODO: ES feature include Searchable::Dependents::Stage
# include Searchable::Dependents::Stage
belongs_to :subject, counter_cache: true belongs_to :subject, counter_cache: true

@ -2,8 +2,7 @@
# 可以在初始创建的时候 # 可以在初始创建的时候
class Subject < ApplicationRecord class Subject < ApplicationRecord
# TODO: ES feature include Searchable::Subject
# include Searchable::Subject
#status :0 编辑中 1 审核中 2 发布 #status :0 编辑中 1 审核中 2 发布
belongs_to :repertoire belongs_to :repertoire

@ -1,7 +1,6 @@
class User < ApplicationRecord class User < ApplicationRecord
include Watchable include Watchable
# TODO: ES feature include Searchable::Dependents::User
# include Searchable::Dependents::User
# Account statuses # Account statuses
STATUS_ANONYMOUS = 0 STATUS_ANONYMOUS = 0

@ -0,0 +1,13 @@
defaults: &defaults
url: http://localhost:9200
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
url: 'http://elastic:Elas+ucloud123@106.75.27.125:59200/'
# url: 'http://elastic:TEST_elastickibana321@es-cn-0pp174wsj000iubdx.public.elasticsearch.aliyuncs.com'

@ -0,0 +1,2 @@
redis_config = Rails.application.config_for(:elasticsearch)
ENV['ELASTICSEARCH_URL'] = redis_config['url']
Loading…
Cancel
Save