Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spike - Do Not Merge] trying to add classes for the new specialist-finder index #3019

Closed
wants to merge 8 commits into from
Prev Previous commit
Add new endpoint to query specialist-finder index
New parallel stack to the existing search endpoint so we don't interfere with existing search functionality.
When doing the testing, we've noticed that certain things are configured only for government_test index but not for the govuk (and hence also our new index) - such as spelling typo suggestions, and organisation expansion.

Should the tests be more explicit about calling this out?
minhngocd committed Nov 5, 2024
commit 88d7b2003b58095ea91726acc154922d9d5ebfd1
21 changes: 21 additions & 0 deletions lib/rummager/app.rb
Original file line number Diff line number Diff line change
@@ -143,6 +143,27 @@ def json_only
halt(500, env["sinatra.error"].message)
end

# Return results for the Specialist Finder searches
#
# For details, see docs/search-api.md
["/specialist-documents-search.?:request_format?", "/api/specialist-documents-search.?:request_format?"].each do |path|
get path do
json_only

query_params = parse_query_string(request.query_string)

begin
results = SearchConfig.run_specialist_document_search(query_params)
rescue BaseParameterParser::ParseError => e
status 422
return { error: e.error }.to_json
end

headers["Access-Control-Allow-Origin"] = "*"
results.to_json
end
end

# Return results for the GOV.UK site search
#
# For details, see docs/search-api.md
12 changes: 12 additions & 0 deletions lib/search/query_builder.rb
Original file line number Diff line number Diff line change
@@ -64,12 +64,24 @@ def query
end

def filter
return specialist_documents_post_filter if content_index_names.include?(SearchConfig.specialist_finder_index_name)

Search::FormatMigrator.new(
search_params.search_config,
base_query: QueryComponents::Filter.new(search_params).payload,
).call
end

def specialist_documents_post_filter
{ bool:
{
minimum_should_match: 1,
should: [{
bool: { must: QueryComponents::Filter.new(search_params).payload },
}],
} }
end

private

attr_reader :content_index_names, :metasearch_index
22 changes: 22 additions & 0 deletions lib/search_config.rb
Original file line number Diff line number Diff line change
@@ -52,6 +52,11 @@ def run_search(raw_parameters)
search_params.search_config.run_search_with_params(search_params)
end

def run_specialist_document_search(raw_parameters)
search_params = parse_parameters(raw_parameters)
search_params.search_config.run_specialist_document_search_with_params(search_params)
end

def run_batch_search(searches)
search_params = []
searches.each do |search|
@@ -121,6 +126,10 @@ def run_search_with_params(search_params)
searcher.run(search_params)
end

def run_specialist_document_search_with_params(search_params)
specialist_document_searcher.run(search_params)
end

def run_batch_search_with_params(search_params)
batch_searcher.run(search_params)
end
@@ -149,6 +158,10 @@ def new_content_index
@new_content_index ||= search_server.index_for_search([SearchConfig.govuk_index_name])
end

def specialist_documents_content_index
@specialist_documents_content_index ||= search_server.index_for_search(SearchConfig.content_index_names + [SearchConfig.specialist_finder_index_name])
end

def base_uri
cluster.uri
end
@@ -177,6 +190,15 @@ def searcher
)
end

def specialist_document_searcher
@specialist_document_searcher ||= Search::Query.new(
content_index: specialist_documents_content_index,
registries:,
metasearch_index:,
spelling_index:,
)
end

def batch_searcher
@batch_searcher ||= Search::BatchQuery.new(
content_index:,
3 changes: 2 additions & 1 deletion lib/search_server.rb
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ def initialize(base_uri, schema, index_names, govuk_index_name, content_index_na
@govuk_index_name = govuk_index_name
@content_index_names = content_index_names
@search_config = search_config
@specialist_finder_index_name = SearchConfig.specialist_finder_index_name
end

def index_group(prefix)
@@ -52,7 +53,7 @@ def validate_index_name!(index_name)

def index_name_valid?(index_name)
index_name.split(",").all? do |name|
@index_names.include?(name) || @govuk_index_name == name
@index_names.include?(name) || @govuk_index_name == name || @specialist_finder_index_name == name
end
end
end
545 changes: 545 additions & 0 deletions spec/integration/search/search_specialist_documents_spec.rb

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions spec/support/search_integration_spec_helper.rb
Original file line number Diff line number Diff line change
@@ -31,93 +31,93 @@ def cma_case_attributes(attributes = {})
}.merge(attributes)
end

def commit_filter_from_date_documents
def commit_filter_from_date_documents(index = "govuk_test")
commit_document(
"govuk_test",
index,
cma_case_attributes("opened_date" => "2014-03-30", "link" => "/old-cma-with-date"),
type: "cma_case",
)
commit_document(
"govuk_test",
index,
cma_case_attributes("opened_date" => "2014-03-30T23:00:00.000+00:00", "link" => "/old-cma-with-datetime"),
type: "cma_case",
)
commit_document(
"govuk_test",
index,
cma_case_attributes("opened_date" => "2014-03-31", "link" => "/matching-cma-with-date"),
type: "cma_case",
)
commit_document(
"govuk_test",
index,
cma_case_attributes("opened_date" => "2014-03-31T00:00:00.000+00:00", "link" => "/matching-cma-with-datetime"),
type: "cma_case",
)
end

def commit_filter_from_time_documents
def commit_filter_from_time_documents(index = "govuk_test")
commit_document(
"govuk_test",
index,
cma_case_attributes("opened_date" => "2014-03-31", "link" => "/old-cma-with-date"),
type: "cma_case",
)
commit_document(
"govuk_test",
index,
cma_case_attributes("opened_date" => "2014-03-31T13:59:59.000+00:00", "link" => "/old-cma-with-datetime"),
type: "cma_case",
)
commit_document(
"govuk_test",
index,
cma_case_attributes("opened_date" => "2014-04-01", "link" => "/matching-cma-with-date"),
type: "cma_case",
)
commit_document(
"govuk_test",
index,
cma_case_attributes("opened_date" => "2014-03-31T14:00:00.000+00:00", "link" => "/matching-cma-with-datetime"),
type: "cma_case",
)
end

def commit_filter_to_date_documents
def commit_filter_to_date_documents(index = "govuk_test")
commit_document(
"govuk_test",
index,
cma_case_attributes("opened_date" => "2014-04-02", "link" => "/matching-cma-with-date"),
type: "cma_case",
)
commit_document(
"govuk_test",
index,
cma_case_attributes("opened_date" => "2014-04-02T05:00:00.000+00:00", "link" => "/matching-cma-with-datetime"),
type: "cma_case",
)
commit_document(
"govuk_test",
index,
cma_case_attributes("opened_date" => "2014-04-03", "link" => "/future-cma-with-date"),
type: "cma_case",
)
commit_document(
"govuk_test",
index,
cma_case_attributes("opened_date" => "2014-04-03T00:00:00.000+00:00", "link" => "/future-cma-with-datetime"),
type: "cma_case",
)
end

def commit_filter_to_time_documents
def commit_filter_to_time_documents(index = "govuk_test")
commit_document(
"govuk_test",
index,
cma_case_attributes("opened_date" => "2014-04-02", "link" => "/matching-cma-with-date"),
type: "cma_case",
)
commit_document(
"govuk_test",
index,
cma_case_attributes("opened_date" => "2014-04-02T11:00:00.000+00:00", "link" => "/matching-cma-with-datetime"),
type: "cma_case",
)
commit_document(
"govuk_test",
index,
cma_case_attributes("opened_date" => "2014-04-03", "link" => "/future-cma-with-date"),
type: "cma_case",
)
commit_document(
"govuk_test",
index,
cma_case_attributes("opened_date" => "2014-04-02T11:00:01.000+00:00", "link" => "/future-cma-with-datetime"),
type: "cma_case",
)