diff --git a/Gemfile b/Gemfile index 713eb860..2dfdc64b 100644 --- a/Gemfile +++ b/Gemfile @@ -128,3 +128,6 @@ gem 'harmonious_dictionary', '~> 0.0.1' gem 'parallel', '~> 1.19', '>= 1.19.1' gem 'letter_avatar' + +gem 'elasticsearch-model', github: 'elastic/elasticsearch-rails', branch: 'main' +gem 'elasticsearch-rails', github: 'elastic/elasticsearch-rails', branch: 'main' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index b1dc2cca..3fd2e9e5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,14 @@ +GIT + remote: https://github.com/elastic/elasticsearch-rails.git + revision: b66fe71cc4b9b10069bf6d39dbbfcc0b117a08a5 + branch: main + specs: + elasticsearch-model (7.2.1) + activesupport (> 3) + elasticsearch (~> 7) + hashie + elasticsearch-rails (7.2.1) + GEM remote: https://gems.ruby-china.com/ specs: @@ -450,6 +461,8 @@ DEPENDENCIES chromedriver-helper deep_cloneable (~> 3.0.0) diffy + elasticsearch-model! + elasticsearch-rails! enumerize faraday (~> 0.15.4) font-awesome-sass (= 4.7.0) diff --git a/app/models/project.rb b/app/models/project.rb index 9c77685f..9b75a94f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -79,9 +79,8 @@ # - - class Project < ApplicationRecord + include Elasticsearch::Model include Matchable include Publicable include Watchable diff --git a/config/configuration.yml.example b/config/configuration.yml.example index 61e66635..dcc1c1bf 100644 --- a/config/configuration.yml.example +++ b/config/configuration.yml.example @@ -67,6 +67,11 @@ default: &default domain: '' base_url: '' + es: + url: 'http://localhost:9200' + user: 'elastic' + password: '123456' + production: <<: *default # 中间层地址 diff --git a/config/initializers/elasticsearch_model.rb b/config/initializers/elasticsearch_model.rb new file mode 100644 index 00000000..0e822cfc --- /dev/null +++ b/config/initializers/elasticsearch_model.rb @@ -0,0 +1,8 @@ +require 'elasticsearch/model' + +es_config = Rails.application.config_for(:es) +host_url = es_config["url"] || 'http://localhost:9200/' +user = es_config["user"] || '' +password = es_config["password"] || '' + +Elasticsearch::Model.client = Elasticsearch::Client.new user: user, password: password, host: host_url \ No newline at end of file