Commit 4471d916 by Hoang Nam Nguyen

'finish search solr and fix bootstrap'

parent 91e3d553
......@@ -5,7 +5,8 @@ git_source(:github) do |repo_name|
"https://github.com/#{repo_name}.git"
end
gem 'will_paginate', '3.1.5'
gem 'kaminari'
gem 'bootstrap4-kaminari-views'
gem 'bootstrap-will_paginate', '1.0.0'
gem 'rubyzip', '>= 1.0.0' # will load new rubyzip version
gem 'zip-zip' # will load compatibility for old rubyzip API.
......
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
......@@ -648,7 +648,7 @@ pre code {
.no-gutters {
margin-right: 0;
margin-left: 0;
margin-left: 10%;
}
.no-gutters > .col,
......@@ -4322,6 +4322,7 @@ tbody.collapse.show {
padding: 0.75rem 1.25rem;
margin-bottom: -1px;
background-color: #fff;
border: 1px solid rgba(0, 0, 0, 0.125);
}
......
/* header */
// /* header */
#logo {
width: 35%;
}
#distance {
margin-top: 10%;
width: 130%;
.distance {
border-radius: 25px;
width: 30%;
}
#slidebar {
padding-right: 5%;
.slide {
float: right;
}
#slide {
padding-left: 32%;
}
.container-fluid {
background-color: white;
}
/* content */
#image_height {
width: 99.5%;
}
// /* content */
#fontwords {
margin-top: 5%;
padding-left: 34%
}
#search_button {
margin-top: 30px;
margin-left: 3%;
}
#search_box {
width: 88%;
margin-top: 30px;
text-align: center;
}
.line_job {
margin-left: -17%;
margin-top: 5%;
font-size: 220%;
}
.jobs {
width: 125%;
margin-left: 2.5%;
margin: 3% 0% 2% -17%;
}
.detail_description {
font-size: 80%;
margin-left: 2%;
}
.cities {
margin-left: 2%;
border: 1px solid rgba(0, 0, 0, 0.125);
}
.titlejob{
width: 50%;
margin-left: -3%;
}
.total_jobs {
margin: -5% 0% 0% 30%;
font-size: 80%;
margin-left: 30%;
margin-top: -5%;
}
.column_set {
......@@ -78,16 +41,13 @@
}
#cities_button {
margin-left: 83%;
margin-bottom: 3%;
margin-top: 3%;
margin: 3% 0% 3% 80%;
}
#industries_button{
margin-bottom: 3%;
margin-top: 3%;
margin-left: 89.7%;
margin: 3% 0% 3% 89.5%;
}
.content_job {
margin-top: -1.5%;
}
......@@ -97,7 +57,10 @@
margin-top: 5%;
}
/* city list */
.titlejob {
margin-left: -3%
}
// /* city list */
.ct_local {
width: 100%;
......@@ -109,6 +72,13 @@
margin-left: 24%;
}
#viet_nam_city{
margin_left: 10%;
/* search list */
.search_list {
border: 1px solid rgba(0, 0, 0, 0.125);
margin: 3% 0% 3% 0%;
}
.search_list_jobs_title {
padding: 0.5% 0% 0% 1%;
}
\ No newline at end of file
// Place all the styles related to the Search controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class SearchController < ApplicationController
def index
@jobs = ::Kaminari.paginate_array(Solr.test_solr(params[:s])[0]).page(params[:page]).per(20) unless params[:s].nil?
@total_result = Solr.test_solr(params[:s])[1]
@total_jobs = Job.count
end
end
module SearchHelper
end
<%# Link to the "Last" page
- available local variables
url: url to the last page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="last">
<%= link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, remote: remote %>
</span>
<%# Link to the "Next" page
- available local variables
url: url to the next page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="next">
<%= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, rel: 'next', remote: remote %>
</span>
<%# Link showing page number
- available local variables
page: a page object for "this" page
url: url to this page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="page<%= ' current' if page.current? %>">
<%= link_to_unless page.current?, page, url, {remote: remote, rel: page.rel} %>
</span>
<%# The container tag
- available local variables
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
paginator: the paginator that renders the pagination tags inside
-%>
<%= paginator.render do -%>
<nav class="pagination">
<%= first_page_tag unless current_page.first? %>
<%= prev_page_tag unless current_page.first? %>
<% each_page do |page| -%>
<% if page.display_tag? -%>
<%= page_tag page %>
<% elsif !page.was_truncated? -%>
<%= gap_tag %>
<% end -%>
<% end -%>
<% unless current_page.out_of_range? %>
<%= next_page_tag unless current_page.last? %>
<%= last_page_tag unless current_page.last? %>
<% end %>
</nav>
<% end -%>
<%# Link to the "Previous" page
- available local variables
url: url to the previous page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="prev">
<%= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, rel: 'prev', remote: remote %>
</span>
<%# Link to the "First" page
- available local variables
url: url to the first page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="first">
<%= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, remote: remote %>
</span>
<%# Non-link tag that stands for skipped pages...
- available local variables
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="page gap"><%= t('views.pagination.truncate').html_safe %></span>
<%# Link to the "Last" page
- available local variables
url: url to the last page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="last">
<%= link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, remote: remote %>
</span>
<%# Link to the "Next" page
- available local variables
url: url to the next page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="next">
<%= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, rel: 'next', remote: remote %>
</span>
<%# Link showing page number
- available local variables
page: a page object for "this" page
url: url to this page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="page<%= ' current' if page.current? %>">
<%= link_to_unless page.current?, page, url, {remote: remote, rel: page.rel} %>
</span>
<%# The container tag
- available local variables
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
paginator: the paginator that renders the pagination tags inside
-%>
<%= paginator.render do -%>
<nav class="pagination">
<%= first_page_tag unless current_page.first? %>
<%= prev_page_tag unless current_page.first? %>
<% each_page do |page| -%>
<% if page.display_tag? -%>
<%= page_tag page %>
<% elsif !page.was_truncated? -%>
<%= gap_tag %>
<% end -%>
<% end -%>
<% unless current_page.out_of_range? %>
<%= next_page_tag unless current_page.last? %>
<%= last_page_tag unless current_page.last? %>
<% end %>
</nav>
<% end -%>
<%# Link to the "Previous" page
- available local variables
url: url to the previous page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="prev">
<%= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, rel: 'prev', remote: remote %>
</span>
<nav class="navbar navbar-light bg-faded">
<div class="container-fluid">
<div class="navbar-header">
<a href="http://zigexn.vn">
<%= image_tag("logo.png", class: "navbar-brand", id: "logo") %>
</a>
</div>
<ul class="nav navbar-nav" id="slide">
<li><button type="button" class="btn btn-info" id="distance">Login</button></li>
<li><button type="button" class="btn btn-info" id="distance">Favorite</button></li>
<div class="row">
<div class="col">
<a class="navbar-brand" href="http://zigexn.vn">
<%= image_tag("logo.png", class: "navbar-brand", id: "logo") %>
</a>
</div>
<div class="col-6 col-md-4">
<ul class="nav navbar-nav" >
<li><button type="button" class="btn btn-info distance mt-4 slide" >Login</button></li>
<li><button type="button" class="btn btn-info distance mt-1 slide" >Favorite</button></li>
</ul>
<ul class="nav navbar-nav navbar-right" id="slidebar">
<li><button type="button" class="btn btn-info" id="distance">Register</button></li>
<li><button type="button" class="btn btn-info" id="distance">History</button></li>
</div>
<div class="col-6 col-md-4">
<ul class="nav navbar-nav" id="slidebar">
<li><button type="button" class="btn btn-info distance mt-4 no-gutters">Register</button></li>
<li><button type="button" class="btn btn-info distance mt-1 no-gutters">History</button></li>
</ul>
</div>
</nav>
</div>
<div class="search_list titlejob">
<a href="#" class="search_list_jobs_title">
<%= job['job_name'].join(',') %>
</a>
<% if job['short_description'] != nil %>
<li class="detail_description">
<%= truncate job['short_description'].join(',') ,length: 200%>
<%= link_to 'read more', '#'%></li>
</li>
<% end %>
<div class="row ml-0">
<li class="detail_description">
<%= job['city_name'].join(',') %>
</li>
<% if job['salary'] != nil %>
<li class=" detail_description float-right">
<%= job['salary'].join(',') %>
</li>
<% end -%>
</div>
</div>
\ No newline at end of file
<%= form_tag search_index_path, method: :get do %>
<div class="row search_field">
<%= search_field_tag 's', nil, placeholder: 'Search...', class: 'col-10 form-control' %>
<%= submit_tag 'Search',id: "search_button", class: 'col-1 btn btn-success form-control' %>
</div>
<% end %>
<div class="row mt-4">
<h4 class="text-success col-3">Total: <%= @total_jobs %></h4>
<h4 class="text-success col-3">Result for: <%= @total_result%> </h4>
</div>
<div class="mt-4">
<%= paginate @jobs,theme: 'twitter-bootstrap-4'%>
<%= render partial: "search",collection: @jobs, as: :job %>
<%= paginate @jobs,theme: 'twitter-bootstrap-4'%>
</div>
\ No newline at end of file
<div class="jobs list-group-item">
<div class="w-100 list-group-item">
<%= render partial: "job",collection: @jobs, as: :job %>
</div>
\ No newline at end of file
......@@ -3,10 +3,11 @@
<%= job.job_title %>
</p>
</a>
<div class="content_job">
<li class="detail_description"><%= truncate job.short_description,length: 160%>
<% if job.short_description != nil %>
<li class="detail_description"><%= truncate job.short_description,length: 160%>
<%= link_to 'read more', '#' %></li>
<% end %>
<li class="detail_description"> <%= job.salary %></li>
<% job.cities.each do |city| %>
<li class="detail_description"><%= city.location %></li>
......
<p class="text-success line_job">City List</p>
<h1 class="text-success line_job">City List</h1>
<div class="ct_local">
<%= link_to "Viet Nam", '#' , id: "viet_nam_city" , class: "ct_local_font" %>
<%= link_to "International", '#', id: "international_city", class: "ct_local_font" %>
</div>
<p class="text-success line_job">Viet Nam</p>
<h1 class="text-success line_job">Viet Nam</h1>
<div class="row">
<%= render partial: "city_list",collection: @vn_cities, as: :city %>
</div>
<p class="text-success line_job">International</p>
<h1 class="text-success line_job">International</h1>
<div class="row">
<%= render partial: "city_list",collection: @international_cities, as: :city %>
</div>
\ No newline at end of file
<p class="text-success line_job">Industry List</p>
<h1 class="text-success line_job">Industry List</h1>
<div class="row">
<%= render partial: "industry_list", collection: @industries_page, as: :industry %>
</div>
<%= image_tag("home_page.jpg", id: "image_height") %>
<%= image_tag("home_page.jpg", id: "image_height", class: "col-md-12 padding-0") %>
<div class="row">
<div class="col">
<h1 id="fontwords">Total jobs: <em> <%= @total_job %> </em>job</h1>
<h1 id="fontwords" class="mt-5">Total jobs: <em> <%= @total_job %> </em>job</h1>
</div>
</div>
<div class="row">
<input type="text" name="search" placeholder="Search...." id="search_box">
<button type="button" class="btn btn-success" id="search_button">Search</button>
</div>
<%= form_tag search_index_path, method: :get do %>
<div class="row search_field mt-3">
<%= search_field_tag 's', nil, placeholder: 'Search...', class: 'col-10 form-control' %>
<%= submit_tag 'Search', class: 'col-1 btn btn-success form-control ml-4' %>
</div>
<% end %>
<p class="text-success line_job"> Latest Jobs</p>
<h1 class="text-success line_job"> Latest Jobs</h1>
<div class="row">
<%= render 'index' %>
</div>
<p class="text-success line_job">Top Cities</p>
<h1 class="text-success line_job">Top Cities</h1>
<div class="cities">
<%= render 'cities' %>
</div>
<p class="text-success line_job">Top Industry</p>
<h1 class="text-success line_job">Top Industry</h1>
<div class="row cities">
<%= render 'industries' %>
</div>
\ No newline at end of file
......@@ -10,6 +10,7 @@ module VenJob
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
config.eager_load_paths += %W(#{config.root}/lib)
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
......
......@@ -7,4 +7,5 @@ Rails.application.routes.draw do
get 'top_pages/top_page'
get 'top_pages/jobs'
root 'top_pages#top_page'
resources :search, only: :index
end
......@@ -16,7 +16,7 @@ ActiveRecord::Schema.define(version: 20170914072404) do
t.string "location"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "is_vietnam"
t.boolean "city_type"
t.integer "job_cities_count", default: 0
end
......
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if [[ $EUID -ne 0 ]]; then
echo -e "\nERROR: This script must be run as root\n" 1>&2
exit 1
fi
print_usage() {
ERROR_MSG="$1"
if [ "$ERROR_MSG" != "" ]; then
echo -e "\nERROR: $ERROR_MSG\n" 1>&2
fi
echo ""
echo "Usage: install_solr_service.sh <path_to_solr_distribution_archive> [OPTIONS]"
echo ""
echo " The first argument to the script must be a path to a Solr distribution archive, such as solr-5.0.0.tgz"
echo " (only .tgz or .zip are supported formats for the archive)"
echo ""
echo " Supported OPTIONS include:"
echo ""
echo " -d Directory for live / writable Solr files, such as logs, pid files, and index data; defaults to /var/solr"
echo ""
echo " -i Directory to extract the Solr installation archive; defaults to /opt/"
echo " The specified path must exist prior to using this script."
echo ""
echo " -p Port Solr should bind to; default is 8983"
echo ""
echo " -s Service name; defaults to solr"
echo ""
echo " -u User to own the Solr files and run the Solr process as; defaults to solr"
echo " This script will create the specified user account if it does not exist."
echo ""
echo " -f Upgrade Solr. Overwrite symlink and init script of previous installation."
echo ""
echo " -n Do not start Solr service after install, and do not abort on missing Java"
echo ""
echo " NOTE: Must be run as the root user"
echo ""
} # end print_usage
print_error() {
echo $1
exit 1
}
# Locate *NIX distribution by looking for match from various detection strategies
# We start with /etc/os-release, as this will also work for Docker containers
for command in "grep -E \"^NAME=\" /etc/os-release" \
"lsb_release -i" \
"cat /proc/version" \
"uname -a" ; do
distro_string=$(eval $command 2>/dev/null)
unset distro
if [[ ${distro_string,,} == *"debian"* ]]; then
distro=Debian
elif [[ ${distro_string,,} == *"red hat"* ]]; then
distro=RedHat
elif [[ ${distro_string,,} == *"centos"* ]]; then
distro=CentOS
elif [[ ${distro_string,,} == *"ubuntu"* ]]; then
distro=Ubuntu
elif [[ ${distro_string,,} == *"suse"* ]]; then
distro=SUSE
elif [[ ${distro_string,,} == *"darwin"* ]]; then
echo "Sorry, this script does not support macOS. You'll need to setup Solr as a service manually using the documentation provided in the Solr Reference Guide."
echo "You could also try installing via Homebrew (http://brew.sh/), e.g. brew install solr"
exit 1
fi
if [[ $distro ]] ; then break ; fi
done
if [[ ! $distro ]] ; then
echo -e "\nERROR: Unable to auto-detect your *NIX distribution!\nYou'll need to setup Solr as a service manually using the documentation provided in the Solr Reference Guide.\n" 1>&2
exit 1
fi
if [ -z "$1" ]; then
print_usage "Must specify the path to the Solr installation archive, such as solr-5.0.0.tgz"
exit 1
fi
SOLR_ARCHIVE=$1
if [ ! -f "$SOLR_ARCHIVE" ]; then
print_usage "Specified Solr installation archive $SOLR_ARCHIVE not found!"
exit 1
fi
# strip off path info
SOLR_INSTALL_FILE=${SOLR_ARCHIVE##*/}
is_tar=true
if [ ${SOLR_INSTALL_FILE: -4} == ".tgz" ]; then
SOLR_DIR=${SOLR_INSTALL_FILE%.tgz}
elif [ ${SOLR_INSTALL_FILE: -4} == ".zip" ]; then
SOLR_DIR=${SOLR_INSTALL_FILE%.zip}
is_tar=false
else
print_usage "Solr installation archive $SOLR_ARCHIVE is invalid, expected a .tgz or .zip file!"
exit 1
fi
SOLR_START=true
if [ $# -gt 1 ]; then
shift
while true; do
case $1 in
-i)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "Directory path is required when using the $1 option!"
exit 1
fi
SOLR_EXTRACT_DIR=$2
shift 2
;;
-d)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "Directory path is required when using the $1 option!"
exit 1
fi
SOLR_VAR_DIR="$2"
shift 2
;;
-u)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "Username is required when using the $1 option!"
exit 1
fi
SOLR_USER="$2"
shift 2
;;
-s)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "Service name is required when using the $1 option!"
exit 1
fi
SOLR_SERVICE="$2"
shift 2
;;
-p)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "Port is required when using the $1 option!"
exit 1
fi
SOLR_PORT="$2"
shift 2
;;
-f)
SOLR_UPGRADE="YES"
shift 1
;;
-n)
SOLR_START=false
shift 1
;;
-help|-usage)
print_usage ""
exit 0
;;
--)
shift
break
;;
*)
if [ "$1" != "" ]; then
print_usage "Unrecognized or misplaced argument: $1!"
exit 1
else
break # out-of-args, stop looping
fi
;;
esac
done
fi
# Test for availability of needed tools
if [[ $is_tar ]] ; then
tar --version &>/dev/null || print_error "Script requires the 'tar' command"
else
unzip -hh &>/dev/null || print_error "Script requires the 'unzip' command"
fi
if [[ $SOLR_START == "true" ]] ; then
service --version &>/dev/null || print_error "Script requires the 'service' command"
java -version &>/dev/null || print_error "Solr requires java, please install or set JAVA_HOME properly"
fi
lsof -h &>/dev/null || echo "We recommend installing the 'lsof' command for more stable start/stop of Solr"
if [ -z "$SOLR_EXTRACT_DIR" ]; then
SOLR_EXTRACT_DIR=/opt
fi
if [ ! -d "$SOLR_EXTRACT_DIR" ]; then
print_usage "Installation directory $SOLR_EXTRACT_DIR not found! Please create it before running this script."
exit 1
fi
if [ -z "$SOLR_SERVICE" ]; then
SOLR_SERVICE=solr
fi
if [ -z "$SOLR_VAR_DIR" ]; then
SOLR_VAR_DIR="/var/$SOLR_SERVICE"
fi
if [ -z "$SOLR_USER" ]; then
SOLR_USER=solr
fi
if [ -z "$SOLR_PORT" ]; then
SOLR_PORT=8983
fi
if [ -z "$SOLR_UPGRADE" ]; then
SOLR_UPGRADE=NO
fi
if [ ! "$SOLR_UPGRADE" = "YES" ]; then
if [ -f "/etc/init.d/$SOLR_SERVICE" ]; then
print_usage "/etc/init.d/$SOLR_SERVICE already exists! Perhaps Solr is already setup as a service on this host? To upgrade Solr use the -f option."
exit 1
fi
if [ -e "$SOLR_EXTRACT_DIR/$SOLR_SERVICE" ]; then
print_usage "$SOLR_EXTRACT_DIR/$SOLR_SERVICE already exists! Please move this directory / link or choose a different service name using the -s option."
exit 1
fi
fi
# stop running instance
if [ -f "/etc/init.d/$SOLR_SERVICE" ]; then
echo -e "\nStopping Solr instance if exists ...\n"
service "$SOLR_SERVICE" stop
fi
# create user if not exists
solr_uid="`id -u "$SOLR_USER"`"
if [ $? -ne 0 ]; then
echo "Creating new user: $SOLR_USER"
if [ "$distro" == "RedHat" ] || [ "$distro" == "CentOS" ] ; then
adduser --system -U -m --home-dir "$SOLR_VAR_DIR" "$SOLR_USER"
elif [ "$distro" == "SUSE" ]; then
useradd --system -U -m --home-dir "$SOLR_VAR_DIR" "$SOLR_USER"
else
adduser --system --shell /bin/bash --group --disabled-password --home "$SOLR_VAR_DIR" "$SOLR_USER"
fi
fi
# extract
SOLR_INSTALL_DIR="$SOLR_EXTRACT_DIR/$SOLR_DIR"
if [ ! -d "$SOLR_INSTALL_DIR" ]; then
echo -e "\nExtracting $SOLR_ARCHIVE to $SOLR_EXTRACT_DIR\n"
if $is_tar ; then
tar zxf "$SOLR_ARCHIVE" -C "$SOLR_EXTRACT_DIR"
else
unzip -q "$SOLR_ARCHIVE" -d "$SOLR_EXTRACT_DIR"
fi
if [ ! -d "$SOLR_INSTALL_DIR" ]; then
echo -e "\nERROR: Expected directory $SOLR_INSTALL_DIR not found after extracting $SOLR_ARCHIVE ... script fails.\n" 1>&2
exit 1
fi
chown -R root: "$SOLR_INSTALL_DIR"
find "$SOLR_INSTALL_DIR" -type d -print0 | xargs -0 chmod 0755
find "$SOLR_INSTALL_DIR" -type f -print0 | xargs -0 chmod 0644
chmod -R 0755 "$SOLR_INSTALL_DIR/bin"
else
echo -e "\nWARNING: $SOLR_INSTALL_DIR already exists! Skipping extract ...\n"
fi
# create a symlink for easier scripting
if [ -h "$SOLR_EXTRACT_DIR/$SOLR_SERVICE" ]; then
echo -e "\nRemoving old symlink $SOLR_EXTRACT_DIR/$SOLR_SERVICE ...\n"
rm "$SOLR_EXTRACT_DIR/$SOLR_SERVICE"
fi
if [ -e "$SOLR_EXTRACT_DIR/$SOLR_SERVICE" ]; then
echo -e "\nWARNING: $SOLR_EXTRACT_DIR/$SOLR_SERVICE is not symlink! Skipping symlink update ...\n"
else
echo -e "\nInstalling symlink $SOLR_EXTRACT_DIR/$SOLR_SERVICE -> $SOLR_INSTALL_DIR ...\n"
ln -s "$SOLR_INSTALL_DIR" "$SOLR_EXTRACT_DIR/$SOLR_SERVICE"
fi
# install init.d script
echo -e "\nInstalling /etc/init.d/$SOLR_SERVICE script ...\n"
cp "$SOLR_INSTALL_DIR/bin/init.d/solr" "/etc/init.d/$SOLR_SERVICE"
chmod 0744 "/etc/init.d/$SOLR_SERVICE"
chown root: "/etc/init.d/$SOLR_SERVICE"
# do some basic variable substitution on the init.d script
sed_expr1="s#SOLR_INSTALL_DIR=.*#SOLR_INSTALL_DIR=\"$SOLR_EXTRACT_DIR/$SOLR_SERVICE\"#"
sed_expr2="s#SOLR_ENV=.*#SOLR_ENV=\"/etc/default/$SOLR_SERVICE.in.sh\"#"
sed_expr3="s#RUNAS=.*#RUNAS=\"$SOLR_USER\"#"
sed_expr4="s#Provides:.*#Provides: $SOLR_SERVICE#"
sed -i -e "$sed_expr1" -e "$sed_expr2" -e "$sed_expr3" -e "$sed_expr4" "/etc/init.d/$SOLR_SERVICE"
# install/move configuration
if [ ! -d /etc/default ]; then
mkdir /etc/default
chown root: /etc/default
chmod 0755 /etc/default
fi
if [ -f "$SOLR_VAR_DIR/solr.in.sh" ]; then
echo -e "\nMoving existing $SOLR_VAR_DIR/solr.in.sh to /etc/default/$SOLR_SERVICE.in.sh ...\n"
mv "$SOLR_VAR_DIR/solr.in.sh" "/etc/default/$SOLR_SERVICE.in.sh"
elif [ -f "/etc/default/$SOLR_SERVICE.in.sh" ]; then
echo -e "\n/etc/default/$SOLR_SERVICE.in.sh already exist. Skipping install ...\n"
else
echo -e "\nInstalling /etc/default/$SOLR_SERVICE.in.sh ...\n"
cp "$SOLR_INSTALL_DIR/bin/solr.in.sh" "/etc/default/$SOLR_SERVICE.in.sh"
mv "$SOLR_INSTALL_DIR/bin/solr.in.sh" "$SOLR_INSTALL_DIR/bin/solr.in.sh.orig"
mv "$SOLR_INSTALL_DIR/bin/solr.in.cmd" "$SOLR_INSTALL_DIR/bin/solr.in.cmd.orig"
echo "SOLR_PID_DIR=\"$SOLR_VAR_DIR\"
SOLR_HOME=\"$SOLR_VAR_DIR/data\"
LOG4J_PROPS=\"$SOLR_VAR_DIR/log4j.properties\"
SOLR_LOGS_DIR=\"$SOLR_VAR_DIR/logs\"
SOLR_PORT=\"$SOLR_PORT\"
" >> "/etc/default/$SOLR_SERVICE.in.sh"
fi
chown root:${SOLR_USER} "/etc/default/$SOLR_SERVICE.in.sh"
chmod 0640 "/etc/default/$SOLR_SERVICE.in.sh"
# install data directories and files
mkdir -p "$SOLR_VAR_DIR/data"
mkdir -p "$SOLR_VAR_DIR/logs"
if [ -f "$SOLR_VAR_DIR/data/solr.xml" ]; then
echo -e "\n$SOLR_VAR_DIR/data/solr.xml already exists. Skipping install ...\n"
else
cp "$SOLR_INSTALL_DIR/server/solr/"{solr.xml,zoo.cfg} "$SOLR_VAR_DIR/data/"
fi
if [ -f "$SOLR_VAR_DIR/log4j.properties" ]; then
echo -e "\n$SOLR_VAR_DIR/log4j.properties already exists. Skipping install ...\n"
else
cp "$SOLR_INSTALL_DIR/server/resources/log4j.properties" "$SOLR_VAR_DIR/log4j.properties"
fi
chown -R "$SOLR_USER:" "$SOLR_VAR_DIR"
find "$SOLR_VAR_DIR" -type d -print0 | xargs -0 chmod 0750
find "$SOLR_VAR_DIR" -type f -print0 | xargs -0 chmod 0640
# configure autostart of service
if [[ "$distro" == "RedHat" || "$distro" == "CentOS" || "$distro" == "SUSE" ]]; then
chkconfig "$SOLR_SERVICE" on
else
update-rc.d "$SOLR_SERVICE" defaults
fi
echo "Service $SOLR_SERVICE installed."
echo "Customize Solr startup configuration in /etc/default/$SOLR_SERVICE.in.sh"
# start service
if [[ $SOLR_START == "true" ]] ; then
service "$SOLR_SERVICE" start
sleep 5
service "$SOLR_SERVICE" status
else
echo "Not starting Solr service (option -n given). Start manually with 'service $SOLR_SERVICE start'"
fi
class Solr
def initialize
@solr = RSolr.connect :url => 'http://localhost:8983/solr/venjobs'
end
require 'pry'
def self.sync_all
import_fields = [salary,industry,city,company]
class Solr
def self.test_solr(search_string)
solr = RSolr.connect :url => 'http://localhost:8983'
response = solr.get 'solr/venjobs/select', :params => {
:q=> search_string,
:start=>0,
:rows=>50000,
}
result = []
response["response"]["docs"].each do |doc|
result << doc
end
[result, response["response"]["numFound"]]
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