Connecting to a set of solr servers.
To get a SolrCollection instance from a SolrConnection use either dictionary-style or attribute-style access:
>>> from solrcloudpy.connection import SolrConnection
>>> conn = SolrConnection()
>>> conn.list()
[u'collection1']
>>> conn['collection1']
SolrCollection<collection1>
Connection to a solr server or several ones
| Parameters: |
|
|---|
Determine the state of all nodes and collections in the cluster. Problematic nodes or collections are returned, along with their state, otherwise an OK message is returned
Gets the cluster leader
Create a collection.
| Parameters: |
|
|---|
Lists out the current collections in the cluster
Lists all nodes that are currently online
Manage and search a Solr Collection.
The Collections API is used to enable you to create, remove, or reload collections. Consult the Collections API for more details
>>> from solrcloudpy.connection import SolrConnection
>>> conn = SolrConnection()
>>> coll = conn['test1'].create()
>>> coll
SolrCollection<collection1>
This class is also used for query a Solr collection. The endpoints supported by default are:
- /select : the default Solr request handler
- /mlt: the request handler for doing more like this search
- /clustering: Solr’s clustering component
Support will be coming for the following endpoints:
/get: Solr’s real-time get request handler
/highlight: Solr’s search highlight component
/terms: Term component
>>> from solrcloudpy import SolrConnection >>> coll = SolrConnection()['collection1'] >>> response = coll.search({'q':'money'}) >>> response <SolrResponse [200]> >>> response.result { "response": "SolrResponse << {'start': 0, 'numFound': 0, 'docs': []} >>" }
Add a list of document to the collection
| Parameters: | docs – a list of documents to add |
|---|
Perform clustering on a query
| Parameters: | params – query parameters. Here params can be a SearchOptions instance, a dictionary or a list of tuples |
|---|
Commit changes to a collection
Create a collection
| Parameters: |
|
|---|---|
| Additional Parameters: | |
|
|
Additional parameters are further documented at https://cwiki.apache.org/confluence/display/solr/Collections+API#CollectionsAPI-CreateaCollection
Create or modify an alias for a collection
| Parameters: | alias – the name of the alias |
|---|
Create a new shard
| Parameters: |
|
|---|
Delete documents in a collection. Deletes occur either by id or by query
| Parameters: |
|
|---|
Delete an alias for a collection
| Parameters: | alias – the name of the alias |
|---|
Delete a replica
| Parameters: |
|
|---|
Delete a collection
Finds if a collection exists in the cluster
| Parameters: | collection – the collection to find |
|---|
Get a high-level overview of this collection’s index
Determines if this collection is an alias for a ‘real’ collection
Perform MLT on this index
| Parameters: | params – query parameters. Here params can be a SearchOptions instance, a dictionary or a list of tuples |
|---|
Optimize a collection for searching
| Parameters: |
|
|---|
Reload a collection
Search this index
| Parameters: | params – query parameters. Here params can be a SearchOptions instance, a dictionary or a list of tuples |
|---|
Split a shard into two new shards
| Parameters: |
|
|---|
Get the state of this collection
Get different statistics about the undelying index in a collection
Get cache statistics about the index. We retrieve cache stats for the document, filter, fiedvalue, fieldcache caches
Get query handler statistics for all of the handlers used in this Solr node
Get and modify schema
Add fields to the schema
| Parameters: | json_schema – specs for the fields to add |
|---|
Get information about a copy field in the schema
| Parameters: | ftype – the name of the field type |
|---|
Get information about all copy field in the schema
Get information about a dynamic field in the schema
| Parameters: | field – the name of the field |
|---|
Get information about a dynamic field in the schema
Get information about a field in the schema
| Parameters: | field – the name of the field |
|---|
Get information about all field in the schema
Get information about a field type in the schema
| Parameters: | ftype – the name of the field type |
|---|
Get information about field types in the schema
Manage options to pass to a solr query
Although one can use plain dictionaries to pass parameters to solr, this class makes this task more convenient. Currently, it covers all options to pass to do:
- MLT search via the mltparams member variable
- normal search via commonparams member variable
- faceted search via the facetparams member variable
Example:
>>> se = SearchOptions()
>>> se.commonparams.q("*:*").fl('*,score')
{'q': set(['*:*']), 'fl': set(['*,score'])}
>>> se.facetparams.field("id")
{'facet.field': set(['id'])}
>>> se
{'commonparams': {'q': set(['*:*']), 'fl': set(['*,score'])}, 'facetparams': {'facet.field': set(['id'])}, 'mltparams': {}}
A generic representation of a solr response. This objects contains both the Response object variable from the requests package and the parsed content in a SolrResult instance.
Status code of this response
Generic representation of a Solr search result. The response is a object whose attributes can be also accessed as dictionary keys.
Example:
>>> result
{
"response": "SolrResponse << {'start': 0, 'numFound': 0, 'docs': []} >>"
}
>>> result['response'].start
0
>>> result.response.numFound
0
Convert this result into a python dict for easier manipulation