Commit f302f7cb by thanhnd

import db and search from solr

parent 586c4a4e
Pipeline #599 failed with stages
in 0 seconds
...@@ -69,4 +69,4 @@ gem 'bootstrap-sass' ...@@ -69,4 +69,4 @@ gem 'bootstrap-sass'
#setting file yml #setting file yml
gem 'settingslogic' gem 'settingslogic'
gem 'rsolr'
...@@ -92,6 +92,8 @@ GEM ...@@ -92,6 +92,8 @@ GEM
warden (~> 1.2.3) warden (~> 1.2.3)
erubi (1.9.0) erubi (1.9.0)
execjs (2.7.0) execjs (2.7.0)
faraday (1.0.1)
multipart-post (>= 1.2, < 3)
ffi (1.12.2) ffi (1.12.2)
globalid (0.4.2) globalid (0.4.2)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
...@@ -135,6 +137,7 @@ GEM ...@@ -135,6 +137,7 @@ GEM
mini_portile2 (2.4.0) mini_portile2 (2.4.0)
minitest (5.14.0) minitest (5.14.0)
msgpack (1.3.3) msgpack (1.3.3)
multipart-post (2.1.1)
mysql2 (0.5.3) mysql2 (0.5.3)
nio4r (2.5.2) nio4r (2.5.2)
nokogiri (1.10.8) nokogiri (1.10.8)
...@@ -183,6 +186,9 @@ GEM ...@@ -183,6 +186,9 @@ GEM
responders (3.0.0) responders (3.0.0)
actionpack (>= 5.0) actionpack (>= 5.0)
railties (>= 5.0) railties (>= 5.0)
rsolr (2.3.0)
builder (>= 2.1.2)
faraday (>= 0.9.0)
ruby_dep (1.5.0) ruby_dep (1.5.0)
rubyzip (2.2.0) rubyzip (2.2.0)
sass-rails (6.0.0) sass-rails (6.0.0)
...@@ -259,6 +265,7 @@ DEPENDENCIES ...@@ -259,6 +265,7 @@ DEPENDENCIES
mysql2 mysql2
puma (~> 4.1) puma (~> 4.1)
rails (~> 6.0.2, >= 6.0.2.1) rails (~> 6.0.2, >= 6.0.2.1)
rsolr
sass-rails (>= 6) sass-rails (>= 6)
selenium-webdriver selenium-webdriver
settingslogic settingslogic
......
...@@ -125,11 +125,13 @@ ul.breadcrumb li a:hover { ...@@ -125,11 +125,13 @@ ul.breadcrumb li a:hover {
font-size: 16px; font-size: 16px;
margin: 4px 2px; margin: 4px 2px;
cursor: pointer; cursor: pointer;
align: center float: right;
} }
.button1 {border-radius: 4px;} .button1 {border-radius: 4px;}
.button2 { .button2 {
background-color: #4CAF50; /* Green */
float: right; float: right;
border-radius: 4px; border-radius: 4px;
display: inline-block;
} }
...@@ -12,7 +12,11 @@ class JobsController < ApplicationController ...@@ -12,7 +12,11 @@ class JobsController < ApplicationController
def search def search
return redirect_to root_path, alert: "Empty field!" if params[:search].blank? return redirect_to root_path, alert: "Empty field!" if params[:search].blank?
@search_job = Job.includes(:city).where("job_name LIKE ?","%#{params[:search]}%") #@search_job = Job.includes(:city).where("job_name LIKE ?","%#{params[:search]}%")
@pagin_job = @search_job.page(params[:page]).per(Settings.page) #@pagin_job = @search_job.page(params[:page]).per(Settings.page)
solr_rs = Solr.new
@search_job = solr_rs.query(params[:search])
  • Do rsolr sử dụng response['response']['docs'] để phân trang nên đoạn này anh gán

    @pagin_job = solr_rs.query(params[:search])

  • fixed

Please register or sign in to reply
@pagin_job = @search_job
end end
end end
<font color="red"><b><label > Job List:</label></b></font> <font color="red"><b><label > Job List:</label></b></font>
<%= paginate @pagin_job %>
<% @pagin_job.each do |job| %> <% @pagin_job.each do |job| %>
<ul> <ul>
<button class="button button2">Favorites</button> <button class="button2">Favorites</button>
<li><%= job.job_name %></li> <li><%= job['job_name'] %></li>
<li><%= job.city.city_name %></li>
<li ><span class="text"><%= job.description %></span></li>
</ul> </ul>
<% end %> <% end %>
<%= paginate @pagin_job %>
\ No newline at end of file
...@@ -10,7 +10,7 @@ module VenjobThanhnd ...@@ -10,7 +10,7 @@ module VenjobThanhnd
class Application < Rails::Application class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version. # Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.0 config.load_defaults 6.0
config.autoload_paths << Rails.root.join("lib")
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers # Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading # -- all .rb files in that directory are automatically loaded after loading
......
require 'rsolr'
class Solr
attr_accessor :response, :solr
def initialize
# Direct connection
@solr = RSolr.connect :url => 'http://localhost:8983/solr/jobs/'
@response = nil
end
# send a request to /select
def query (cond)
  • anh @thanhnd có thể thêm phân trang bằng cách này solr.paginate 1, 10, "select", :params => {:q => "test"}

    method query anh thêm 1 param truyền từ controller qua, lấy cái Settings.page như anh dùng ở commit trước

    Link tài liệu: https://github.com/rsolr/rsolr#pagination-

    Edited by Trịnh Hoàng Phúc
  • fixed

Please register or sign in to reply
response = solr.get 'select', :params => {:q => "job_name:#{cond}"}
response['response']['docs']
end
end
\ No newline at end of file
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