Search in sources :

Example 1 with ANALYZER

use of org.neo4j.kernel.api.impl.fulltext.FulltextIndexSettingsKeys.ANALYZER 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);
        }
    }
}
Also used : AnalyzerProvider(org.neo4j.graphdb.schema.AnalyzerProvider) DroppableLuceneIndex(org.neo4j.kernel.api.impl.index.DroppableLuceneIndex) SchemaIndex(org.neo4j.kernel.api.impl.schema.SchemaIndex) Log(org.neo4j.logging.Log) CursorContext(org.neo4j.io.pagecache.context.CursorContext) TokenNameLookup(org.neo4j.common.TokenNameLookup) IndexType(org.neo4j.internal.schema.IndexType) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) Config(org.neo4j.configuration.Config) DatabaseIndex(org.neo4j.kernel.api.impl.index.DatabaseIndex) Value(org.neo4j.values.storable.Value) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.IndexSamplingConfig) StringUtils(org.apache.commons.lang3.StringUtils) FulltextIndexSettings.createAnalyzer(org.neo4j.kernel.api.impl.fulltext.FulltextIndexSettings.createAnalyzer) LuceneSchemaIndexBuilder(org.neo4j.kernel.api.impl.schema.LuceneSchemaIndexBuilder) DroppableIndex(org.neo4j.kernel.api.impl.index.DroppableIndex) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) Exceptions(org.neo4j.internal.helpers.Exceptions) PageCache(org.neo4j.io.pagecache.PageCache) StringUtils.defaultIfEmpty(org.apache.commons.lang3.StringUtils.defaultIfEmpty) IndexStorageFactory(org.neo4j.kernel.api.impl.index.storage.IndexStorageFactory) PartitionedIndexStorage(org.neo4j.kernel.api.impl.index.storage.PartitionedIndexStorage) TextValue(org.neo4j.values.storable.TextValue) MinimalIndexAccessor(org.neo4j.kernel.api.index.MinimalIndexAccessor) Services(org.neo4j.service.Services) Objects(java.util.Objects) Stream(java.util.stream.Stream) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Optional(java.util.Optional) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) DirectoryFactory(org.neo4j.kernel.api.impl.index.storage.DirectoryFactory) IndexCapability(org.neo4j.internal.schema.IndexCapability) FulltextSettings(org.neo4j.configuration.FulltextSettings) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) ANALYZER(org.neo4j.kernel.api.impl.fulltext.FulltextIndexSettingsKeys.ANALYZER) LuceneMinimalIndexAccessor(org.neo4j.kernel.api.impl.index.LuceneMinimalIndexAccessor) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) ReadOnlyIndexPartitionFactory(org.neo4j.kernel.api.impl.index.partition.ReadOnlyIndexPartitionFactory) IndexProvider(org.neo4j.kernel.api.index.IndexProvider) ByteBufferFactory(org.neo4j.io.memory.ByteBufferFactory) Values(org.neo4j.values.storable.Values) TokenHolder(org.neo4j.token.api.TokenHolder) JobScheduler(org.neo4j.scheduler.JobScheduler) IndexConfig(org.neo4j.internal.schema.IndexConfig) MemoryTracker(org.neo4j.memory.MemoryTracker) FulltextIndexSettings.isEventuallyConsistent(org.neo4j.kernel.api.impl.fulltext.FulltextIndexSettings.isEventuallyConsistent) Analyzer(org.apache.lucene.analysis.Analyzer) IOException(java.io.IOException) IndexDirectoryStructure(org.neo4j.kernel.api.index.IndexDirectoryStructure) StoreMigrationParticipant(org.neo4j.storageengine.migration.StoreMigrationParticipant) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) TokenHolders(org.neo4j.token.TokenHolders) TokenNotFoundException(org.neo4j.token.api.TokenNotFoundException) FulltextIndexSettings.createPropertyNames(org.neo4j.kernel.api.impl.fulltext.FulltextIndexSettings.createPropertyNames) NamedToken(org.neo4j.token.api.NamedToken) ValueGroup(org.neo4j.values.storable.ValueGroup) SchemaIndexMigrator(org.neo4j.storageengine.migration.SchemaIndexMigrator) IndexRef(org.neo4j.internal.schema.IndexRef) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) AnalyzerProvider(org.neo4j.graphdb.schema.AnalyzerProvider) TextValue(org.neo4j.values.storable.TextValue) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) TokenHolder(org.neo4j.token.api.TokenHolder) FulltextIndexSettings.createAnalyzer(org.neo4j.kernel.api.impl.fulltext.FulltextIndexSettings.createAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) NamedToken(org.neo4j.token.api.NamedToken) TokenNotFoundException(org.neo4j.token.api.TokenNotFoundException)

Aggregations

IOException (java.io.IOException)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Stream (java.util.stream.Stream)1 StringUtils (org.apache.commons.lang3.StringUtils)1 StringUtils.defaultIfEmpty (org.apache.commons.lang3.StringUtils.defaultIfEmpty)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 TokenNameLookup (org.neo4j.common.TokenNameLookup)1 Config (org.neo4j.configuration.Config)1 FulltextSettings (org.neo4j.configuration.FulltextSettings)1 DatabaseReadOnlyChecker (org.neo4j.configuration.helpers.DatabaseReadOnlyChecker)1 AnalyzerProvider (org.neo4j.graphdb.schema.AnalyzerProvider)1 Exceptions (org.neo4j.internal.helpers.Exceptions)1 InternalIndexState (org.neo4j.internal.kernel.api.InternalIndexState)1 IndexCapability (org.neo4j.internal.schema.IndexCapability)1 IndexConfig (org.neo4j.internal.schema.IndexConfig)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)1 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)1 IndexRef (org.neo4j.internal.schema.IndexRef)1