Skip to content

search

pyDataverse.api.search

Configuration options for search queries.

This class defines all available parameters that can be used to customize search behavior, including filtering, sorting, pagination, and result formatting.

Attributes

NameTypeDescription
typeOptional[Literal['dataverse', 'dataset', 'file']]Filter results by content type (dataverse, dataset, or file).
subtreeOptional[str]Limit search to a specific dataverse and its sub-dataverses.
sortOptional[str]Field to sort results by (e.g., ‘name’, ‘date’).
per_pageintNumber of results to return per page (1-1000, default 10).
startintStarting index for pagination (default 0).
orderLiteral['asc', 'desc']Sort order, either ascending or descending (default ‘desc’).
filter_queryOptional[str]Advanced filter using Solr query syntax.
show_entity_idsboolWhether to include entity IDs in the response.
show_relevanceboolWhether to include relevance scores in the response.
show_facetsboolWhether to include facet information for result filtering.
geo_pointboolGeographic point for spatial search (latitude,longitude format).
geo_radiusOptional[str]Radius for geographic search (e.g., ‘10km’, ‘5mi’).

Class to access Dataverse’s Search API.

This class provides methods to search through Dataverse content including dataverses, datasets, and files. It supports advanced search features like filtering, sorting, pagination, and geographic search.

The Search API uses Solr under the hood, allowing for powerful query capabilities including faceted search, relevance scoring, and complex filtering.

Attributes

NameTypeDescription
api_base_urlThe base URL for search API endpoints.

Examples

Basic search:

>>> search_api = SearchApi.from_api(native_api)
>>> results = search_api.search("climate change")

Advanced search with options:

>>> options = QueryOptions(
... type="dataset",
... per_page=20,
... sort="date",
... order="desc"
... )
>>> results = search_api.search("climate", options)

Methods

api_base_url(self)

Construct the base URL for search API endpoints.

Returns

TypeDescription
The complete URL path for search API requests.
search(self, query: str, options: Optional[QueryOptions] = None) -> SearchResponse

Search through Dataverse content.

Performs a search across dataverses, datasets, and files using the provided query string. Supports advanced filtering, sorting, and pagination options.

The search uses Solr’s full-text search capabilities, allowing for:

  • Simple keyword searches
  • Phrase searches (using quotes)
  • Boolean operators (AND, OR, NOT)
  • Wildcard searches (* and ?)
  • Field-specific searches

HTTP: GET /api/search

Parameters

NameTypeDescription
querystrThe search query string. Can include keywords, phrases in quotes, boolean operators, and field-specific searches.
optionsOptional[QueryOptions]Optional configuration for search behavior including filtering, sorting, pagination, and result formatting options. (default: None)

Returns

TypeDescription
SearchResponseSearchResponse object containing search results, metadata, and facet
SearchResponseinformation if requested.

Examples

Simple keyword search:

>>> results = search_api.search("climate change")

Phrase search:

>>> results = search_api.search('"global warming"')

Boolean search:

>>> results = search_api.search("climate AND temperature")

Field-specific search:

>>> results = search_api.search("title:climate")

Search with options:

>>> options = QueryOptions(type="dataset", per_page=50)
>>> results = search_api.search("climate", options)

Raises

ExceptionDescription
ApiRequestErrorIf the search request fails or returns an error.