Welcome to solr-conabio’s documentation!

solr-conabio is a simple tool for making queries to a Solr server.

Main Query Function

solr_conabio.query(host, collection, query=None, extra='', facet=None, rows=None, start=None, group=None, additional_queries=None, collapse=None, frmt='json', fq=None, fl=None)[source]

Make query to solar and return results.

Parameters:
host : str

Host name of solr server

collection : str

Collection from which to query

query : dict, optional

Query configuration. See _generate_query(). If no query is provided, all documents will be returned (limited by the rows argument).

extra : str, optional

A string to be appended to the query url. Defaults to empty string.

facet : dict, optional

Facet configuration. See _generate_facet(). If no facet configuration is provided no facet will be included.

rows : int, optional

Number of documents to return from query. Defaults to 10.

start : int, optional

Index of document at which to start querying. Defaults to 0.

group : dict, optional

Group configuration. See _generate_group(). If no group configurations are provided no grouping will occur.

additional_queries : dict or list or tuple, optional

Single or mutiple queries to add.

collapse : dict, optional

Collapse configuration. See _generate_collapse(). If no collapse configurations are provided no collapse will occur.

frmt : str, optional

Format of solr response. Defaults to json.

fq : dict, optional

Query configuration to use as filter query parameter. See _generate_query(). If no configuration is provided no filter query will be used.

fl : list or tuple, optional

Field list parameter. Only fields included in this list will be returned by solr.

Returns:
data : frmt

Solar response in the desired format (frmt)

All utilities

solr_conabio.solr_api._generate_collapse(collapse)[source]

Make collapse string for query from collapse configurations.

A collapse configuration is a dictionary with following fields:
  1. field
    Field with which to collapse results.
  2. null_policy, optional
    Policy with which to handle missing data
  3. size, optional
    Number of documents per group to show in result.
solr_conabio.solr_api._generate_facet(config)[source]

Make facet string for query from facet configurations.

A facet configuration is a dictionary with specific fields.

Facet can be of three types:

  1. field
  2. count
  3. pivot

There are global configurations for all facet types. These are specified in the following fields:

  1. limit
  2. sort
  3. mincount

For field type facet you must specify the following fields:

  1. field
    Field with which to bucketize documents. This field can be a list of fields.

For range type facet you must specify the following fields:

  1. range
    Field with which to bucketize documents.
  2. start
  3. end
  4. step

For pivot type facet you must specify the following fields:

  1. pivot
    List of fields with which to bucketize documents.

For more information of faceting checkout the solr documentation: https://lucene.apache.org/solr/guide/6_6/faceting.html

solr_conabio.solr_api._generate_group(group)[source]

Make group text for query from group configurations.

A group configuration is a dictionary with following fields:
  1. field
    Field with which to make groups.
  2. query, optional
    Addiontal query to form groups.
  3. limit, optional
    Number of groups to show in result.
solr_conabio.solr_api._generate_join(collection, local_id, foreign_id)[source]

Make join string for query from parameters.

solr_conabio.solr_api._generate_query(query)[source]

Make query string from query configurations.

Query syntax is as follows:

  1. A simple query has the following form:

    {field_1: value_1, ..., field_n: value_n}
    

in which case the resulting query is:

q=field1:value_1 AND ... AND fieldn:value_n

if the value of a field is a list or tuple of strings, the generated string field:value will be replaced with:

(field:subvalue_1 OR ... OR field:subvalue_k)
  1. A list can be a query if its of the form:

    [
        {query_1},
        ...,
        {query_n}
    ]
    

where each object in the list is a valid query. In this case the resulting query is:

q=(query_txt_1) AND ... AND (query_txt_n)
  1. A query is a dict of the type:

    query = {'AND': list_of_queries, ...}
    

or:

query = {'OR': list_of_queries, ...}

where list of queries is a list as in the previous point. Both keys cannot appear at the same time and they define the CONJUNCTION operator. Hence if:

list_of_queries = [{query_1}, ..., {query_n}]

the resulting query is:

q=(query_txt_1) CONJUNCTION ... CONJUNCTION (query_txt_n)

4. If the query is of the previous type, it may have additional fields modifying the query, such as:

  1. ‘JOIN’.
    Which is a join configuration. See _generate_join()

Examples

Say you want to generate the query:

q=(
    (field1:user OR field1:curator)
        AND
    (
        (field2:specimen AND field3:*)
            OR
        (
            field4:excretes
                OR
            field4:print
                OR
            field4:remains
        )
    )
        AND
    field4:id
)

This is the result of:

q = _generate_query([
    {field1: ['user', 'curator']},
    {'OR':[
        {fiedl2: 'specimen', field3: '*'},
        {field4: ['excretes', 'print', 'remains']},
    ]},
    {field4: 'id'}
])
solr_conabio.solr_api.query(host, collection, query=None, extra='', facet=None, rows=None, start=None, group=None, additional_queries=None, collapse=None, frmt='json', fq=None, fl=None)[source]

Make query to solar and return results.

Parameters:
host : str

Host name of solr server

collection : str

Collection from which to query

query : dict, optional

Query configuration. See _generate_query(). If no query is provided, all documents will be returned (limited by the rows argument).

extra : str, optional

A string to be appended to the query url. Defaults to empty string.

facet : dict, optional

Facet configuration. See _generate_facet(). If no facet configuration is provided no facet will be included.

rows : int, optional

Number of documents to return from query. Defaults to 10.

start : int, optional

Index of document at which to start querying. Defaults to 0.

group : dict, optional

Group configuration. See _generate_group(). If no group configurations are provided no grouping will occur.

additional_queries : dict or list or tuple, optional

Single or mutiple queries to add.

collapse : dict, optional

Collapse configuration. See _generate_collapse(). If no collapse configurations are provided no collapse will occur.

frmt : str, optional

Format of solr response. Defaults to json.

fq : dict, optional

Query configuration to use as filter query parameter. See _generate_query(). If no configuration is provided no filter query will be used.

fl : list or tuple, optional

Field list parameter. Only fields included in this list will be returned by solr.

Returns:
data : frmt

Solar response in the desired format (frmt)

Indices and tables