public class IndexSchema extends Object
IndexSchema
contains information about the valid fields in an index
and the types of those fields.Modifier and Type | Class and Description |
---|---|
static class |
IndexSchema.DynamicCopy |
static class |
IndexSchema.DynamicField |
static class |
IndexSchema.DynamicReplacement |
static class |
IndexSchema.SchemaProps |
Modifier | Constructor and Description |
---|---|
protected |
IndexSchema(SolrConfig solrConfig,
SolrResourceLoader loader) |
|
IndexSchema(SolrConfig solrConfig,
String name,
InputSource is)
Constructs a schema using the specified resource name and stream.
|
Modifier and Type | Method and Description |
---|---|
IndexSchema |
addCopyFields(Map<String,Collection<String>> copyFields,
boolean persist)
Copies this schema and adds the new copy fields to the copy
Requires synchronizing on the object returned by
getSchemaUpdateLock() . |
IndexSchema |
addCopyFields(String source,
Collection<String> destinations,
int maxChars)
Copies this schema and adds the new copy fields to the copy.
|
IndexSchema |
addDynamicFields(Collection<SchemaField> newDynamicFields,
Map<String,Collection<String>> copyFieldNames,
boolean persist)
Copies this schema, adds the given dynamic fields to the copy,
Requires synchronizing on the object returned by
getSchemaUpdateLock() . |
IndexSchema |
addField(SchemaField newField) |
IndexSchema |
addField(SchemaField newField,
boolean persist)
Copies this schema, adds the given field to the copy
Requires synchronizing on the object returned by
getSchemaUpdateLock() . |
IndexSchema |
addField(SchemaField newField,
Collection<String> copyFieldNames)
Copies this schema, adds the given field to the copy
Requires synchronizing on the object returned by
getSchemaUpdateLock() . |
IndexSchema |
addFields(Collection<SchemaField> newFields)
Copies this schema, adds the given fields to the copy.
|
IndexSchema |
addFields(Collection<SchemaField> newFields,
Map<String,Collection<String>> copyFieldNames,
boolean persist)
Copies this schema, adds the given fields to the copy
Requires synchronizing on the object returned by
getSchemaUpdateLock() . |
IndexSchema |
addFieldTypes(List<FieldType> fieldTypeList,
boolean persist)
Copies this schema, adds the given field type to the copy,
Requires synchronizing on the object returned by
getSchemaUpdateLock() . |
IndexSchema |
deleteCopyFields(Map<String,Collection<String>> copyFields)
Copies this schema and deletes the given copy fields from the copy.
|
IndexSchema |
deleteDynamicFields(Collection<String> fieldNamePatterns)
Copies this schema, deletes the named dynamic fields from the copy.
|
IndexSchema |
deleteFields(Collection<String> names)
Copies this schema, deletes the named fields from the copy.
|
IndexSchema |
deleteFieldTypes(Collection<String> names)
Copies this schema, deletes the named field types from the copy.
|
protected static IndexSchema.DynamicField[] |
dynamicFieldListToSortedArray(List<IndexSchema.DynamicField> dynamicFieldList)
Sort the dynamic fields and stuff them in a normal array for faster access.
|
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.
|
protected String |
getFieldTypeXPathExpressions() |
Analyzer |
getIndexAnalyzer()
Returns the Analyzer used when indexing documents for this index
|
Map |
getNamedPropertyValues()
Get a map of property name -> value for the whole schema.
|
Map<String,Object> |
getNamedPropertyValues(String name,
SolrParams params) |
Analyzer |
getQueryAnalyzer()
Returns the Analyzer used when searching this index
|
String |
getQueryParserDefaultOperator()
Deprecated.
this will go away in Solr 7.0
|
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.
|
Object |
getSchemaUpdateLock()
Returns the schema update lock that should be synchronized on
to update the schema.
|
Similarity |
getSimilarity()
Returns the Similarity used for this index
|
SimilarityFactory |
getSimilarityFactory()
Returns the SimilarityFactory that constructed the Similarity for this index
|
Map<String,UninvertingReader.Type> |
getUninversionMap(IndexReader reader) |
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
|
protected boolean |
isDuplicateDynField(List<IndexSchema.DynamicField> dFields,
SchemaField f) |
boolean |
isDynamicField(String fieldName)
Is the specified field dynamic or not.
|
boolean |
isMutable() |
protected boolean |
isValidDynamicField(List<IndexSchema.DynamicField> dFields,
SchemaField f) |
protected static boolean |
isValidFieldGlob(String name)
Returns true if the given name has exactly one asterisk either at the start or end of the name
|
protected void |
loadCopyFields(Document document,
XPath xpath)
Loads the copy fields
|
protected Map<String,Boolean> |
loadFields(Document document,
XPath xpath)
Loads fields and dynamic fields.
|
SchemaField |
newDynamicField(String fieldNamePattern,
String fieldType,
Map<String,?> options)
Returns a SchemaField if the given dynamic field glob does not already
exist in this schema, and does not match any dynamic fields
in this schema.
|
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.
|
FieldType |
newFieldType(String typeName,
String className,
Map<String,?> options)
Returns a FieldType if the given typeName does not already
exist in this schema.
|
protected void |
postReadInform() |
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.
|
protected void |
registerExplicitSrcAndDestFields(String source,
int maxChars,
SchemaField destSchemaField,
SchemaField sourceSchemaField) |
ManagedIndexSchema |
replaceDynamicField(String fieldNamePattern,
FieldType replacementFieldType,
Map<String,?> replacementArgs)
Copies this schema, deletes the named dynamic field from the copy, creates a new dynamic
field with the same field name pattern using the given args, then rebinds any referring
dynamic copy fields to the replacement dynamic field.
|
IndexSchema |
replaceField(String fieldName,
FieldType replacementFieldType,
Map<String,?> replacementArgs)
Copies this schema, deletes the named field from the copy, creates a new field
with the same name using the given args, then rebinds any referring copy fields
to the replacement field.
|
IndexSchema |
replaceFieldType(String typeName,
String replacementClassName,
Map<String,Object> replacementArgs)
Copies this schema, deletes the named field type from the copy, creates a new field type
with the same name using the given args, rebuilds fields and dynamic fields of the given
type, then rebinds any referring copy fields to the rebuilt fields.
|
void |
setResourceName(String resourceName)
Sets the name of the resource used to instantiate this schema.
|
public static final String COPY_FIELD
public static final String COPY_FIELDS
public static final String DEFAULT_OPERATOR
public static final String DEFAULT_SCHEMA_FILE
public static final String DEFAULT_SEARCH_FIELD
public static final String DESTINATION
public static final String DYNAMIC_FIELD
public static final String DYNAMIC_FIELDS
public static final String FIELD
public static final String FIELDS
public static final String FIELD_TYPE
public static final String FIELD_TYPES
public static final String INTERNAL_POLY_FIELD_PREFIX
public static final String LUCENE_MATCH_VERSION_PARAM
public static final String MAX_CHARS
public static final String NAME
public static final String REQUIRED
public static final String SCHEMA
public static final String SIMILARITY
public static final String SLASH
public static final String SOLR_QUERY_PARSER
public static final String SOURCE
public static final String TYPE
public static final String TYPES
public static final String UNIQUE_KEY
public static final String VERSION
protected final SolrConfig solrConfig
protected String resourceName
protected String name
protected float version
protected final SolrResourceLoader loader
protected Map<String,SchemaField> fields
protected List<SchemaField> fieldsWithDefaultValue
protected Collection<SchemaField> requiredFields
protected volatile IndexSchema.DynamicField[] dynamicFields
protected List<SchemaAware> schemaAware
protected String defaultSearchFieldName
protected String queryParserDefaultOperator
protected boolean isExplicitQueryParserDefaultOperator
protected IndexSchema.DynamicCopy[] dynamicCopyFields
protected Map<SchemaField,Integer> copyFieldTargetCounts
protected Similarity similarity
protected SimilarityFactory similarityFactory
protected boolean isExplicitSimilarity
protected SchemaField uniqueKeyField
protected String uniqueKeyFieldName
protected FieldType uniqueKeyFieldType
public IndexSchema(SolrConfig solrConfig, String name, InputSource is)
protected IndexSchema(SolrConfig solrConfig, SolrResourceLoader loader)
public IndexSchema.DynamicField[] getDynamicFields()
public IndexSchema.DynamicCopy[] getDynamicCopyFields()
public SolrResourceLoader getResourceLoader()
public String getResourceName()
public void setResourceName(String resourceName)
public String getSchemaName()
public Version getDefaultLuceneMatchVersion()
public float getVersion()
public Map<String,SchemaField> getFields()
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
public Map<String,FieldType> getFieldTypes()
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
public List<SchemaField> getFieldsWithDefaultValue()
public Collection<SchemaField> getRequiredFields()
public Similarity getSimilarity()
public SimilarityFactory getSimilarityFactory()
public Analyzer getIndexAnalyzer()
This Analyzer is field (and dynamic field) name aware, and delegates to a field specific Analyzer based on the field type.
public Analyzer getQueryAnalyzer()
This Analyzer is field (and dynamic field) name aware, and delegates to a field specific Analyzer based on the field type.
public String getDefaultSearchFieldName()
QueryParsing.getDefaultField(IndexSchema, String)
@Deprecated public String getQueryParserDefaultOperator()
public SchemaField getUniqueKeyField()
public IndexableField getUniqueKeyField(Document doc)
printableUniqueKey(org.apache.lucene.document.Document)
public String printableUniqueKey(Document doc)
public void refreshAnalyzers()
getFields()
, this function is required
to synch the internally cached field analyzers.public Map<String,UninvertingReader.Type> getUninversionMap(IndexReader reader)
public boolean isMutable()
protected void readSchema(InputSource is)
protected void postReadInform()
protected Map<String,Boolean> loadFields(Document document, XPath xpath) throws XPathExpressionException
XPathExpressionException
protected static IndexSchema.DynamicField[] dynamicFieldListToSortedArray(List<IndexSchema.DynamicField> dynamicFieldList)
protected void loadCopyFields(Document document, XPath xpath) throws XPathExpressionException
XPathExpressionException
protected static boolean isValidFieldGlob(String name)
protected boolean isValidDynamicField(List<IndexSchema.DynamicField> dFields, SchemaField f)
public void registerDynamicFields(SchemaField... fields)
fields
- The sequence of SchemaField
protected boolean isDuplicateDynField(List<IndexSchema.DynamicField> dFields, SchemaField f)
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
SolrCoreAware
protected void registerExplicitSrcAndDestFields(String source, int maxChars, SchemaField destSchemaField, SchemaField sourceSchemaField)
public SchemaField[] getDynamicFieldPrototypes()
public boolean hasExplicitField(String fieldName)
public boolean isDynamicField(String fieldName)
public SchemaField getFieldOrNull(String fieldName)
fieldName
- may be an explicitly defined field or a name that
matches a dynamic field.SchemaField
getFieldType(java.lang.String)
,
getField(String)
public SchemaField getField(String fieldName)
fieldName
- may be an explicitly defined field or a name that
matches a dynamic field.SchemaField
SolrException
- if no such field existsgetFieldType(java.lang.String)
,
getFieldOrNull(String)
public FieldType getFieldType(String fieldName)
This method exists because it can be more efficient then
getField(java.lang.String)
for dynamic fields if a full SchemaField isn't needed.
fieldName
- may be an explicitly created field, or a name that
excercises a dynamic field.SolrException
- if no such field existsgetField(String)
,
getFieldTypeNoEx(java.lang.String)
public FieldType getFieldTypeByName(String fieldTypeName)
FieldType
(not to be confused with getFieldType(String)
which
takes in the name of a field), return the FieldType
.public FieldType getFieldTypeNoEx(String fieldName)
This method exists because it can be more efficient then
getField(java.lang.String)
for dynamic fields if a full SchemaField isn't needed.
fieldName
- may be an explicitly created field, or a name that
exercises a dynamic field.getField(String)
,
getFieldTypeNoEx(java.lang.String)
public FieldType getDynamicFieldType(String fieldName)
fieldName
- may be an explicitly created field, or a name that
exercises a dynamic field.SolrException
- if no such field existsgetField(String)
,
getFieldTypeNoEx(java.lang.String)
public List<String> getCopySources(String destField)
public List<CopyField> getCopyFieldsList(String sourceField)
public boolean isCopyFieldTarget(SchemaField f)
public Map getNamedPropertyValues()
public Map<String,Object> getNamedPropertyValues(String name, SolrParams params)
public List<SimpleOrderedMap<Object>> getCopyFieldProperties(boolean showDetails, Set<String> requestedSourceFields, Set<String> requestedDestinationFields)
showDetails
- If true, source and destination dynamic bases, and explicit fields matched by source globs,
will be added to dynamic copyField directives where appropriaterequestedSourceFields
- If not null, output is restricted to those copyField directives
with the requested source field namesrequestedDestinationFields
- If not null, output is restricted to those copyField directives
with the requested destination field namespublic IndexSchema addField(SchemaField newField, boolean persist)
getSchemaUpdateLock()
.newField
- the SchemaField to addpersist
- to persist the schema or notnewField(String, String, Map)
public IndexSchema addField(SchemaField newField)
public IndexSchema addField(SchemaField newField, Collection<String> copyFieldNames)
getSchemaUpdateLock()
.newField
- the SchemaField to addcopyFieldNames
- 0 or more names of targets to copy this field to. The targets must already exist.newField(String, String, Map)
public IndexSchema addFields(Collection<SchemaField> newFields)
getSchemaUpdateLock()
.newFields
- the SchemaFields to addnewField(String, String, Map)
public IndexSchema addFields(Collection<SchemaField> newFields, Map<String,Collection<String>> copyFieldNames, boolean persist)
getSchemaUpdateLock()
.newFields
- the SchemaFields to addcopyFieldNames
- 0 or more names of targets to copy this field to. The target fields must already exist.persist
- Persist the schema or notnewField(String, String, Map)
public IndexSchema deleteFields(Collection<String> names)
The schema will not be persisted.
Requires synchronizing on the object returned by
getSchemaUpdateLock()
.
names
- the names of the fields to deletepublic IndexSchema replaceField(String fieldName, FieldType replacementFieldType, Map<String,?> replacementArgs)
The schema will not be persisted.
Requires synchronizing on the object returned by getSchemaUpdateLock()
.
fieldName
- The name of the field to be replacedreplacementFieldType
- The field type of the replacement fieldreplacementArgs
- Initialization params for the replacement fieldpublic IndexSchema addDynamicFields(Collection<SchemaField> newDynamicFields, Map<String,Collection<String>> copyFieldNames, boolean persist)
getSchemaUpdateLock()
.newDynamicFields
- the SchemaFields to addcopyFieldNames
- 0 or more names of targets to copy this field to. The target fields must already exist.persist
- to persist the schema or notnewDynamicField(String, String, Map)
public IndexSchema deleteDynamicFields(Collection<String> fieldNamePatterns)
The schema will not be persisted.
Requires synchronizing on the object returned by
getSchemaUpdateLock()
.
fieldNamePatterns
- the names of the dynamic fields to deletepublic ManagedIndexSchema replaceDynamicField(String fieldNamePattern, FieldType replacementFieldType, Map<String,?> replacementArgs)
The schema will not be persisted.
Requires synchronizing on the object returned by getSchemaUpdateLock()
.
fieldNamePattern
- The glob for the dynamic field to be replacedreplacementFieldType
- The field type of the replacement dynamic fieldreplacementArgs
- Initialization params for the replacement dynamic fieldpublic IndexSchema addCopyFields(Map<String,Collection<String>> copyFields, boolean persist)
getSchemaUpdateLock()
.copyFields
- Key is the name of the source field name, value is a collection of target field names. Fields must exist.persist
- to persist the schema or notto limit the number of copied characters.
public IndexSchema addCopyFields(String source, Collection<String> destinations, int maxChars)
getSchemaUpdateLock()
source
- source field namedestinations
- collection of target field namesmaxChars
- max number of characters to copy from the source to each
of the destinations. Use CopyField.UNLIMITED
if you don't want to limit the number of copied chars.public IndexSchema deleteCopyFields(Map<String,Collection<String>> copyFields)
The schema will not be persisted.
Requires synchronizing on the object returned by
getSchemaUpdateLock()
.
copyFields
- Key is the name of the source field name, value is a collection of target field names.
Each corresponding copy field directives must exist.public SchemaField newField(String fieldName, String fieldType, Map<String,?> options)
addField(SchemaField)
.fieldName
- the name of the field to addfieldType
- the field type for the new fieldoptions
- the options to use when creating the SchemaFieldaddField(SchemaField)
public SchemaField newDynamicField(String fieldNamePattern, String fieldType, Map<String,?> options)
addField(SchemaField)
.fieldNamePattern
- the pattern for the dynamic field to addfieldType
- the field type for the new fieldoptions
- the options to use when creating the SchemaFieldaddField(SchemaField)
public Object getSchemaUpdateLock()
public IndexSchema addFieldTypes(List<FieldType> fieldTypeList, boolean persist)
getSchemaUpdateLock()
.fieldTypeList
- a list of FieldTypes to addpersist
- to persist the schema or notnewFieldType(String, String, Map)
public IndexSchema deleteFieldTypes(Collection<String> names)
The schema will not be persisted.
Requires synchronizing on the object returned by getSchemaUpdateLock()
.
names
- the names of the field types to deletepublic IndexSchema replaceFieldType(String typeName, String replacementClassName, Map<String,Object> replacementArgs)
The schema will not be persisted.
Requires synchronizing on the object returned by getSchemaUpdateLock()
.
typeName
- The name of the field type to be replacedreplacementClassName
- The class name of the replacement field typereplacementArgs
- Initialization params for the replacement field typepublic FieldType newFieldType(String typeName, String className, Map<String,?> options)
addFieldTypes(java.util.List, boolean)
.typeName
- the name of the type to addclassName
- the name of the FieldType classoptions
- the options to use when creating the FieldTypeaddFieldTypes(java.util.List, boolean)
protected String getFieldTypeXPathExpressions()
Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.