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