-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #241 from sul-dlss/suggester
adds in autocomplete and spellcheck to application and Solr config
- Loading branch information
Showing
20 changed files
with
358 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
$(document).on('ready page:load', function() { | ||
var terms = new Bloodhound({ | ||
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), | ||
queryTokenizer: Bloodhound.tokenizers.whitespace, | ||
remote: { | ||
url: '/suggest?q=%QUERY' | ||
} | ||
}); | ||
|
||
terms.initialize(); | ||
|
||
$('input.search_q').typeahead({ | ||
hint: true, | ||
highlight: true, | ||
minLength: 2 | ||
}, | ||
{ | ||
name: 'terms', | ||
displayKey: 'term', | ||
source: terms.ttAdapter() | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.twitter-typeahead { | ||
float: left; | ||
width: 100%; | ||
z-index: 10000; | ||
|
||
.tt-input.form-control { | ||
width: 100%; | ||
} | ||
|
||
.tt-hint.form-control { | ||
width: 100%; | ||
} | ||
|
||
.tt-dropdown-menu { | ||
@extend .dropdown-menu; | ||
font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; | ||
|
||
width: 100%; | ||
|
||
.tt-suggestion p{ | ||
font-size: 14px; | ||
padding-left: 10px; | ||
} | ||
|
||
.tt-cursor { | ||
background-color: $dropdown-link-hover-bg; | ||
color: $dropdown-link-hover-color; | ||
text-decoration: none; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class SuggestController < ApplicationController | ||
include Earthworks::Suggest | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Earthworks | ||
module Suggest | ||
extend ActiveSupport::Concern | ||
include Suggest::SearchHelper | ||
|
||
## | ||
# Get suggestion results from the Solr index | ||
def index | ||
@response = get_suggestions params | ||
respond_to do |format| | ||
format.json do | ||
render json: @response.suggestions | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Earthworks | ||
module Suggest | ||
class Response | ||
attr_reader :response, :request_params | ||
|
||
## | ||
# Creates a suggest response | ||
# @param [RSolr::HashWithResponse] response | ||
# @param [Hash] request_params | ||
def initialize(response, request_params) | ||
@response = response | ||
@request_params = request_params | ||
end | ||
|
||
## | ||
# Trys the suggestor response to return suggestions if they are | ||
# present | ||
# @return [Array] | ||
def suggestions | ||
response.try(:[], 'suggest').try(:[], 'mySuggester').try(:[], request_params[:q]).try(:[], 'suggestions') || [] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Earthworks | ||
module Suggest | ||
module SearchHelper | ||
extend ActiveSupport::Concern | ||
include Blacklight::SearchHelper | ||
|
||
## | ||
# For now, only use the q parameter to create a | ||
# Earthworks::Suggest::Response | ||
# @param [Hash] params | ||
# @return [Earthworks::Suggest::Response] | ||
def get_suggestions(params) | ||
request_params = { q: params[:q] } | ||
Earthworks::Suggest::Response.new suggest_results(request_params), request_params | ||
end | ||
|
||
## | ||
# Query the suggest handler using RSolr::Client::send_and_receive | ||
# @param [Hash] request_params | ||
# @return [RSolr::HashWithResponse] | ||
def suggest_results(request_params) | ||
repository.connection.send_and_receive('suggest', params: request_params) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'rails_helper' | ||
|
||
describe SuggestController do | ||
describe 'GET index' do | ||
it 'assigns @response' do | ||
get :index, format: 'json' | ||
expect(assigns(:response)).to be_an Earthworks::Suggest::Response | ||
end | ||
it 'renders json' do | ||
get :index, format: 'json' | ||
expect(response.body).to eq [].to_json | ||
end | ||
it 'returns suggestions' do | ||
get :index, format: 'json', q: 'st' | ||
json = JSON.parse(response.body) | ||
expect(json.count).to eq 2 | ||
expect(json.first['term']).to eq 'stanford' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'rails_helper' | ||
|
||
feature 'Search' do | ||
feature 'spelling suggestions' do | ||
scenario 'are turned on' do | ||
visit root_path | ||
fill_in 'q', with: 'standford' | ||
click_button 'search' | ||
expect(page).to have_content 'Did you mean to type:' | ||
end | ||
end | ||
end |
Oops, something went wrong.