Commit 3873645b by Hoang Phuc Do

Import data to Solr

parent 887f6cb4
...@@ -22,4 +22,7 @@ ...@@ -22,4 +22,7 @@
/public/uploads/* /public/uploads/*
# Ignore database config file # Ignore database config file
/config/database.yml /config/database.yml
\ No newline at end of file config/settings.local.yml
config/settings/*.local.yml
config/environments/*.local.yml
...@@ -36,6 +36,8 @@ gem 'carrierwave', '~> 1.0' ...@@ -36,6 +36,8 @@ gem 'carrierwave', '~> 1.0'
gem 'mini_magick' gem 'mini_magick'
# bootstrap-sass is a Sass-powered version of Bootstrap 3 # bootstrap-sass is a Sass-powered version of Bootstrap 3
gem 'bootstrap-sass', '~> 3.3.6' gem 'bootstrap-sass', '~> 3.3.6'
# Easiest way to manage multi-environment settings in any ruby project or framework: Rails, Sinatra, Pandrino and others
gem 'config'
# Faker, a port of Data::Faker from Perl, is used to easily generate fake data: names, addresses, phone numbers, etc. # Faker, a port of Data::Faker from Perl, is used to easily generate fake data: names, addresses, phone numbers, etc.
gem 'faker', '~> 1.6', '>= 1.6.3' gem 'faker', '~> 1.6', '>= 1.6.3'
# Kaminari is a Scope & Engine based, clean, powerful, agnostic, customizable and sophisticated paginator for Rails 4+ # Kaminari is a Scope & Engine based, clean, powerful, agnostic, customizable and sophisticated paginator for Rails 4+
...@@ -54,6 +56,8 @@ gem 'rails-assets-bootstrap-touchspin', source: 'https://rails-assets.org' ...@@ -54,6 +56,8 @@ gem 'rails-assets-bootstrap-touchspin', source: 'https://rails-assets.org'
gem 'sidekiq', '~> 5.0', '>= 5.0.2' gem 'sidekiq', '~> 5.0', '>= 5.0.2'
# Toastr: Simple javascript toast notifications, plugged into the rails asset pipeline. # Toastr: Simple javascript toast notifications, plugged into the rails asset pipeline.
gem 'toastr-rails', '~> 1.0', '>= 1.0.3' gem 'toastr-rails', '~> 1.0', '>= 1.0.3'
# RSolr aims to provide a simple and extensible library for working with Solr
gem 'rsolr', '~> 2.0', '>= 2.0.2'
# Use Capistrano for deployment # Use Capistrano for deployment
# gem 'capistrano-rails', group: :development # gem 'capistrano-rails', group: :development
......
...@@ -73,7 +73,11 @@ GEM ...@@ -73,7 +73,11 @@ GEM
execjs execjs
coffee-script-source (1.12.2) coffee-script-source (1.12.2)
concurrent-ruby (1.0.5) concurrent-ruby (1.0.5)
config (1.4.0)
activesupport (>= 3.0)
deep_merge (~> 1.1.1)
connection_pool (2.2.1) connection_pool (2.2.1)
deep_merge (1.1.1)
devise (4.3.0) devise (4.3.0)
bcrypt (~> 3.0) bcrypt (~> 3.0)
orm_adapter (~> 0.1) orm_adapter (~> 0.1)
...@@ -84,6 +88,8 @@ GEM ...@@ -84,6 +88,8 @@ GEM
execjs (2.7.0) execjs (2.7.0)
faker (1.6.6) faker (1.6.6)
i18n (~> 0.5) i18n (~> 0.5)
faraday (0.12.1)
multipart-post (>= 1.2, < 3)
ffi (1.9.18) ffi (1.9.18)
font-awesome-rails (4.7.0.2) font-awesome-rails (4.7.0.2)
railties (>= 3.2, < 5.2) railties (>= 3.2, < 5.2)
...@@ -129,6 +135,7 @@ GEM ...@@ -129,6 +135,7 @@ GEM
mini_portile2 (2.2.0) mini_portile2 (2.2.0)
minitest (5.10.2) minitest (5.10.2)
multi_json (1.12.1) multi_json (1.12.1)
multipart-post (2.0.0)
mysql2 (0.4.6) mysql2 (0.4.6)
nio4r (2.1.0) nio4r (2.1.0)
nokogiri (1.8.0) nokogiri (1.8.0)
...@@ -184,6 +191,9 @@ GEM ...@@ -184,6 +191,9 @@ GEM
responders (2.4.0) responders (2.4.0)
actionpack (>= 4.2.0, < 5.3) actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3) railties (>= 4.2.0, < 5.3)
rsolr (2.0.2)
builder (>= 2.1.2)
faraday
rubocop (0.49.1) rubocop (0.49.1)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0) parser (>= 2.3.3.1, < 3.0)
...@@ -258,6 +268,7 @@ DEPENDENCIES ...@@ -258,6 +268,7 @@ DEPENDENCIES
capybara (~> 2.13) capybara (~> 2.13)
carrierwave (~> 1.0) carrierwave (~> 1.0)
coffee-rails (~> 4.2) coffee-rails (~> 4.2)
config
devise (~> 4.3) devise (~> 4.3)
faker (~> 1.6, >= 1.6.3) faker (~> 1.6, >= 1.6.3)
font-awesome-rails (~> 4.7, >= 4.7.0.2) font-awesome-rails (~> 4.7, >= 4.7.0.2)
...@@ -271,6 +282,7 @@ DEPENDENCIES ...@@ -271,6 +282,7 @@ DEPENDENCIES
puma (~> 3.7) puma (~> 3.7)
rails (~> 5.1.1) rails (~> 5.1.1)
rails-assets-bootstrap-touchspin! rails-assets-bootstrap-touchspin!
rsolr (~> 2.0, >= 2.0.2)
rubocop (~> 0.49.1) rubocop (~> 0.49.1)
sass-rails (~> 5.0) sass-rails (~> 5.0)
selenium-webdriver selenium-webdriver
......
require 'rsolr'
class SolrSearch
attr_accessor :rsolr
def initialize
@rsolr = RSolr.connect url: Settings.rsolr.address
end
end
\ No newline at end of file
Config.setup do |config|
# Name of the constant exposing loaded settings
config.const_name = 'Settings'
# Ability to remove elements of the array set in earlier loaded settings file. For example value: '--'.
#
# config.knockout_prefix = nil
# Overwrite arrays found in previously loaded settings file. When set to `false`, arrays will be merged.
#
# config.overwrite_arrays = true
# Load environment variables from the `ENV` object and override any settings defined in files.
#
# config.use_env = false
# Define ENV variable prefix deciding which variables to load into config.
#
# config.env_prefix = 'Settings'
# What string to use as level separator for settings loaded from ENV variables. Default value of '.' works well
# with Heroku, but you might want to change it for example for '__' to easy override settings from command line, where
# using dots in variable names might not be allowed (eg. Bash).
#
# config.env_separator = '.'
# Ability to process variables names:
# * nil - no change
# * :downcase - convert to lower case
#
# config.env_converter = :downcase
# Parse numeric values as integers instead of strings.
#
# config.env_parse_values = true
end
# RSolr
rsolr:
address: http://localhost:8983/solr/dhp_venshop
\ No newline at end of file
namespace :import_solr_data do
desc "Import product data from database"
task product: :environment do
documents = []
Product.all.each do |product|
documents << { id: product.id, title: product.title, price: product.price }
end
solr_search = SolrSearch.new
solr_search.rsolr.add documents
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment