org.apache.solr.schema
Class IndexSchema

java.lang.Object
  extended by org.apache.solr.schema.IndexSchema
Direct Known Subclasses:
ManagedIndexSchema

public class IndexSchema
extends Object

IndexSchema contains information about the valid fields in an index and the types of those fields.


Nested Class Summary
static class IndexSchema.DynamicCopy
           
static class IndexSchema.DynamicField
           
static class IndexSchema.DynamicReplacement
           
 
Field Summary
static String COPY_FIELD
           
static String COPY_FIELDS
           
protected  Map<String,List<CopyField>> copyFieldsMap
           
protected  Map<SchemaField,Integer> copyFieldTargetCounts
          keys are all fields copied to, count is num of copyField directives that target them.
static String DEFAULT_OPERATOR
           
static String DEFAULT_SCHEMA_FILE
           
static String DEFAULT_SEARCH_FIELD
           
protected  String defaultSearchFieldName
           
static String DESTINATION
           
static String DYNAMIC_FIELD
           
static String DYNAMIC_FIELDS
           
protected  IndexSchema.DynamicCopy[] dynamicCopyFields
           
protected  IndexSchema.DynamicField[] dynamicFields
           
static String FIELD
           
static String FIELD_TYPE
           
static String FIELD_TYPES
           
protected  Map<String,SchemaField> fields
           
static String FIELDS
           
protected  List<SchemaField> fieldsWithDefaultValue
           
protected  Map<String,FieldType> fieldTypes
           
static String INTERNAL_POLY_FIELD_PREFIX
           
protected  boolean isExplicitQueryParserDefaultOperator
           
protected  boolean isExplicitSimilarity
           
protected  SolrResourceLoader loader
           
static String LUCENE_MATCH_VERSION_PARAM
           
protected  String name
           
static String NAME
           
protected  String queryParserDefaultOperator
           
static String REQUIRED
           
protected  Collection<SchemaField> requiredFields
           
protected  String resourceName
           
static String SCHEMA
           
protected  List<SchemaAware> schemaAware
           
protected  Similarity similarity
           
static String SIMILARITY
           
protected  SimilarityFactory similarityFactory
           
static String SLASH
           
static String SOLR_QUERY_PARSER
           
protected  SolrConfig solrConfig
           
static String SOURCE
           
static String TYPE
           
static String TYPES
           
static String UNIQUE_KEY
           
protected  SchemaField uniqueKeyField
           
protected  String uniqueKeyFieldName
           
protected  FieldType uniqueKeyFieldType
           
protected  float version
           
static String VERSION
           
 
Constructor Summary
protected IndexSchema(SolrConfig solrConfig, SolrResourceLoader loader)
           
  IndexSchema(SolrConfig solrConfig, String name, InputSource is)
          Constructs a schema using the specified resource name and stream.
 
Method Summary
 IndexSchema addCopyFields(Map<String,Collection<String>> copyFields)
          Copies this schema and adds the new copy fields to the copy, then persists the new schema
 IndexSchema addField(SchemaField newField)
          Copies this schema, adds the given field to the copy, then persists the new schema.
 IndexSchema addField(SchemaField newField, Collection<String> copyFieldNames)
          Copies this schema, adds the given field to the copy, then persists the new schema.
 IndexSchema addFields(Collection<SchemaField> newFields)
          Copies this schema, adds the given fields to the copy, then persists the new schema.
 IndexSchema addFields(Collection<SchemaField> newFields, Map<String,Collection<String>> copyFieldNames)
          Copies this schema, adds the given fields to the copy, then persists the new schema.
 Analyzer getAnalyzer()
          Returns the Analyzer used when indexing documents for this index
 List<SimpleOrderedMap<Object>> getCopyFieldProperties(boolean showDetails, Set<String> requestedSourceFields, Set<String> requestedDestinationFields)
          Returns a list of copyField directives, with optional details and optionally restricting to those directives that contain the requested source and/or destination field names.
 List<CopyField> getCopyFieldsList(String sourceField)
          Get all copy fields for a specified source field, both static and dynamic ones.
 Map<String,List<CopyField>> getCopyFieldsMap()
           
 List<String> getCopySources(String destField)
          Get all copy fields, both the static and the dynamic ones.
 Version getDefaultLuceneMatchVersion()
          The Default Lucene Match Version for this IndexSchema
 String getDefaultSearchFieldName()
          Name of the default search field specified in the schema file.
 IndexSchema.DynamicCopy[] getDynamicCopyFields()
           
 SchemaField[] getDynamicFieldPrototypes()
           
 IndexSchema.DynamicField[] getDynamicFields()
           
 FieldType getDynamicFieldType(String fieldName)
          Returns the FieldType of the best matching dynamic field for the specified field name
 String getDynamicPattern(String fieldName)
           
 SchemaField getField(String fieldName)
          Returns the SchemaField that should be used for the specified field name
 SchemaField getFieldOrNull(String fieldName)
          Returns the SchemaField that should be used for the specified field name, or null if none exists.
 Map<String,SchemaField> getFields()
          Provides direct access to the Map containing all explicit (ie: non-dynamic) fields in the index, keyed on field name.
 List<SchemaField> getFieldsWithDefaultValue()
          Provides direct access to the List containing all fields with a default value
 FieldType getFieldType(String fieldName)
          Returns the FieldType for the specified field name.
 FieldType getFieldTypeByName(String fieldTypeName)
          Given the name of a FieldType (not to be confused with getFieldType(String) which takes in the name of a field), return the FieldType.
 FieldType getFieldTypeNoEx(String fieldName)
          Returns the FieldType for the specified field name.
 Map<String,FieldType> getFieldTypes()
          Provides direct access to the Map containing all Field Types in the index, keyed on field type name.
 SimpleOrderedMap<Object> getNamedPropertyValues()
          Get a map of property name -> value for the whole schema.
 Analyzer getQueryAnalyzer()
          Returns the Analyzer used when searching this index
 String getQueryParserDefaultOperator()
          default operator ("AND" or "OR") for QueryParser
 Collection<SchemaField> getRequiredFields()
          Provides direct access to the List containing all required fields.
 SolrResourceLoader getResourceLoader()
           
 String getResourceName()
          Gets the name of the resource used to instantiate this schema.
 String getSchemaName()
          Gets the name of the schema as specified in the schema resource.
 Similarity getSimilarity()
          Returns the Similarity used for this index
 SimilarityFactory getSimilarityFactory()
          Returns the SimilarityFactory that constructed the Similarity for this index
 SchemaField getUniqueKeyField()
          Unique Key field specified in the schema file
 IndexableField getUniqueKeyField(Document doc)
          The raw (field type encoded) value of the Unique Key field for the specified Document
 float getVersion()
           
 boolean hasExplicitField(String fieldName)
          Does the schema explicitly define the specified field, i.e.
 boolean isCopyFieldTarget(SchemaField f)
          Check if a field is used as the destination of a copyField operation
 boolean isDynamicField(String fieldName)
          Is the specified field dynamic or not.
 boolean isMutable()
           
protected  Map<String,Boolean> loadFields(Document document, XPath xpath)
          Loads fields and dynamic fields.
 SchemaField newField(String fieldName, String fieldType, Map<String,?> options)
          Returns a SchemaField if the given fieldName does not already exist in this schema, and does not match any dynamic fields in this schema.
 String printableUniqueKey(Document doc)
          The printable value of the Unique Key field for the specified Document
protected  void readSchema(InputSource is)
           
 void refreshAnalyzers()
          This will re-create the Analyzers.
 void registerCopyField(String source, String dest)
           
 void registerCopyField(String source, String dest, int maxChars)
           NOTE: this function is not thread safe.
 void registerDynamicFields(SchemaField... fields)
          Register one or more new Dynamic Fields with the Schema.
 void setResourceName(String resourceName)
          Sets the name of the resource used to instantiate this schema.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPY_FIELD

public static final String COPY_FIELD
See Also:
Constant Field Values

COPY_FIELDS

public static final String COPY_FIELDS
See Also:
Constant Field Values

DEFAULT_OPERATOR

public static final String DEFAULT_OPERATOR
See Also:
Constant Field Values

DEFAULT_SCHEMA_FILE

public static final String DEFAULT_SCHEMA_FILE
See Also:
Constant Field Values

DEFAULT_SEARCH_FIELD

public static final String DEFAULT_SEARCH_FIELD
See Also:
Constant Field Values

DESTINATION

public static final String DESTINATION
See Also:
Constant Field Values

DYNAMIC_FIELD

public static final String DYNAMIC_FIELD
See Also:
Constant Field Values

DYNAMIC_FIELDS

public static final String DYNAMIC_FIELDS
See Also:
Constant Field Values

FIELD

public static final String FIELD
See Also:
Constant Field Values

FIELDS

public static final String FIELDS
See Also:
Constant Field Values

FIELD_TYPE

public static final String FIELD_TYPE
See Also:
Constant Field Values

FIELD_TYPES

public static final String FIELD_TYPES
See Also:
Constant Field Values

INTERNAL_POLY_FIELD_PREFIX

public static final String INTERNAL_POLY_FIELD_PREFIX
See Also:
Constant Field Values

LUCENE_MATCH_VERSION_PARAM

public static final String LUCENE_MATCH_VERSION_PARAM
See Also:
Constant Field Values

NAME

public static final String NAME
See Also:
Constant Field Values

REQUIRED

public static final String REQUIRED
See Also:
Constant Field Values

SCHEMA

public static final String SCHEMA
See Also:
Constant Field Values

SIMILARITY

public static final String SIMILARITY
See Also:
Constant Field Values

SLASH

public static final String SLASH
See Also:
Constant Field Values

SOLR_QUERY_PARSER

public static final String SOLR_QUERY_PARSER
See Also:
Constant Field Values

SOURCE

public static final String SOURCE
See Also:
Constant Field Values

TYPE

public static final String TYPE
See Also:
Constant Field Values

TYPES

public static final String TYPES
See Also:
Constant Field Values

UNIQUE_KEY

public static final String UNIQUE_KEY
See Also:
Constant Field Values

VERSION

public static final String VERSION
See Also:
Constant Field Values

solrConfig

protected final SolrConfig solrConfig

resourceName

protected String resourceName

name

protected String name

version

protected float version

loader

protected final SolrResourceLoader loader

fields

protected Map<String,SchemaField> fields

fieldTypes

protected Map<String,FieldType> fieldTypes

fieldsWithDefaultValue

protected List<SchemaField> fieldsWithDefaultValue

requiredFields

protected Collection<SchemaField> requiredFields

dynamicFields

protected volatile IndexSchema.DynamicField[] dynamicFields

schemaAware

protected List<SchemaAware> schemaAware

defaultSearchFieldName

protected String defaultSearchFieldName

queryParserDefaultOperator

protected String queryParserDefaultOperator

isExplicitQueryParserDefaultOperator

protected boolean isExplicitQueryParserDefaultOperator

copyFieldsMap

protected Map<String,List<CopyField>> copyFieldsMap

dynamicCopyFields

protected IndexSchema.DynamicCopy[] dynamicCopyFields

copyFieldTargetCounts

protected Map<SchemaField,Integer> copyFieldTargetCounts
keys are all fields copied to, count is num of copyField directives that target them.


similarity

protected Similarity similarity

similarityFactory

protected SimilarityFactory similarityFactory

isExplicitSimilarity

protected boolean isExplicitSimilarity

uniqueKeyField

protected SchemaField uniqueKeyField

uniqueKeyFieldName

protected String uniqueKeyFieldName

uniqueKeyFieldType

protected FieldType uniqueKeyFieldType
Constructor Detail

IndexSchema

public IndexSchema(SolrConfig solrConfig,
                   String name,
                   InputSource is)
Constructs a schema using the specified resource name and stream.

See Also:
By default, this follows the normal config path directory searching rules., SolrResourceLoader.openResource(java.lang.String)

IndexSchema

protected IndexSchema(SolrConfig solrConfig,
                      SolrResourceLoader loader)
Method Detail

getDynamicFields

public IndexSchema.DynamicField[] getDynamicFields()

getCopyFieldsMap

public Map<String,List<CopyField>> getCopyFieldsMap()

getDynamicCopyFields

public IndexSchema.DynamicCopy[] getDynamicCopyFields()

getResourceLoader

public SolrResourceLoader getResourceLoader()
Since:
solr 1.4

getResourceName

public String getResourceName()
Gets the name of the resource used to instantiate this schema.


setResourceName

public void setResourceName(String resourceName)
Sets the name of the resource used to instantiate this schema.


getSchemaName

public String getSchemaName()
Gets the name of the schema as specified in the schema resource.


getDefaultLuceneMatchVersion

public Version getDefaultLuceneMatchVersion()
The Default Lucene Match Version for this IndexSchema


getVersion

public float getVersion()

getFields

public Map<String,SchemaField> getFields()
Provides direct access to the Map containing all explicit (ie: non-dynamic) fields in the index, keyed on field name.

Modifying this Map (or any item in it) will affect the real schema

NOTE: this function is not thread safe. However, it is safe to use within the standard inform( SolrCore core ) function for SolrCoreAware classes. Outside inform, this could potentially throw a ConcurrentModificationException


getFieldTypes

public Map<String,FieldType> getFieldTypes()
Provides direct access to the Map containing all Field Types in the index, keyed on field type name.

Modifying this Map (or any item in it) will affect the real schema. However if you make any modifications, be sure to call refreshAnalyzers() to update the Analyzers for the registered fields.

NOTE: this function is not thread safe. However, it is safe to use within the standard inform( SolrCore core ) function for SolrCoreAware classes. Outside inform, this could potentially throw a ConcurrentModificationException


getFieldsWithDefaultValue

public List<SchemaField> getFieldsWithDefaultValue()
Provides direct access to the List containing all fields with a default value


getRequiredFields

public Collection<SchemaField> getRequiredFields()
Provides direct access to the List containing all required fields. This list contains all fields with default values.


getSimilarity

public Similarity getSimilarity()
Returns the Similarity used for this index


getSimilarityFactory

public SimilarityFactory getSimilarityFactory()
Returns the SimilarityFactory that constructed the Similarity for this index


getAnalyzer

public Analyzer getAnalyzer()
Returns the Analyzer used when indexing documents for this index

This Analyzer is field (and dynamic field) name aware, and delegates to a field specific Analyzer based on the field type.


getQueryAnalyzer

public Analyzer getQueryAnalyzer()
Returns the Analyzer used when searching this index

This Analyzer is field (and dynamic field) name aware, and delegates to a field specific Analyzer based on the field type.


getDefaultSearchFieldName

public String getDefaultSearchFieldName()
Name of the default search field specified in the schema file.
Note:Avoid calling this, try to use this method so that the 'df' param is consulted as an override: QueryParsing.getDefaultField(IndexSchema, String)


getQueryParserDefaultOperator

public String getQueryParserDefaultOperator()
default operator ("AND" or "OR") for QueryParser


getUniqueKeyField

public SchemaField getUniqueKeyField()
Unique Key field specified in the schema file

Returns:
null if this schema has no unique key field

getUniqueKeyField

public IndexableField getUniqueKeyField(Document doc)
The raw (field type encoded) value of the Unique Key field for the specified Document

Returns:
null if this schema has no unique key field
See Also:
printableUniqueKey(org.apache.lucene.document.Document)

printableUniqueKey

public String printableUniqueKey(Document doc)
The printable value of the Unique Key field for the specified Document

Returns:
null if this schema has no unique key field

refreshAnalyzers

public void refreshAnalyzers()
This will re-create the Analyzers. If you make any modifications to the Field map (getFields(), this function is required to synch the internally cached field analyzers.

Since:
solr 1.3

isMutable

public boolean isMutable()

readSchema

protected void readSchema(InputSource is)

loadFields

protected Map<String,Boolean> loadFields(Document document,
                                         XPath xpath)
                                  throws XPathExpressionException
Loads fields and dynamic fields.

Returns:
a map from field name to explicit required value
Throws:
XPathExpressionException

registerDynamicFields

public void registerDynamicFields(SchemaField... fields)
Register one or more new Dynamic Fields with the Schema.

Parameters:
fields - The sequence of SchemaField

registerCopyField

public void registerCopyField(String source,
                              String dest)

registerCopyField

public void registerCopyField(String source,
                              String dest,
                              int maxChars)

NOTE: this function is not thread safe. However, it is safe to use within the standard inform( SolrCore core ) function for SolrCoreAware classes. Outside inform, this could potentially throw a ConcurrentModificationException

See Also:
SolrCoreAware

getDynamicFieldPrototypes

public SchemaField[] getDynamicFieldPrototypes()

getDynamicPattern

public String getDynamicPattern(String fieldName)

hasExplicitField

public boolean hasExplicitField(String fieldName)
Does the schema explicitly define the specified field, i.e. not as a result of a copyField declaration? We consider it explicitly defined if it matches a field name or a dynamicField name.

Returns:
true if explicitly declared in the schema.

isDynamicField

public boolean isDynamicField(String fieldName)
Is the specified field dynamic or not.

Returns:
true if the specified field is dynamic

getFieldOrNull

public SchemaField getFieldOrNull(String fieldName)
Returns the SchemaField that should be used for the specified field name, or null if none exists.

Parameters:
fieldName - may be an explicitly defined field or a name that matches a dynamic field.
Returns:
The SchemaField
See Also:
getFieldType(java.lang.String), getField(String)

getField

public SchemaField getField(String fieldName)
Returns the SchemaField that should be used for the specified field name

Parameters:
fieldName - may be an explicitly defined field or a name that matches a dynamic field.
Returns:
The SchemaField
Throws:
SolrException - if no such field exists
See Also:
getFieldType(java.lang.String), getFieldOrNull(String)

getFieldType

public FieldType getFieldType(String fieldName)
Returns the FieldType for the specified field name.

This method exists because it can be more efficient then getField(java.lang.String) for dynamic fields if a full SchemaField isn't needed.

Parameters:
fieldName - may be an explicitly created field, or a name that excercises a dynamic field.
Throws:
SolrException - if no such field exists
See Also:
getField(String), getFieldTypeNoEx(java.lang.String)

getFieldTypeByName

public FieldType getFieldTypeByName(String fieldTypeName)
Given the name of a FieldType (not to be confused with getFieldType(String) which takes in the name of a field), return the FieldType.

Parameters:
fieldTypeName - The name of the FieldType
Returns:
The FieldType or null.

getFieldTypeNoEx

public FieldType getFieldTypeNoEx(String fieldName)
Returns the FieldType for the specified field name.

This method exists because it can be more efficient then getField(java.lang.String) for dynamic fields if a full SchemaField isn't needed.

Parameters:
fieldName - may be an explicitly created field, or a name that exercises a dynamic field.
Returns:
null if field is not defined.
See Also:
getField(String), getFieldTypeNoEx(java.lang.String)

getDynamicFieldType

public FieldType getDynamicFieldType(String fieldName)
Returns the FieldType of the best matching dynamic field for the specified field name

Parameters:
fieldName - may be an explicitly created field, or a name that exercises a dynamic field.
Throws:
SolrException - if no such field exists
See Also:
getField(String), getFieldTypeNoEx(java.lang.String)

getCopySources

public List<String> getCopySources(String destField)
Get all copy fields, both the static and the dynamic ones.

Returns:
Array of fields copied into this field

getCopyFieldsList

public List<CopyField> getCopyFieldsList(String sourceField)
Get all copy fields for a specified source field, both static and dynamic ones.

Returns:
List of CopyFields to copy to.
Since:
solr 1.4

isCopyFieldTarget

public boolean isCopyFieldTarget(SchemaField f)
Check if a field is used as the destination of a copyField operation

Since:
solr 1.3

getNamedPropertyValues

public SimpleOrderedMap<Object> getNamedPropertyValues()
Get a map of property name -> value for the whole schema.


getCopyFieldProperties

public List<SimpleOrderedMap<Object>> getCopyFieldProperties(boolean showDetails,
                                                             Set<String> requestedSourceFields,
                                                             Set<String> requestedDestinationFields)
Returns a list of copyField directives, with optional details and optionally restricting to those directives that contain the requested source and/or destination field names.

Parameters:
showDetails - If true, source and destination dynamic bases, and explicit fields matched by source globs, will be added to dynamic copyField directives where appropriate
requestedSourceFields - If not null, output is restricted to those copyField directives with the requested source field names
requestedDestinationFields - If not null, output is restricted to those copyField directives with the requested destination field names
Returns:
a list of copyField directives

addField

public IndexSchema addField(SchemaField newField)
Copies this schema, adds the given field to the copy, then persists the new schema.

Parameters:
newField - the SchemaField to add
Returns:
a new IndexSchema based on this schema with newField added
See Also:
newField(String, String, Map)

addField

public IndexSchema addField(SchemaField newField,
                            Collection<String> copyFieldNames)
Copies this schema, adds the given field to the copy, then persists the new schema.

Parameters:
newField - the SchemaField to add
copyFieldNames - 0 or more names of targets to copy this field to. The targets must already exist.
Returns:
a new IndexSchema based on this schema with newField added
See Also:
newField(String, String, Map)

addFields

public IndexSchema addFields(Collection<SchemaField> newFields)
Copies this schema, adds the given fields to the copy, then persists the new schema.

Parameters:
newFields - the SchemaFields to add
Returns:
a new IndexSchema based on this schema with newFields added
See Also:
newField(String, String, Map)

addFields

public IndexSchema addFields(Collection<SchemaField> newFields,
                             Map<String,Collection<String>> copyFieldNames)
Copies this schema, adds the given fields to the copy, then persists the new schema.

Parameters:
newFields - the SchemaFields to add
copyFieldNames - 0 or more names of targets to copy this field to. The target fields must already exist.
Returns:
a new IndexSchema based on this schema with newFields added
See Also:
newField(String, String, Map)

addCopyFields

public IndexSchema addCopyFields(Map<String,Collection<String>> copyFields)
Copies this schema and adds the new copy fields to the copy, then persists the new schema

Parameters:
copyFields - Key is the name of the source field name, value is a collection of target field names. Fields must exist.
Returns:
The new Schema with the copy fields added

newField

public SchemaField newField(String fieldName,
                            String fieldType,
                            Map<String,?> options)
Returns a SchemaField if the given fieldName does not already exist in this schema, and does not match any dynamic fields in this schema. The resulting SchemaField can be used in a call to addField(SchemaField).

Parameters:
fieldName - the name of the field to add
fieldType - the field type for the new field
options - the options to use when creating the SchemaField
Returns:
The created SchemaField
See Also:
addField(SchemaField)


Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.