Commit 4a7b53ad by vulehuan

search product with solr

parent d6f6c521
......@@ -37,6 +37,18 @@
var requestUrl = $(this).attr('href') + '&quantity=' + quantity;
window.location.href = requestUrl;
});
//
$('#btn-search').unbind('click').bind('click', function(e){
e.preventDefault();
var keyword = $('#txt-keyword').val();
var url = $(this).attr('href') + '?keyword=' + encodeURI(keyword);
window.location.href = url;
});
$('#txt-keyword').keydown(function (e){
if(e.keyCode == 13){
$('#btn-search').click();
}
})
});
})(jQuery);
jQuery.noConflict();
\ No newline at end of file
jQuery.noConflict();
......@@ -464,4 +464,8 @@ footer {
}
.btn-update-card-quantity {
margin-bottom: 3px;
}
\ No newline at end of file
}
.block-search-result {
padding-top: 10px;
}
......@@ -53,11 +53,14 @@ class ProductsController < ApplicationController
if params[:keyword] == nil
redirect_to products_path
end
@products = Product.search do
search = Product.search do
fulltext params[:keyword] do
boost_fields :name => 2.0
end
paginate :page => params[:page], :per_page => 8
end
@products = search.results
@total = search.total
end
private
......
......@@ -11,8 +11,8 @@
</div>
<div class="block-user-action">
<div class="btn-group">
<%
if signed_in?
<%
if signed_in?
user = current_user
%>
<a href="<%= cards_path %>" class="btn btn-danger"> <span class="glyphicon glyphicon-shopping-cart"></span> Your cart
......@@ -51,7 +51,7 @@
</a>
<% end %>
</div>
</div>
<div class="clearfix"></div>
......@@ -59,9 +59,9 @@
<!-- search -->
<div class="input-group block-search">
<input id="txt-keyword" type="text" class="form-control"
placeholder="Enter keywords" value=""> <span
placeholder="Enter keywords" value="<%= params['keyword'] %>"> <span
class="input-group-btn"> <a id="btn-search"
class="btn btn-default" href="javascript:void(0)"><span
class="btn btn-default" href="<%= url_for(controller: 'products', action: 'search') %>"><span
class="glyphicon glyphicon-search"></span>Search</a>
</span>
</div>
\ No newline at end of file
</div>
......@@ -3,5 +3,11 @@
<h2 class="sprite-2">
Search results<span class="sprite-2"></span>
</h2>
<div class="block-search-result">
<p>
Found <%= @total %> product(s) with <b><%= params[:keyword] %></b>
</p>
<%= render 'shared/grid', items: @products %>
</div>
<%= will_paginate @products, renderer: BootstrapPagination::Rails %>
</div>
<%
<%
if items == nil || items.empty?
if params[:action] != 'search'
%>
<p>No products available.</p>
<%
end
else
items.each_slice(4) do |row|
items.each_slice(4) do |row|
%>
<div class="row">
<%
<%
row.each do |obj|
url = product_path(obj)
add_to_card_url = cards_path + "?product_id=" + obj.id.to_s
......
7100
\ No newline at end of file
23236
\ 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