Skip to content
Snippets Groups Projects
Commit c36bdf07 authored by Mateus Rambo Strey's avatar Mateus Rambo Strey
Browse files

add elasticsearch autocomplete

parent d9097598
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ $(document).ready(function() { ...@@ -4,7 +4,7 @@ $(document).ready(function() {
source: function (request, response) { source: function (request, response) {
$.ajax({ $.ajax({
url: "/autocomplete", url: "/autocomplete",
data: { q: request.term }, data: { query: request.term },
dataType: "json", dataType: "json",
success: response, success: response,
error: function () { error: function () {
......
...@@ -18,14 +18,12 @@ class SearchController < ApplicationController ...@@ -18,14 +18,12 @@ class SearchController < ApplicationController
end end
def autocomplete def autocomplete
begin render json: LearningObject.search(params[:query], {
auto = AutocompleteService.new fields: ['name^5', 'author'],
query = params['q'] || '' limit: 10,
json_data = auto.query(query) load: false,
render text: json_data misspellings: { below: 5 }
rescue }).map(&:name)
render text: '[]'
end
end end
private private
......
...@@ -12,7 +12,7 @@ class LearningObject < ActiveRecord::Base ...@@ -12,7 +12,7 @@ class LearningObject < ActiveRecord::Base
belongs_to :publisher, polymorphic: true belongs_to :publisher, polymorphic: true
searchkick language: "brazilian" searchkick language: 'brazilian', searchable: [:name, :description, :author, :object_type]
def search_data def search_data
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment