Classes

Solr class

class mysolr.Solr(base_url='http://localhost:8080/solr/')

Acts as an easy-to-use interface to Solr.

Asynchronous search using async module from requests.

Parameters:
  • queries – List of queries. Each query is a dictionary containing any of the available Solr query parameters described in http://wiki.apache.org/solr/CommonQueryParameters. ‘q’ is a mandatory parameter.
  • size – Size of threadpool
  • resource – Request dispatcher. ‘select’ by default.
commit(wait_flush=True, wait_searcher=True, expunge_deletes=False)

Sends a commit message to Solr.

Parameters:
  • wait_flush – Block until index changes are flushed to disk (default is True).
  • wait_searcher – Block until a new searcher is opened and registered as the main query searcher, making the changes visible (default is True).
  • expunge_deletes – Merge segments with deletes away (default is False)
delete_by_key(identifier, commit=True)

Sends an ID delete message to Solr.

Parameters:commit – If True, sends a commit message after the operation is executed.
delete_by_query(query, commit=True)

Sends a query delete message to Solr.

Parameters:commit – If True, sends a commit message after the operation is executed.
optimize(wait_flush=True, wait_searcher=True, max_segments=1)

Sends an optimize message to Solr.

Parameters:
  • wait_flush – Block until index changes are flushed to disk (default is True)
  • wait_searcher – Block until a new searcher is opened and registered as the main query searcher, making the changes visible (default is True)
  • max_segments – Optimizes down to at most this number of segments (default is 1)
rollback()

Sends a rollback message to Solr server.

search(resource='select', **kwargs)

Queries Solr with the given kwargs and returns a SolrResponse object.

Parameters:
search_cursor(resource='select', **kwargs)
update(documents, input_type='json', commit=True)

Sends an update/add message to add the array of hashes(documents) to Solr.

Parameters:
  • documents – A list of solr-compatible documents to index. You should use unicode strings for text/string fields.
  • input_type – The format which documents are sent. Remember that json is not supported until version 3.
  • commit – If True, sends a commit message after the operation is executed.

SolrResponse class

class mysolr.SolrResponse(solr_response)

Parse solr response and make it accesible.

documents = None

Documents list.

facets = None

Facets parsed as a OrderedDict (Order matters).

highlighting = None

Shorcut to highlighting result

qtime = None

Query time.

raw_response = None

Solr full response.

spellcheck = None

Spellcheck result parsed into a more readable object.

start = None

Offset.

stats = None

Shorcut to stats resuts

status = None

Response status.

total_results = None

Number of results.

url = None

Solr query URL

Cursor class

class mysolr.Cursor(url, query)

Implements the concept of cursor in relational databases

fetch(rows=None)

Generator method that grabs all the documents in bulk sets of ‘rows’ documents

Parameters:rows – number of rows for each request

mysolr is a simple Apache Solr library for Python. You are currently looking at the documentation of the development release.

Table Of Contents

Related Topics

Fork me on GitHub