SolrClient.Schema module

Solr Schema component for basic interations:

>>> field = {'name':'fieldname','stored':True,'indexed':True,'type':'tdate'}
>>> solr.schema.create_field('SolrClient_unittest', field)
{'responseHeader': {'status': 0, 'QTime': 85}}
>>> solr.schema.does_field_exist('SolrClient_unittest','fieldname')
True
>>> res = solr.schema.create_field('SolrClient_unittest', field)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Nick\Documents\GitHub\SolrClient\SolrClient\schema.py", line 43, in create_field
        raise ValueError("Field {} Already Exists in Solr Collection {}".format(field_dict['name'],collection))
ValueError: Field fieldname Already Exists in Solr Collection SolrClient_unittest
class SolrClient.Schema(solr)

Class for interacting with Solr collections that are using data driven schemas. At this point there are basic methods for creating/deleting fields, contributions to this class are very welcome.

More info on Solr can be found here: https://cwiki.apache.org/confluence/display/solr/Schema+API

create_copy_field(collection, copy_dict)

Creates a copy field.

copy_dict should look like

{'source':'source_field_name','dest':'destination_field_name'}
Parameters:
  • collection (string) – Name of the collection for the action
  • copy_field (dict) – Dictionary of field info

Reference: https://cwiki.apache.org/confluence/display/solr/Schema+API#SchemaAPI-AddaNewCopyFieldRule

create_field(collection, field_dict)

Creates a new field in managed schema, will raise ValueError if the field already exists. field_dict should look like this:

{
     "name":"sell-by",
     "type":"tdate",
     "stored":True
}

Reference: https://cwiki.apache.org/confluence/display/solr/Defining+Fields

delete_copy_field(collection, copy_dict)

Deletes a copy field.

copy_dict should look like

{'source':'source_field_name','dest':'destination_field_name'}
Parameters:
  • collection (string) – Name of the collection for the action
  • copy_field (dict) – Dictionary of field info
delete_field(collection, field_name)

Deletes a field from the Solr Collection. Will raise ValueError if the field doesn’t exist.

Parameters:
  • collection (string) – Name of the collection for the action
  • field_name (string) – String name of the field.
does_field_exist(collection, field_name)

Checks if the field exists will return a boolean True (exists) or False(doesn’t exist).

Parameters:
  • collection (string) – Name of the collection for the action
  • field_name (string) – String name of the field.
get_schema_copyfields(collection)
get_schema_fields(collection)

Returns Schema Fields from a Solr Collection

replace_field(collection, field_dict)

Replace a field in managed schema, will raise ValueError if the field does not exist. field_dict as in create_field(...).

Parameters: