Skip to content

Commit

Permalink
Move bloom addon settings to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
ragadeeshu committed Sep 12, 2017
1 parent b1eccb9 commit f116167
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 85 deletions.
Expand Up @@ -27,30 +27,27 @@
import java.nio.file.Paths; import java.nio.file.Paths;


import org.neo4j.function.Factory; import org.neo4j.function.Factory;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.api.impl.index.IndexWriterConfigs; import org.neo4j.kernel.api.impl.index.IndexWriterConfigs;
import org.neo4j.kernel.api.impl.index.builder.LuceneIndexStorageBuilder; import org.neo4j.kernel.api.impl.index.builder.LuceneIndexStorageBuilder;
import org.neo4j.kernel.api.impl.index.partition.WritableIndexPartitionFactory; import org.neo4j.kernel.api.impl.index.partition.WritableIndexPartitionFactory;
import org.neo4j.kernel.configuration.Config;


import static org.neo4j.kernel.api.impl.index.LuceneKernelExtensions.directoryFactory; import static org.neo4j.kernel.api.impl.index.LuceneKernelExtensions.directoryFactory;


public class FulltextFactory public class FulltextFactory
{ {
private final FileSystemAbstraction fileSystem; private final FileSystemAbstraction fileSystem;
private final String[] properties;
private final WritableIndexPartitionFactory partitionFactory; private final WritableIndexPartitionFactory partitionFactory;
private final Factory<IndexWriterConfig> population; private final Factory<IndexWriterConfig> population;
private final File storeDir; private final File storeDir;
private final Analyzer analyzer; private final Analyzer analyzer;


public LuceneFulltext createFulltextHelper( String identifier, FULLTEXT_HELPER_TYPE type ) public LuceneFulltext createFulltextHelper( String identifier, FULLTEXT_HELPER_TYPE type, String[] properties )
{ {
LuceneIndexStorageBuilder storageBuilder = LuceneIndexStorageBuilder.create(); LuceneIndexStorageBuilder storageBuilder = LuceneIndexStorageBuilder.create();
storageBuilder.withFileSystem( fileSystem ).withIndexIdentifier( identifier ).withDirectoryFactory( storageBuilder.withFileSystem( fileSystem ).withIndexIdentifier( identifier ).withDirectoryFactory(
directoryFactory( false, this.fileSystem ) ).withIndexRootFolder( Paths.get( this.storeDir.getAbsolutePath(), "fulltextHelper" ).toFile() ); directoryFactory( false, this.fileSystem ) ).withIndexRootFolder( Paths.get( this.storeDir.getAbsolutePath(), "fulltextHelper" ).toFile() );
return new LuceneFulltext( storageBuilder.build(), partitionFactory, this.properties, analyzer, identifier, type ); return new LuceneFulltext( storageBuilder.build(), partitionFactory, properties, analyzer, identifier, type );
} }


public enum FULLTEXT_HELPER_TYPE public enum FULLTEXT_HELPER_TYPE
Expand All @@ -59,19 +56,10 @@ public enum FULLTEXT_HELPER_TYPE
RELATIONSHIPS RELATIONSHIPS
} }


public FulltextFactory( FileSystemAbstraction fileSystem, File storeDir, Config config ) throws IOException public FulltextFactory( FileSystemAbstraction fileSystem, File storeDir, Analyzer analyzer ) throws IOException
{ {
this.analyzer = analyzer;
this.fileSystem = fileSystem; this.fileSystem = fileSystem;
this.properties = config.get( GraphDatabaseSettings.bloom_indexed_properties ).toArray( new String[0] );
try
{
Class configuredAnalayzer = Class.forName( config.get( GraphDatabaseSettings.bloom_analyzer ) );
analyzer = (Analyzer) configuredAnalayzer.newInstance();
}
catch ( Exception e )
{
throw new RuntimeException( "Could not create the configured analyzer", e );
}
population = () -> IndexWriterConfigs.population( analyzer ); population = () -> IndexWriterConfigs.population( analyzer );
partitionFactory = new WritableIndexPartitionFactory( population ); partitionFactory = new WritableIndexPartitionFactory( population );
this.storeDir = storeDir; this.storeDir = storeDir;
Expand Down
Expand Up @@ -19,6 +19,8 @@
*/ */
package org.neo4j.kernel.api.impl.fulltext.integrations.bloom; package org.neo4j.kernel.api.impl.fulltext.integrations.bloom;


import org.apache.lucene.analysis.Analyzer;

import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;


Expand Down Expand Up @@ -53,11 +55,23 @@ public BloomKernelExtension( FileSystemAbstraction fileSystemAbstraction, File s
@Override @Override
public void init() throws IOException, ProcedureException public void init() throws IOException, ProcedureException
{ {
String[] properties = config.get( LoadableBloomFulltextConfig.bloom_indexed_properties ).toArray( new String[0] );
Analyzer analyzer;
try
{
Class configuredAnalayzer = Class.forName( config.get( LoadableBloomFulltextConfig.bloom_analyzer ) );
analyzer = (Analyzer) configuredAnalayzer.newInstance();
}
catch ( Exception e )
{
throw new RuntimeException( "Could not create the configured analyzer", e );
}

FulltextProvider provider = FulltextProvider.instance( db ); FulltextProvider provider = FulltextProvider.instance( db );
fulltextFactory = new FulltextFactory( fileSystemAbstraction, storeDir, config ); fulltextFactory = new FulltextFactory( fileSystemAbstraction, storeDir, analyzer );
LuceneFulltext nodes = fulltextFactory.createFulltextHelper( "bloomNodes", FulltextFactory.FULLTEXT_HELPER_TYPE.NODES ); LuceneFulltext nodes = fulltextFactory.createFulltextHelper( "bloomNodes", FulltextFactory.FULLTEXT_HELPER_TYPE.NODES, properties );
LuceneFulltext relationships = LuceneFulltext relationships =
fulltextFactory.createFulltextHelper( "bloomRelationships", FulltextFactory.FULLTEXT_HELPER_TYPE.RELATIONSHIPS ); fulltextFactory.createFulltextHelper( "bloomRelationships", FulltextFactory.FULLTEXT_HELPER_TYPE.RELATIONSHIPS, properties );
provider.register( nodes ); provider.register( nodes );
provider.register( relationships ); provider.register( relationships );


Expand Down
Expand Up @@ -37,15 +37,15 @@
public class BloomProcedure extends CallableProcedure.BasicProcedure public class BloomProcedure extends CallableProcedure.BasicProcedure
{ {
private static final String PROCEDURE_NAME = "bloomFulltext"; private static final String PROCEDURE_NAME = "bloomFulltext";

private static final String[] PROCEDURE_NAMESPACE = {"db", "fulltext"};
private static final String[] PROCEDURE_NAMESPACE = {"dbms", "fulltext"}; public static final String OUTPUT_NAME = "entityid";
private final LuceneFulltext luceneFulltext; private final LuceneFulltext luceneFulltext;
private String type; private String type;


BloomProcedure( String type, LuceneFulltext luceneFulltext ) BloomProcedure( String type, LuceneFulltext luceneFulltext )
{ {
super( procedureSignature( new QualifiedName( PROCEDURE_NAMESPACE, PROCEDURE_NAME + type ) ).in( "terms", super( procedureSignature( new QualifiedName( PROCEDURE_NAMESPACE, PROCEDURE_NAME + type ) ).in( "terms",
Neo4jTypes.NTList( Neo4jTypes.NTString ) ).out( "entityid", Neo4jTypes.NTInteger ).description( Neo4jTypes.NTList( Neo4jTypes.NTString ) ).out( OUTPUT_NAME, Neo4jTypes.NTInteger ).description(
String.format( "Queries the bloom index for %s.", type ) ).build() ); String.format( "Queries the bloom index for %s.", type ) ).build() );
this.luceneFulltext = luceneFulltext; this.luceneFulltext = luceneFulltext;
this.type = type; this.type = type;
Expand Down
@@ -0,0 +1,27 @@
package org.neo4j.kernel.api.impl.fulltext.integrations.bloom;

import java.util.List;

import org.neo4j.configuration.Description;
import org.neo4j.configuration.Internal;
import org.neo4j.configuration.LoadableConfig;
import org.neo4j.graphdb.config.Setting;

import static org.neo4j.kernel.configuration.Settings.NO_DEFAULT;
import static org.neo4j.kernel.configuration.Settings.STRING;
import static org.neo4j.kernel.configuration.Settings.STRING_LIST;
import static org.neo4j.kernel.configuration.Settings.setting;

public class LoadableBloomFulltextConfig implements LoadableConfig
{

// Bloom index
@Internal
public static final Setting<List<String>> bloom_indexed_properties = setting( "unsupported.dbms.bloom_indexed_properties", STRING_LIST, NO_DEFAULT );

@Description( "Define the analyzer to use for the bloom index. Expects the fully qualified classname of the analyzer to use" )
@Internal
public static final Setting<String> bloom_analyzer =
setting( "unsupported.dbms.bloom_analyzer", STRING, "org.apache.lucene.analysis.standard.StandardAnalyzer" );

}
@@ -0,0 +1 @@
org.neo4j.kernel.api.impl.fulltext.integrations.bloom.LoadableBloomFulltextConfig

0 comments on commit f116167

Please sign in to comment.