-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API endpoint for search suggestions
This returns suggestions from the (internal) Search API v2, for consumption by the autocomplete component soon to be used across GOV.UK for site search. - Update `gds-api-adapters` to get access to new `autocomplete` method for Search API v2 - Add API endpoint - Reconfigure autocomplete setup to use v2 `source_key` and the new endpoint's path (with an override option for local development)
- Loading branch information
Showing
6 changed files
with
45 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Api::AutocompletesController < ApplicationController | ||
def index | ||
render json: autocomplete_response | ||
end | ||
|
||
private | ||
|
||
def autocomplete_response | ||
Services | ||
.search_api_v2 | ||
.autocomplete(params.require(:q)) | ||
.to_hash | ||
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
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,20 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe "autocomplete API", type: :request do | ||
let(:search_api_v2) { double(:search_api_v2, autocomplete: autocomplete_response) } | ||
|
||
let(:suggestions) { %w[blue grey red] } | ||
let(:autocomplete_response) { instance_double(GdsApi::Response, to_hash: { suggestions: }) } | ||
|
||
before do | ||
allow(Services).to receive(:search_api_v2).and_return(search_api_v2) | ||
end | ||
|
||
it "returns suggestions from Search API v2" do | ||
get "/api/search/autocomplete?q=loving+him+was" | ||
|
||
expect(search_api_v2).to have_received(:autocomplete).with("loving him was") | ||
expect(response).to be_successful | ||
expect(JSON.parse(response.body)).to eq("suggestions" => %w[blue grey red]) | ||
end | ||
end |