Skip to content

Commit

Permalink
changed elasticsearch to algolia search
Browse files Browse the repository at this point in the history
  • Loading branch information
enterteg committed Mar 29, 2016
1 parent 3bed642 commit 1174661
Show file tree
Hide file tree
Showing 33 changed files with 1,512 additions and 40 deletions.
5 changes: 1 addition & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ gem 'tinymce-rails'
gem 'truncate_html', '~> 0.9.3'
gem 'lightbox2-rails'
gem 'will_paginate', '~> 3.0.6'
gem 'searchkick'
gem 'elasticsearch-model'
gem 'elasticsearch-rails'
gem 'bonsai-elasticsearch-rails'
gem "algoliasearch-rails"
gem 'responders', '~> 2.0'
#-----------------

Expand Down
34 changes: 8 additions & 26 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
algoliasearch (1.7.0)
httpclient (~> 2.4)
json (>= 1.5.1)
algoliasearch-rails (1.14.1)
algoliasearch (>= 1.2.14)
json (>= 1.5.1)
arel (6.0.3)
attachinary (1.3.1)
cloudinary (~> 1.1.0)
Expand All @@ -44,7 +50,6 @@ GEM
bcrypt (3.1.11)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bonsai-elasticsearch-rails (0.0.4)
builder (3.2.2)
byebug (8.2.2)
cloudinary (1.1.4)
Expand All @@ -61,30 +66,15 @@ GEM
debug_inspector (0.0.2)
domain_name (0.5.20160310)
unf (>= 0.0.5, < 1.0.0)
elasticsearch (1.0.15)
elasticsearch-api (= 1.0.15)
elasticsearch-transport (= 1.0.15)
elasticsearch-api (1.0.15)
multi_json
elasticsearch-model (0.1.8)
activesupport (> 3)
elasticsearch (> 0.4)
hashie
elasticsearch-rails (0.1.8)
elasticsearch-transport (1.0.15)
faraday
multi_json
erubis (2.7.0)
execjs (2.6.0)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
globalid (0.3.6)
activesupport (>= 4.1.0)
haml (4.0.7)
tilt
hashie (3.4.3)
http-cookie (1.0.2)
domain_name (~> 0.5)
httpclient (2.7.1)
i18n (0.7.0)
jbuilder (2.4.1)
activesupport (>= 3.0.0, < 5.1)
Expand All @@ -104,7 +94,6 @@ GEM
mini_portile2 (2.0.0)
minitest (5.8.4)
multi_json (1.11.2)
multipart-post (2.0.0)
netrc (0.11.0)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
Expand Down Expand Up @@ -160,10 +149,6 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
searchkick (1.2.1)
activemodel
elasticsearch (>= 1)
hashie
spring (1.6.4)
sprockets (3.5.2)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -199,14 +184,12 @@ PLATFORMS
ruby

DEPENDENCIES
algoliasearch-rails
attachinary
bcrypt (~> 3.1.7)
bonsai-elasticsearch-rails
byebug
cloudinary
coffee-rails (~> 4.1.0)
elasticsearch-model
elasticsearch-rails
haml (~> 4.0, >= 4.0.7)
jbuilder (~> 2.0)
jquery-rails
Expand All @@ -217,7 +200,6 @@ DEPENDENCIES
responders (~> 2.0)
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
searchkick
spring
tinymce-rails
truncate_html (~> 0.9.3)
Expand Down
7 changes: 5 additions & 2 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
//= require jquery
//= require jquery_ujs

//= require algolia/algoliasearch.min

//= require jquery.ui.widget
//= require jquery.iframe-transport
//= require jquery.fileupload
//= require cloudinary/jquery.cloudinary
//= require attachinary


//= require turbolinks
//= require tinymce

//= require lightbox

//= require turbolinks
//= require_tree .
6 changes: 4 additions & 2 deletions app/assets/javascripts/posts.coffee.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ set_map = ->
$('#map_form').fadeOut()

$ ->
$('.attachinary-input').attachinary()
if $('.attachinary-input')
$('.attachinary-input').attachinary()
set_map()
tinyMCE.init {
selector: 'textarea#post_desc',
Expand All @@ -68,7 +69,8 @@ $ ->


$(document).on 'page:load', ->
$('.attachinary-input').attachinary()
if $('.attachinary-input')
$('.attachinary-input').attachinary()
set_map()
tinyMCE.init {
selector: 'textarea#post_desc',
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/public_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def about
def search
@controller = 'search'
if params[:search].present?
@posts = Post.paginate_it(params[:page]).search(params[:search])
@posts = Post.includes(:photo_files).search(params[:search], hitsPerPage: 5)
p
else
redirect_to action: :index
end
Expand Down
6 changes: 5 additions & 1 deletion app/models/post.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
class Post < ActiveRecord::Base
searchkick
include AlgoliaSearch

algoliasearch do
attribute :title, :desc
end

validate :validate_travel_pin
belongs_to :category
has_attachments :photos, maximum: 30
Expand Down
6 changes: 4 additions & 2 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
- else
.search
= form_tag search_path, method: :get do
= text_field_tag :search
= text_field_tag :search,'', id: 'search'
= submit_tag 'Search'
/ - else
/ .social
Expand All @@ -55,4 +55,6 @@
- if flash[:notice]
#notice
= flash[:notice]
= yield
= yield


2 changes: 1 addition & 1 deletion app/views/posts/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
.photos
-@post.photos.each do |photo|
= link_to (cloudinary_url photo.path), data: {lightbox: 'example-set'} do
= cl_image_tag photo.path, size: '300x170', crop: :fill
= cl_image_tag photo.path, size: '240x130', crop: :fill
.clear

= link_to :back do
Expand Down
1 change: 0 additions & 1 deletion app/views/public/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@
= render @posts

= will_paginate @posts, previous_label: 'prev', next_label: 'older posts', inner_window: 1, outer_window: 1

1 change: 1 addition & 0 deletions config/initializers/algoliasearch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AlgoliaSearch.configuration = { application_id: 'SQGFP5WYEF', api_key: '9a56d49162d6bad282c6284088e1177a', pagination_backend: :will_paginate }
1 change: 1 addition & 0 deletions solr/configsets/sunspot/conf/_rest_managed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"initArgs":{},"managedList":[]}
31 changes: 31 additions & 0 deletions solr/configsets/sunspot/conf/admin-extra.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
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>
-->
67 changes: 67 additions & 0 deletions solr/configsets/sunspot/conf/currency.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" ?>
<!--
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.
-->

<!-- Example exchange rates file for CurrencyField type named "currency" in example schema -->

<currencyConfig version="1.0">
<rates>
<!-- Updated from http://www.exchangerate.com/ at 2011-09-27 -->
<rate from="USD" to="ARS" rate="4.333871" comment="ARGENTINA Peso" />
<rate from="USD" to="AUD" rate="1.025768" comment="AUSTRALIA Dollar" />
<rate from="USD" to="EUR" rate="0.743676" comment="European Euro" />
<rate from="USD" to="BRL" rate="1.881093" comment="BRAZIL Real" />
<rate from="USD" to="CAD" rate="1.030815" comment="CANADA Dollar" />
<rate from="USD" to="CLP" rate="519.0996" comment="CHILE Peso" />
<rate from="USD" to="CNY" rate="6.387310" comment="CHINA Yuan" />
<rate from="USD" to="CZK" rate="18.47134" comment="CZECH REP. Koruna" />
<rate from="USD" to="DKK" rate="5.515436" comment="DENMARK Krone" />
<rate from="USD" to="HKD" rate="7.801922" comment="HONG KONG Dollar" />
<rate from="USD" to="HUF" rate="215.6169" comment="HUNGARY Forint" />
<rate from="USD" to="ISK" rate="118.1280" comment="ICELAND Krona" />
<rate from="USD" to="INR" rate="49.49088" comment="INDIA Rupee" />
<rate from="USD" to="XDR" rate="0.641358" comment="INTNL MON. FUND SDR" />
<rate from="USD" to="ILS" rate="3.709739" comment="ISRAEL Sheqel" />
<rate from="USD" to="JPY" rate="76.32419" comment="JAPAN Yen" />
<rate from="USD" to="KRW" rate="1169.173" comment="KOREA (SOUTH) Won" />
<rate from="USD" to="KWD" rate="0.275142" comment="KUWAIT Dinar" />
<rate from="USD" to="MXN" rate="13.85895" comment="MEXICO Peso" />
<rate from="USD" to="NZD" rate="1.285159" comment="NEW ZEALAND Dollar" />
<rate from="USD" to="NOK" rate="5.859035" comment="NORWAY Krone" />
<rate from="USD" to="PKR" rate="87.57007" comment="PAKISTAN Rupee" />
<rate from="USD" to="PEN" rate="2.730683" comment="PERU Sol" />
<rate from="USD" to="PHP" rate="43.62039" comment="PHILIPPINES Peso" />
<rate from="USD" to="PLN" rate="3.310139" comment="POLAND Zloty" />
<rate from="USD" to="RON" rate="3.100932" comment="ROMANIA Leu" />
<rate from="USD" to="RUB" rate="32.14663" comment="RUSSIA Ruble" />
<rate from="USD" to="SAR" rate="3.750465" comment="SAUDI ARABIA Riyal" />
<rate from="USD" to="SGD" rate="1.299352" comment="SINGAPORE Dollar" />
<rate from="USD" to="ZAR" rate="8.329761" comment="SOUTH AFRICA Rand" />
<rate from="USD" to="SEK" rate="6.883442" comment="SWEDEN Krona" />
<rate from="USD" to="CHF" rate="0.906035" comment="SWITZERLAND Franc" />
<rate from="USD" to="TWD" rate="30.40283" comment="TAIWAN Dollar" />
<rate from="USD" to="THB" rate="30.89487" comment="THAILAND Baht" />
<rate from="USD" to="AED" rate="3.672955" comment="U.A.E. Dirham" />
<rate from="USD" to="UAH" rate="7.988582" comment="UKRAINE Hryvnia" />
<rate from="USD" to="GBP" rate="0.647910" comment="UNITED KINGDOM Pound" />

<!-- Cross-rates for some common currencies -->
<rate from="EUR" to="GBP" rate="0.869914" />
<rate from="EUR" to="NOK" rate="7.800095" />
<rate from="GBP" to="NOK" rate="8.966508" />
</rates>
</currencyConfig>
36 changes: 36 additions & 0 deletions solr/configsets/sunspot/conf/elevate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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>
Loading

0 comments on commit 1174661

Please sign in to comment.