use of org.neo4j.token.api.TokenHolder in project neo4j by neo4j.
the class FulltextIndexProvider method validateIndexRef.
private void validateIndexRef(IndexRef<?> ref) {
String providerName = getProviderDescriptor().name();
if (ref.getIndexType() != IndexType.FULLTEXT) {
throw new IllegalArgumentException("The '" + providerName + "' index provider only supports FULLTEXT index types: " + ref);
}
if (!ref.schema().isFulltextSchemaDescriptor()) {
throw new IllegalArgumentException("The " + ref.schema() + " index schema is not a full-text index schema, " + "which it is required to be for the '" + providerName + "' index provider to be able to create an index.");
}
Value value = ref.getIndexConfig().get(ANALYZER);
if (value != null) {
if (value.valueGroup() == ValueGroup.TEXT) {
String analyzerName = ((TextValue) value).stringValue();
Optional<AnalyzerProvider> analyzerProvider = listAvailableAnalyzers().filter(analyzer -> analyzer.getName().equals(analyzerName)).findFirst();
if (analyzerProvider.isPresent()) {
// Verify that the analyzer provider works.
Analyzer analyzer = analyzerProvider.get().createAnalyzer();
Objects.requireNonNull(analyzer, "The '" + analyzerName + "' analyzer returned a 'null' analyzer.");
} else {
throw new IllegalArgumentException("No such full-text analyzer: '" + analyzerName + "'.");
}
} else {
throw new IllegalArgumentException("Wrong index setting value type for fulltext analyzer: '" + value + "'.");
}
}
TokenHolder propertyKeyTokens = tokenHolders.propertyKeyTokens();
for (int propertyId : ref.schema().getPropertyIds()) {
try {
NamedToken token = propertyKeyTokens.getTokenById(propertyId);
if (token.name().equals(LuceneFulltextDocumentStructure.FIELD_ENTITY_ID)) {
throw new IllegalArgumentException("Unable to index the property, the name is reserved for internal use " + LuceneFulltextDocumentStructure.FIELD_ENTITY_ID);
}
} catch (TokenNotFoundException e) {
throw new IllegalArgumentException("Schema references non-existing property key token id: " + propertyId + ".", e);
}
}
}
Aggregations