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

Refactor Hyrax::SolrQueryBuilderService to build up the query and allow execution #4936

Closed
elrayle opened this issue May 7, 2021 · 0 comments · Fixed by #4938
Closed

Refactor Hyrax::SolrQueryBuilderService to build up the query and allow execution #4936

elrayle opened this issue May 7, 2021 · 0 comments · Fixed by #4938

Comments

@elrayle
Copy link
Contributor

elrayle commented May 7, 2021

Descriptive summary

The solr query builder service will be more functional if it can build up queries across several methods (e.g. include list of ids, limit to model, and attr-value pairs) instead of creating a single query complete query for each method. This will facilitate creation of more complex queries.

Rationale

There is a need to build up queries instead of executing a simple query and then filter the results.

Proposed Design

Rename Class

To recognize that the service does more than construct queries, it is being renamed from Hyrax::SolrQueryBuilderService to Hyrax::SolrQueryService. Hyrax::SolrQueryBuilderService and its methods are being deprecated.

NOTE: SolrQueryBuilderService uses class methods. The refactored SolrQueryService uses instance methods. This allows the query to be built up within the instance.

Name: initialize
Parameters: query: (Default: []), solr_service: (Default: Hyrax::SolrService)
Returns: self
Description: Sets @query and @solr_service

attr_reader :query, :solr_service

Rename Methods that Generate Query Snippets

Methods are being renamed as follows...

Old Name: construct_query_for_ids
New Name: with_ids
Parameters: ids:
Returns: self
Generates: '{!terms f=id}id1,id2'
Old Name: construct_query_for_model
New Name: with_model
Parameters: model:
Returns: self
Generates: '_query_:"{!field f=has_model_ssim}Monograph"'
Old Name: N/A
New Name: with_generic_type
Parameters: generic_type: (Default: 'Work')
Returns: self
Generates: '(_query_:"{!field f=generic_type_sim}Work" OR _query_:"{!field f=generic_type_si}Work")'
Old Name: construct_query_for_pairs
New Name: with_field_pairs
Parameters: field_pairs: , join_with: (Default: ' AND '), type: (Default: 'field')
Returns: self
Generates: '(_query_:"{!field f=library_id_ssim}123" AND _query_:"{!field f=owner_ssim}Fred")'

Methods that Submit Queries

Name: build
Returns: a solr query string
Description: builds a query string from @query. See description of Building the Query below.
Name: count
Returns: count of results
Description: calls SolrService.count with the built query
Name: get
Returns: solr documents matching the query
Description: calls SolrService.get with the built query
Name: reset
Returns: self
Description: resets @query to {}

Building the Query

Example Query array:

[
  '{!terms f=id}id1,id2',
  '_query_:"{!field f=has_model_ssim}Monograph"',
  '(_query_:"{!field f=generic_type_sim}Work" OR _query_:"{!field f=generic_type_si}Work")',
  '(_query_:"{!field f=library_id_ssim}123" AND _query_:"{!field f=owner_ssim}Fred")'
  '(_query_:"{!field f=subject_id_ssim}Science" OR _query_:"{!field f=subject_ssim}Philosophy")'
]

Building process: each component is joined using ' AND '

Results:

  "{!terms f=id}id1,id2 AND " \
  "_query_:\"{!field f=has_model_ssim}Monograph\" AND " \
  "(_query_:\"{!field f=generic_type_sim}Work\" OR _query_:\"{!field f=generic_type_si}Work\") AND " \
  "(_query_:\"{!field f=library_id_ssim}123\" AND _query_:\"{!field f=owner_ssim}Fred\") AND " \
  "(_query_:\"{!field f=subject_id_ssim}Science\" OR _query_:\"{!field f=subject_ssim}Philosophy\")"

Related work

PR #4929 replace AF.where in dashboard_helper_behavior
PR #4910 replace ActiveFedora where with Valkyrized where

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant