Class SchemaHelper
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.cms.search.solr.schema.SchemaHelper
-
- All Implemented Interfaces:
LogEnabled
,Component
,Serviceable
public class SchemaHelper extends AbstractLogEnabled implements Component, Serviceable
Component providing helper methods to work with search schema and fields.
-
-
Field Summary
Fields Modifier and Type Field Description protected DOMParser
_domParser
A DOM parser.protected SourceResolver
_sourceResolver
The source resolver.protected XPathProcessor
_xPathProcessor
A XPath processor.static String
ROLE
The component role.
-
Constructor Summary
Constructors Constructor Description SchemaHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected List<Map<String,Object>>
filterListNode(List<Map<String,Object>> fieldList)
Filters the list of field declarations and only keep valid ones.protected org.apache.solr.client.solrj.request.schema.AnalyzerDefinition
getAnalyzer(Node analyzerNode)
Get an analyzer definition from the corresponding DOM node.protected Map<String,Object>
getAttributes(Node node)
Extract a DOM node attributes as a Map.protected org.apache.solr.client.solrj.request.schema.FieldTypeDefinition
getFieldType(Node fieldTypeNode)
Get a field type definition from the corresponding DOM node.protected List<org.apache.solr.client.solrj.request.schema.FieldTypeDefinition>
getFieldTypes(NodeList fieldTypeNodes)
Get the field type definitions from the corresponding DOM nodes.protected List<Map<String,Object>>
getList(NodeList nodeList)
Extract the list of DOM node attributes.org.apache.solr.client.solrj.response.schema.SchemaRepresentation
getSchema(String location)
Get the schema at the corresponding location (source URI).static String
getSchemaType(MetadataType metaType)
Get the solr schema type from the metadata type.static boolean
isNameValid(String fieldName)
Chekcs that the passed Solr field name is validorg.apache.solr.client.solrj.response.schema.SchemaRepresentation
readSchema(InputStream is)
Read the static schema.void
service(ServiceManager manager)
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
_sourceResolver
protected SourceResolver _sourceResolver
The source resolver.
-
_domParser
protected DOMParser _domParser
A DOM parser.
-
_xPathProcessor
protected XPathProcessor _xPathProcessor
A XPath processor.
-
-
Constructor Detail
-
SchemaHelper
public SchemaHelper()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
getSchemaType
public static String getSchemaType(MetadataType metaType)
Get the solr schema type from the metadata type.- Parameters:
metaType
- The metadata type.- Returns:
- The solr schema type.
-
isNameValid
public static boolean isNameValid(String fieldName)
Chekcs that the passed Solr field name is valid- Parameters:
fieldName
- the Solr field name- Returns:
- true if name is valid, false otherwise
-
getSchema
public org.apache.solr.client.solrj.response.schema.SchemaRepresentation getSchema(String location)
Get the schema at the corresponding location (source URI).- Parameters:
location
- The location, as a source URI.- Returns:
- The schema representation.
-
readSchema
public org.apache.solr.client.solrj.response.schema.SchemaRepresentation readSchema(InputStream is) throws IOException, SAXException
Read the static schema.- Parameters:
is
- An input stream on the schema XML.- Returns:
- The representation of the schema.
- Throws:
IOException
- If an error occurs reading the stream.SAXException
- If an error occurs parsing the XML.
-
getFieldTypes
protected List<org.apache.solr.client.solrj.request.schema.FieldTypeDefinition> getFieldTypes(NodeList fieldTypeNodes)
Get the field type definitions from the corresponding DOM nodes.- Parameters:
fieldTypeNodes
- The field type nodes.- Returns:
- The list of field type definitions.
-
getFieldType
protected org.apache.solr.client.solrj.request.schema.FieldTypeDefinition getFieldType(Node fieldTypeNode)
Get a field type definition from the corresponding DOM node.- Parameters:
fieldTypeNode
- The field type DOM node.- Returns:
- The field type definition.
-
getAnalyzer
protected org.apache.solr.client.solrj.request.schema.AnalyzerDefinition getAnalyzer(Node analyzerNode)
Get an analyzer definition from the corresponding DOM node.- Parameters:
analyzerNode
- The analyzer node.- Returns:
- The analyzer definition.
-
getAttributes
protected Map<String,Object> getAttributes(Node node)
Extract a DOM node attributes as a Map.- Parameters:
node
- The node.- Returns:
- The attributes as a Map.
-
getList
protected List<Map<String,Object>> getList(NodeList nodeList)
Extract the list of DOM node attributes.- Parameters:
nodeList
- The node list.- Returns:
- A List of the attribute values as Maps.
-
-