new QueryService()
QueryService provides methods to execute Solr queries against the
configured query service URL. It supports both GET and POST requests,
handles query parameters, and can include facets, filter queries, and
statistics fields.
- Source:
Methods
buildGetSettings(urlBase, queryParams) → {object}
Build GET ajax settings for a query.
Parameters:
| Name |
Type |
Description |
urlBase |
string
|
The base URL for the query service. |
queryParams |
object
|
The query parameters to include. |
- Source:
Returns:
jQuery AJAX settings object.
-
Type
-
object
buildIdQuery(pid, sid) → {string}
Builds a common query for a PID and optional SID. The query will search
for the PID in either the `id` or `seriesId` fields, and if a SID is
provided, it will also filter by that. If no PID is provided, it will
search for the SID in the `seriesId` field, excluding any versions that
have been obsoleted.
Parameters:
| Name |
Type |
Description |
pid |
string
|
The PID to search for. |
sid |
string
|
The series ID to search for. |
- Source:
Returns:
The constructed query string.
-
Type
-
string
buildPostSettings(urlBase, queryParams) → {object}
Build POST ajax settings for a query.
Parameters:
| Name |
Type |
Description |
urlBase |
string
|
The base URL for the query service. |
queryParams |
object
|
The query parameters to include. |
- Source:
Returns:
jQuery AJAX settings object.
-
Type
-
object
buildQueryObject(opts) → {object}
Construct a query object for Solr. Formats the parameters according to
Solr's expectations, including facets, filter queries, and stats fields.
Applies defaults for missing parameters.
Parameters:
- Source:
Returns:
Query parameters object.
-
Type
-
object
buildQueryParams(opts) → {object}
Build query parameters as a plain object (useful for tests or logging).
Parameters:
- Source:
Returns:
Query parameters object.
-
Type
-
object
decidePost(explicit) → {boolean}
Decide whether to use POST or GET for the query. If `explicit` is
provided, it overrides the auto-decision. If `disableQueryPOSTs` is set,
always use GET. Otherwise, default to using POST.
Parameters:
| Name |
Type |
Description |
explicit |
boolean
|
null
|
Explicitly force POST or GET. If `null`
or `undefined`, auto-decide. |
- Source:
Returns:
`true` for POST, `false` for GET.
-
Type
-
boolean
escapeLucene(value) → {string}
Escape special characters in a Lucene query string. Lucene is the query
language used by Solr.
Parameters:
| Name |
Type |
Description |
value |
string
|
The string to escape. |
- Source:
Returns:
The escaped string.
-
Type
-
string
getQueryConfig(opts) → {object}
Common logic to extract query configuration from options.
Parameters:
- Source:
Returns:
{ queryParams, urlBase, shouldPost }
-
Type
-
object
getQueryPart(field, value) → {string}
Build a query part for a field and value, escaping the value for Lucene.
Parameters:
| Name |
Type |
Description |
field |
string
|
The field name. |
value |
string
|
The value to search for. |
- Source:
Returns:
The formatted query part, e.g., `field:"value"`.
-
Type
-
string
mergeAuth(ajaxOpts) → {object}
Merge authentication settings into AJAX options. If `appUserModel` is not
available, returns the original options.
Parameters:
| Name |
Type |
Description |
ajaxOpts |
object
|
The AJAX options to merge with auth. |
- Source:
Returns:
Merged AJAX options with authentication headers.
-
Type
-
object
normalizeLucene(str, opts) → {string}
Detect and normalize a Lucene query component that may be URL-encoded or
contain unnecessary escapes such as \/. Safe to call on already
normalized strings; returns the input when no changes are needed.
Parameters:
| Name |
Type |
Description |
str |
string
|
The string to normalize. |
opts |
object
|
Options object. |
- Source:
Returns:
The normalized string.
-
Type
-
string
parseResourceMapField(json) → {string|Array.<string>}
Parses the resourceMap field from the Solr response JSON.
Parameters:
| Name |
Type |
Description |
json |
object
|
The JSON object from the Solr response |
- Source:
Returns:
The resourceMap parsed. If it is a string,
it returns the trimmed string. If it is an array, it returns an array
of trimmed strings. If it is neither, it returns an empty array.
-
Type
-
string
|
Array.<string>
parseResourceMapFields(json) → {Array.<object>}
Parses the resourceMap fields from the Solr response JSON.
Parameters:
| Name |
Type |
Description |
json |
Array.<object>
|
The "docs" part of a JSON object from the Solr
response |
- Source:
Returns:
The updated docs with parsed resourceMap fields,
though the original docs are modified in place.
-
Type
-
Array.<object>
parseResponse(response) → {Array.<object>}
Perform basic clean up of a Solr response JSON, including removing
empty values and trimming resourceMap fields.
Parameters:
| Name |
Type |
Description |
response |
object
|
The Solr response JSON object. |
- Source:
Returns:
The cleaned-up array of documents (docs).
-
Type
-
Array.<object>
query(opts) → {jqXHR}
Execute a Solr query and obtain the raw JSON response.
Parameters:
| Name |
Type |
Description |
opts |
QueryOptions
|
Query parameters & flags. |
- Source:
Returns:
jQuery AJAX promise.
-
Type
-
jqXHR
queryServiceUrl() → {string}
Get the configured query service URL from MetacatUI's appModel. Throws an
error if not configured.
- Source:
Throws:
-
If queryServiceUrl is not configured.
-
-
Type
-
Error
Returns:
The query service URL.
-
Type
-
string
queryWithFetch(opts) → {Promise.<object>}
Execute a Solr query using the native Fetch API. Returns a Promise
resolving to the parsed JSON response.
NOTE: This method is not jqXHR-compatible and should not be used in
Backbone sync/fetch overrides.
Parameters:
| Name |
Type |
Description |
opts |
QueryOptions
|
Query parameters & flags. |
- Source:
Throws:
-
On network failure or non-2xx status.
-
-
Type
-
Error
Returns:
A promise resolving to the JSON result.
-
Type
-
Promise.<object>
removeEmptyValues(docs) → {Array.<object>}
Remove empty values from an array of documents. This modifies the
documents in place, removing any properties that are `null`, `undefined`,
or an empty string.
Parameters:
| Name |
Type |
Description |
docs |
Array.<object>
|
The array of documents to clean. |
- Source:
Returns:
The cleaned array of documents.
-
Type
-
Array.<object>
toQueryString(obj) → {string}
Convert an object to a URL query string. Handles arrays by appending each
item with the same key.
Parameters:
| Name |
Type |
Description |
obj |
object
|
The object to convert. |
- Source:
Returns:
The URL-encoded query string.
-
Type
-
string