diff --git a/Gemfile b/Gemfile index 0d31318b8dc..7b8ea8d662e 100644 --- a/Gemfile +++ b/Gemfile @@ -85,6 +85,10 @@ gem "soap4r-ruby1.9" gem "dalli" gem "kgio" +# Load algoliasearch-rails and twitter typeahead for search auto-completion +gem "twitter-typeahead-rails", "0.10.5" +gem "algoliasearch-rails" + # Gems useful for development group :development do gem "vendorer" diff --git a/Gemfile.lock b/Gemfile.lock index a19d2e7fa60..52f0fadc5bb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -39,6 +39,12 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) + algoliasearch (1.6.0) + httpclient (~> 2.4) + json (>= 1.5.1) + algoliasearch-rails (1.13.1) + algoliasearch (>= 1.2.14) + json (>= 1.5.1) arel (6.0.0) ast (2.0.0) astrolabe (1.3.0) @@ -272,6 +278,10 @@ GEM tilt (1.4.1) timecop (0.7.4) tins (1.5.2) + twitter-typeahead-rails (0.10.5) + actionpack (>= 3.1) + jquery-rails + railties (>= 3.1) tzinfo (1.2.2) thread_safe (~> 0.1) uglifier (2.7.1) @@ -295,6 +305,7 @@ PLATFORMS DEPENDENCIES SystemTimer (>= 1.1.3) actionpack-page_caching + algoliasearch-rails autoprefixer-rails bigdecimal (~> 1.1.0) coffee-rails (~> 4.1.0) @@ -338,6 +349,10 @@ DEPENDENCIES soap4r-ruby1.9 sprockets (~> 2.12.3) timecop + twitter-typeahead-rails (= 0.10.5) uglifier (>= 1.3.0) validates_email_format_of (>= 1.5.1) vendorer + +BUNDLED WITH + 1.10.6 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 354cfe66e78..8452576c97c 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -17,6 +17,9 @@ //= require piwik //= require richtext //= require querystring +//= require twitter/typeahead.min +//= require algolia/v3/algoliasearch.min + var querystring = require('querystring-component'); diff --git a/app/assets/javascripts/index/search.js b/app/assets/javascripts/index/search.js index 485920c8e1f..a830b67465b 100644 --- a/app/assets/javascripts/index/search.js +++ b/app/assets/javascripts/index/search.js @@ -1,6 +1,33 @@ //= require jquery.simulate OSM.Search = function(map) { + var algolia, idx; + + algolia = algoliasearch('A4H3Q0LE3T', 'cf91c81dd26f4e3bc03c02e4f9026172'); + idx = algolia.initIndex('osm_idx'); + + // Typeahead UI + $('.autocomplete .typeahead').typeahead({ hint: false }, { + source: idx.ttAdapter({ hitsPerPage: 5 }), + displayKey: 'name', + templates: { + suggestion: function (city) { + // Render UI + return '