API Docs¶
Search engine API.
-
class
invenio_search.api.BaseRecordsSearch(**kwargs)[source]¶ Example subclass for searching records using Elastic DSL.
Use Meta to set kwargs defaults.
-
class
Meta[source]¶ Configuration for
SearchandFacetedSearchclasses.-
default_filter= None¶ Default filter added to search body.
Example:
default_filter = DefaultFilter('_access.owner:"1"').
-
-
classmethod
faceted_search(query=None, filters=None, search=None)[source]¶ Return faceted search instance with defaults set.
Parameters: - query – Elastic DSL query object (
Q). - filters – Dictionary with selected facet values.
- search – An instance of
Searchclass. (default:cls()).
- query – Elastic DSL query object (
-
get_record(id_)[source]¶ Return a record by its identifier.
Parameters: id – The record identifier. Returns: The record.
-
get_records(ids)[source]¶ Return records by their identifiers.
Parameters: ids – A list of record identifier. Returns: A list of records.
-
with_preference_param()[source]¶ Add the preference param to the ES request and return a new Search.
The preference param avoids the bouncing effect with multiple replicas, documented on ES documentation. See: https://www.elastic.co/guide/en/elasticsearch/guide/current /_search_options.html#_preference for more information.
-
class
-
class
invenio_search.api.BaseRecordsSearchV2(fields=('*', ), default_filter=None, **kwargs)[source]¶ Base records search V2.
Sets the needed args in kwargs for the search.
-
get_record(id_)[source]¶ Return a record by its identifier.
Parameters: id – The record identifier. Returns: The record.
-
get_records(ids)[source]¶ Return records by their identifiers.
Parameters: ids – A list of record identifier. Returns: A list of records.
-
with_preference_param(preference)[source]¶ Add the preference param to the ES request and return a new Search.
The preference param avoids the bouncing effect with multiple replicas, documented on ES documentation. See: https://www.elastic.co/guide/en/elasticsearch/guide/current /_search_options.html#_preference for more information.
Parameters: preference – A function that returns the preference value.
-
-
class
invenio_search.api.DefaultFilter(query=None, query_parser=None)[source]¶ Shortcut for defining default filters with query parser.
Build filter property with query parser.
-
query¶ Build lazy query if needed.
-
-
class
invenio_search.api.MinShouldMatch[source]¶ Work-around for Elasticsearch DSL problem.
The ElasticSearch DSL Bool query tries to inspect the
minimum_should_matchparameter, but understands only integers and not queries like “0<1”. This class circumvents the specific problematic clause in Elasticsearch DSL.
-
class
invenio_search.api.RecordsSearch(**kwargs)[source]¶ Prefixed record search class.
Constructor.
-
class
invenio_search.api.RecordsSearchV2(**kwargs)[source]¶ Prefixed record search class.
Constructor.
-
invenio_search.api.UnPrefixedRecordsSearch¶ alias of
invenio_search.api.BaseRecordsSearch
-
invenio_search.api.UnPrefixedRecordsSearchV2¶
Utilities¶
Utility functions for search engine.
-
invenio_search.utils.build_alias_name(index, prefix=None, app=None)[source]¶ Build an alias name.
Parameters: - index – Name of the index.
- prefix – The prefix to prepend to the index name.
-
invenio_search.utils.build_index_from_parts(*parts)[source]¶ Build an index name from parts.
Parameters: parts – String values that will be joined by dashes (“-“).
-
invenio_search.utils.build_index_name(index, prefix=None, suffix=None, app=None)[source]¶ Build an index name.
Parameters: - index – Name of the index.
- prefix – The prefix to prepend to the index name.
- suffix – The suffix to append to the index name.
- app – Flask app passed to
prefix_indexandsuffix_index.
-
invenio_search.utils.prefix_index(index, prefix=None, app=None)[source]¶ Prefixes the given index if needed.
Parameters: - index – Name of the index to prefix.
- prefix – Force a prefix.
- app – Flask app to get the prefix config from.
Returns: A string with the new index name prefixed if needed.
-
invenio_search.utils.schema_to_index(schema, index_names=None)[source]¶ Get index/doc_type given a schema URL.
Parameters: - schema – The schema name
- index_names – A list of index name.
Returns: A tuple containing (index, doc_type).
-
invenio_search.utils.suffix_index(index, suffix=None, app=None)[source]¶ Suffixes the given index.
Parameters: - index – Name of the index to prefix.
- suffix – The suffix to append to the index name.
- app – Flask app to get the “invenio-search” extension from.
Returns: A string with the new index name suffixed.