Commit 62b701c1 by Nguyen Quoc Kien

Fix:#2 rename Solr => SolrModule

parent f61f9e0b
......@@ -14,7 +14,7 @@ class Admin::ProductsController < ApplicationController
def destroy
if @product.destroy
Solr.new.delete_solr_index_after_delete_product(params[:id])
SolrModule.new.delete_solr_index_after_delete_product(params[:id])
flash[:success] = "Delete product : Success"
else
flash[:danger] = "Delete product : Error - Product add to carts"
......@@ -29,7 +29,7 @@ class Admin::ProductsController < ApplicationController
def create
@product = Product.new(product_params)
if @product.save
Solr.new.create_solr_index_after_create_product(@product.id, @product.name, @product.price, @product.description)
SolrModule.new.create_solr_index_after_create_product(@product.id, @product.name, @product.price, @product.description)
flash[:success] = "Create product : Success"
redirect_to admin_products_path
else
......@@ -39,7 +39,7 @@ class Admin::ProductsController < ApplicationController
def update
if @product.update(product_params)
Solr.new.update_solr_index_after_import_product(params[:id], product_params[:name])
SolrModule.new.update_solr_index_after_import_product(params[:id], product_params[:name])
flash[:success] = "Update product : Success"
redirect_to admin_products_path
else
......
class Solr
def initialize
@solr = RSolr.connect :url => Rails.configuration.solr_host.to_s
end
def update_solr_index_after_import_product(id, name)
%x{curl 'localhost:8080/solr/core0/update?commit=true' -H 'Content-type:application/json' -d '[{"id":"#{id}","name":{"set":"#{name}"}}]'}
end
def delete_solr_index_after_delete_product(id)
@solr.delete_by_id id
@solr.commit
@solr.optimize
end
def create_solr_index_after_create_product(id, name, price, description)
doc = [{:id => id,:name => name, :price => price, :description => description}]
@solr.add doc
@solr.commit
@solr.optimize
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