Commit d6f6c521 by hades

solr search - temp

parent dbf792a6
...@@ -124,13 +124,14 @@ GEM ...@@ -124,13 +124,14 @@ GEM
actionpack (>= 3.0) actionpack (>= 3.0)
activesupport (>= 3.0) activesupport (>= 3.0)
sprockets (~> 2.8) sprockets (~> 2.8)
sunspot (2.0.0) sunspot (2.1.0)
pr_geohash (~> 1.0) pr_geohash (~> 1.0)
rsolr (~> 1.0.7) rsolr (~> 1.0.7)
sunspot_rails (2.0.0) sunspot_rails (2.1.0)
nokogiri nokogiri
sunspot (= 2.0.0) rails (>= 3)
sunspot_solr (2.0.0) sunspot (= 2.1.0)
sunspot_solr (2.1.0)
thor (0.18.1) thor (0.18.1)
thread_safe (0.1.3) thread_safe (0.1.3)
atomic atomic
...@@ -155,8 +156,8 @@ PLATFORMS ...@@ -155,8 +156,8 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
bcrypt-ruby (~> 3.0.0) bcrypt-ruby (~> 3.0.0)
breadcrumbs_on_rails breadcrumbs_on_rails (~> 2.3.0)
capybara capybara (~> 2.1.0)
coffee-rails (~> 4.0.0) coffee-rails (~> 4.0.0)
factory_girl_rails factory_girl_rails
faker (= 1.1.2) faker (= 1.1.2)
...@@ -164,13 +165,13 @@ DEPENDENCIES ...@@ -164,13 +165,13 @@ DEPENDENCIES
jquery-rails jquery-rails
mysql2 mysql2
rails (= 4.0.0) rails (= 4.0.0)
recaptcha-mailhide recaptcha-mailhide (~> 0.1.1)
rspec-rails rspec-rails (~> 2.14.0)
sass-rails (~> 4.0.0) sass-rails (~> 4.0.0)
sdoc sdoc
sunspot_rails sunspot_rails (~> 2.1.0)
sunspot_solr sunspot_solr (~> 2.1.0)
turbolinks turbolinks
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
will_paginate (= 3.0.4) will_paginate (= 3.0.4)
will_paginate-bootstrap will_paginate-bootstrap (~> 1.0.0)
...@@ -53,7 +53,11 @@ class ProductsController < ApplicationController ...@@ -53,7 +53,11 @@ class ProductsController < ApplicationController
if params[:keyword] == nil if params[:keyword] == nil
redirect_to products_path redirect_to products_path
end end
@products = Product.search { fulltext params[:keyword] } @products = Product.search do
fulltext params[:keyword] do
boost_fields :name => 2.0
end
end
end end
private private
...@@ -64,7 +68,7 @@ class ProductsController < ApplicationController ...@@ -64,7 +68,7 @@ class ProductsController < ApplicationController
# Before filters # Before filters
def signed_in_user def signed_in_user
unless signed_in? unless signed_in?
store_location store_location
redirect_to signin_url, notice: "Please sign in." redirect_to signin_url, notice: "Please sign in."
end end
......
...@@ -2,7 +2,7 @@ class Product < ActiveRecord::Base ...@@ -2,7 +2,7 @@ class Product < ActiveRecord::Base
validates :name, :code, :condition, :image_medium, :price, :price_currency, presence: true validates :name, :code, :condition, :image_medium, :price, :price_currency, presence: true
belongs_to :product_category belongs_to :product_category
searchable do searchable do
text :title, :description text :name, :description
string :headline, :code, :condition, :price_currency string :headline, :code, :condition, :price_currency
double :price double :price
integer :product_category_id, :user_id integer :product_category_id, :user_id
...@@ -44,7 +44,7 @@ class Product < ActiveRecord::Base ...@@ -44,7 +44,7 @@ class Product < ActiveRecord::Base
def self.get_other_products(product_id, options = { product_category_id: 0, limit: 12 }) def self.get_other_products(product_id, options = { product_category_id: 0, limit: 12 })
limit = options[:limit] limit = options[:limit]
product_category_id = options[:product_category_id] product_category_id = options[:product_category_id]
return Product.select('id, name, image_medium, price, price_currency') return Product.select('id, name, image_medium, price, price_currency')
.where(availability: 'instock').where(product_category_id: product_category_id).where('id != ?', product_id) .where(availability: 'instock').where(product_category_id: product_category_id).where('id != ?', product_id)
.where(status: true) .where(status: true)
...@@ -76,4 +76,4 @@ class Product < ActiveRecord::Base ...@@ -76,4 +76,4 @@ class Product < ActiveRecord::Base
query = query.paginate(:page => page, :per_page => limit).order('created_at DESC').order('updated_at DESC').order('name') query = query.paginate(:page => page, :per_page => limit).order('created_at DESC').order('updated_at DESC').order('name')
return query return query
end end
end end
\ No newline at end of file
<% provide(:title, "Search results") %> <% provide(:title, "Search results") %>
<div class="body-box list-view margin-1"> <div class="body-box list-view">
<h2 class="sprite-2"> <h2 class="sprite-2">
Search results<span class="sprite-2"></span> Search results<span class="sprite-2"></span>
</h2> </h2>
<%= render 'shared/grid', items: @newest_items %> <%= render 'shared/grid', items: @products %>
</div> </div>
\ No newline at end of file
namespace :sunspot do
namespace :solr do
desc 'Start the Solr instance'
task :start => :environment do
case RUBY_PLATFORM
when /w(in)?32$/, /java$/
abort("This command is not supported on #{RUBY_PLATFORM}. " +
"Use rake sunspot:solr:run to run Solr in the foreground.")
end
if defined?(Sunspot::Rails::Server)
Sunspot::Rails::Server.new.start
else
Sunspot::Solr::Server.new.start
end
puts "Successfully started Solr ..."
end
desc 'Run the Solr instance in the foreground'
task :run => :environment do
if defined?(Sunspot::Rails::Server)
Sunspot::Rails::Server.new.run
else
Sunspot::Solr::Server.new.run
end
end
desc 'Stop the Solr instance'
task :stop => :environment do
case RUBY_PLATFORM
when /w(in)?32$/, /java$/
abort("This command is not supported on #{RUBY_PLATFORM}. " +
"Use rake sunspot:solr:run to run Solr in the foreground.")
end
if defined?(Sunspot::Rails::Server)
Sunspot::Rails::Server.new.stop
else
Sunspot::Solr::Server.new.stop
end
puts "Successfully stopped Solr ..."
end
task :reindex => :"sunspot:reindex"
end
end
<!--
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.
-->
<!-- The content of this page will be statically included into the top
of the admin page. Uncomment this as an example to see there the content
will show up.
<hr>
<i>This line will appear before the first table</i>
<tr>
<td colspan="2">
This row will be appended to the end of the first table
</td>
</tr>
<hr>
-->
<?xml version="1.0" encoding="UTF-8" ?>
<!--
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 this file is found in the config directory, it will only be
loaded once at startup. If it is found in Solr's data
directory, it will be re-loaded every commit.
-->
<elevate>
<query text="foo bar">
<doc id="1" />
<doc id="2" />
<doc id="3" />
</query>
<query text="ipod">
<doc id="MA147LL/A" /> <!-- put the actual ipod at the top -->
<doc id="IW-02" exclude="true" /> <!-- exclude this cable -->
</query>
</elevate>
# 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.
# Syntax:
# "source" => "target"
# "source".length() > 0 (source cannot be empty.)
# "target".length() >= 0 (target can be empty.)
# example:
# "À" => "A"
# "\u00C0" => "A"
# "\u00C0" => "\u0041"
# "ß" => "ss"
# "\t" => " "
# "\n" => ""
# À => A
"\u00C0" => "A"
# Á => A
"\u00C1" => "A"
# Â => A
"\u00C2" => "A"
# Ã => A
"\u00C3" => "A"
# Ä => A
"\u00C4" => "A"
# Å => A
"\u00C5" => "A"
# Æ => AE
"\u00C6" => "AE"
# Ç => C
"\u00C7" => "C"
# È => E
"\u00C8" => "E"
# É => E
"\u00C9" => "E"
# Ê => E
"\u00CA" => "E"
# Ë => E
"\u00CB" => "E"
# Ì => I
"\u00CC" => "I"
# Í => I
"\u00CD" => "I"
# Î => I
"\u00CE" => "I"
# Ï => I
"\u00CF" => "I"
# IJ => IJ
"\u0132" => "IJ"
# Ð => D
"\u00D0" => "D"
# Ñ => N
"\u00D1" => "N"
# Ò => O
"\u00D2" => "O"
# Ó => O
"\u00D3" => "O"
# Ô => O
"\u00D4" => "O"
# Õ => O
"\u00D5" => "O"
# Ö => O
"\u00D6" => "O"
# Ø => O
"\u00D8" => "O"
# Œ => OE
"\u0152" => "OE"
# Þ
"\u00DE" => "TH"
# Ù => U
"\u00D9" => "U"
# Ú => U
"\u00DA" => "U"
# Û => U
"\u00DB" => "U"
# Ü => U
"\u00DC" => "U"
# Ý => Y
"\u00DD" => "Y"
# Ÿ => Y
"\u0178" => "Y"
# à => a
"\u00E0" => "a"
# á => a
"\u00E1" => "a"
# â => a
"\u00E2" => "a"
# ã => a
"\u00E3" => "a"
# ä => a
"\u00E4" => "a"
# å => a
"\u00E5" => "a"
# æ => ae
"\u00E6" => "ae"
# ç => c
"\u00E7" => "c"
# è => e
"\u00E8" => "e"
# é => e
"\u00E9" => "e"
# ê => e
"\u00EA" => "e"
# ë => e
"\u00EB" => "e"
# ì => i
"\u00EC" => "i"
# í => i
"\u00ED" => "i"
# î => i
"\u00EE" => "i"
# ï => i
"\u00EF" => "i"
# ij => ij
"\u0133" => "ij"
# ð => d
"\u00F0" => "d"
# ñ => n
"\u00F1" => "n"
# ò => o
"\u00F2" => "o"
# ó => o
"\u00F3" => "o"
# ô => o
"\u00F4" => "o"
# õ => o
"\u00F5" => "o"
# ö => o
"\u00F6" => "o"
# ø => o
"\u00F8" => "o"
# œ => oe
"\u0153" => "oe"
# ß => ss
"\u00DF" => "ss"
# þ => th
"\u00FE" => "th"
# ù => u
"\u00F9" => "u"
# ú => u
"\u00FA" => "u"
# û => u
"\u00FB" => "u"
# ü => u
"\u00FC" => "u"
# ý => y
"\u00FD" => "y"
# ÿ => y
"\u00FF" => "y"
# ff => ff
"\uFB00" => "ff"
# fi => fi
"\uFB01" => "fi"
# fl => fl
"\uFB02" => "fl"
# ffi => ffi
"\uFB03" => "ffi"
# ffl => ffl
"\uFB04" => "ffl"
# ſt => ft
"\uFB05" => "ft"
# st => st
"\uFB06" => "st"
# 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.
#-----------------------------------------------------------------------
# Use a protected word file to protect against the stemmer reducing two
# unrelated words to the same base word.
# Some non-words that normally won't be encountered,
# just to test that they won't be stemmed.
dontstems
zwhacky
# 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.
user=
solr_hostname=localhost
solr_port=8983
rsyncd_port=18983
data_dir=
webapp_name=solr
master_host=
master_data_dir=
master_status_dir=
pizza
history
\ No newline at end of file
# 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.
#-----------------------------------------------------------------------
# a couple of test stopwords to test that the words are really being
# configured from this file:
stopworda
stopwordb
#Standard english stop words taken from Lucene's StopAnalyzer
a
an
and
are
as
at
be
but
by
for
if
in
into
is
it
no
not
of
on
or
s
such
t
that
the
their
then
there
these
they
this
to
was
will
with
# 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.
#-----------------------------------------------------------------------
#some test synonym mappings unlikely to appear in real input text
aaa => aaaa
bbb => bbbb1 bbbb2
ccc => cccc1,cccc2
a\=>a => b\=>b
a\,a => b\,b
fooaaa,baraaa,bazaaa
# Some synonym groups specific to this example
GB,gib,gigabyte,gigabytes
MB,mib,megabyte,megabytes
Television, Televisions, TV, TVs
#notice we use "gib" instead of "GiB" so any WordDelimiterFilter coming
#after us won't split it into two words.
# Synonym mappings can be used for spelling correction too
pixima => pixma
<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="false">
<cores adminPath="/admin/cores" host="${host:}" hostPort="${jetty.port:}">
<core name="default" instanceDir="." dataDir="default/data"/>
<core name="development" instanceDir="." dataDir="development/data"/>
<core name="test" instanceDir="." dataDir="test/data"/>
</cores>
</solr>
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