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

ANW-1134: Avoid resolving top_containers where it's unnecessary #2708

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion backend/app/model/search_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class SearchResolver

# Theoretically someone might resolve a field that matches an unbounded number
# of records, and this could cause an OOM. Set an upper bound.
MAX_BOOLEAN_QUERIES = AppConfig[:max_boolean_queries]
MAX_RESOLVE_RESULTS = AppConfig[:max_page_size] * 2

def initialize(resolve_definitions)
Expand Down Expand Up @@ -30,10 +31,15 @@ def resolve(results)

query = JSONModel.JSONModel(:advanced_query).from_hash('query' => boolean_query)

if query['query']['subqueries'].size > MAX_BOOLEAN_QUERIES
query['query']['subqueries'] = query['query']['subqueries'].take(MAX_BOOLEAN_QUERIES)
Log.warn("Query subqueries hit MAX_BOOLEAN_QUERIES. Result set may be incomplete: #{query.to_hash.inspect}")
end

resolved_results = Solr.search(Solr::Query.create_advanced_search(query).pagination(1, MAX_RESOLVE_RESULTS))

if resolved_results['total_hits'] > MAX_RESOLVE_RESULTS
Log.warn("Resolve query hit MAX_RESOLVE_RESULTS. Result set may be incomplete: #{query.to_hash.inspect}")
Log.warn("Resolve query hit MAX_RESOLVE_RESULTS. Result set may be incomplete: #{query.to_hash.inspect}")
end

# Insert the resolved records into our original result set.
Expand Down
1 change: 1 addition & 0 deletions common/config/config-defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
AppConfig[:solr_facet_limit] = 100

AppConfig[:default_page_size] = 10
AppConfig[:max_boolean_queries] = 1024 # ArchivesSpace Solr default
AppConfig[:max_page_size] = 250

# An option to change the length of the abstracts on the collections overview page
Expand Down
2 changes: 1 addition & 1 deletion public/app/controllers/agents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AgentsController < ApplicationController
DEFAULT_AG_FACET_TYPES = %w{primary_type subjects}
DEFAULT_AG_SEARCH_OPTS = {
'sort' => 'title_sort asc',
'resolve[]' => ['repository:id', 'resource:id@compact_resource', 'ancestors:id@compact_resource', 'top_container_uri_u_sstr:id'],
'resolve[]' => ['repository:id', 'resource:id@compact_resource', 'ancestors:id@compact_resource'],
'facet.mincount' => 1
}

Expand Down
2 changes: 1 addition & 1 deletion public/app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RepositoriesController < ApplicationController
DEFAULT_SEARCH_FACET_TYPES = ['primary_type', 'subjects', 'published_agents']
DEFAULT_REPO_SEARCH_OPTS = {
'sort' => 'title_sort asc',
'resolve[]' => ['repository:id', 'resource:id@compact_resource', 'ancestors:id@compact_resource', 'top_container_uri_u_sstr:id'],
'resolve[]' => ['repository:id', 'resource:id@compact_resource', 'ancestors:id@compact_resource'],
'facet.mincount' => 1
}
DEFAULT_TYPES = %w{archival_object digital_object agent resource accession}
Expand Down
2 changes: 1 addition & 1 deletion public/app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class SearchController < ApplicationController
DEFAULT_SEARCH_FACET_TYPES = ['repository', 'primary_type', 'subjects', 'published_agents', 'langcode']
DEFAULT_SEARCH_OPTS = {
# 'sort' => 'title_sort asc',
'resolve[]' => ['repository:id', 'resource:id@compact_resource', 'ancestors:id@compact_resource', 'top_container_uri_u_sstr:id'],
'resolve[]' => ['repository:id', 'resource:id@compact_resource', 'ancestors:id@compact_resource'],
'facet.mincount' => 1
}
DEFAULT_TYPES = %w{archival_object digital_object digital_object_component agent resource repository accession classification subject}
Expand Down