Skip to content

Commit

Permalink
Introduce setting for bloom indexed properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ragadeeshu committed Sep 12, 2017
1 parent abdc033 commit fbc12d9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
Expand Up @@ -413,6 +413,11 @@ public class GraphDatabaseSettings implements LoadableConfig
public static final Setting<Boolean> enable_native_schema_index = public static final Setting<Boolean> enable_native_schema_index =
setting( "unsupported.dbms.enable_native_schema_index", BOOLEAN, TRUE ); setting( "unsupported.dbms.enable_native_schema_index", BOOLEAN, TRUE );


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

// Store settings // Store settings
@Description( "Make Neo4j keep the logical transaction logs for being able to backup the database. " + @Description( "Make Neo4j keep the logical transaction logs for being able to backup the database. " +
"Can be used for specifying the threshold to prune logical logs after. For example \"10 days\" will " + "Can be used for specifying the threshold to prune logical logs after. For example \"10 days\" will " +
Expand Down
Expand Up @@ -27,10 +27,12 @@
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;


Expand All @@ -40,9 +42,9 @@ public class BloomIndex implements AutoCloseable
private final BloomLuceneIndex relationshipIndex; private final BloomLuceneIndex relationshipIndex;
private final String[] properties; private final String[] properties;


public BloomIndex( FileSystemAbstraction fileSystem, File file, String... properties ) throws IOException public BloomIndex( FileSystemAbstraction fileSystem, File file, Config config ) throws IOException
{ {
this.properties = properties; this.properties = config.get( GraphDatabaseSettings.bloom_indexed_properties ).toArray( new String[0] );
Factory<IndexWriterConfig> population = () -> IndexWriterConfigs.population( new EnglishAnalyzer() ); Factory<IndexWriterConfig> population = () -> IndexWriterConfigs.population( new EnglishAnalyzer() );
WritableIndexPartitionFactory partitionFactory = new WritableIndexPartitionFactory( population ); WritableIndexPartitionFactory partitionFactory = new WritableIndexPartitionFactory( population );


Expand Down
Expand Up @@ -29,6 +29,8 @@
import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType; import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.internal.GraphDatabaseAPI; import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.test.rule.DatabaseRule; import org.neo4j.test.rule.DatabaseRule;
import org.neo4j.test.rule.EmbeddedDatabaseRule; import org.neo4j.test.rule.EmbeddedDatabaseRule;
Expand All @@ -46,16 +48,18 @@ public class BloomLuceneIndexUpdaterTest
@ClassRule @ClassRule
public static TestDirectory testDirectory = TestDirectory.testDirectory( fileSystemRule ); public static TestDirectory testDirectory = TestDirectory.testDirectory( fileSystemRule );
@Rule @Rule
public DatabaseRule dbRule = new EmbeddedDatabaseRule(); public DatabaseRule dbRule = new EmbeddedDatabaseRule().startLazily();


private static final Label LABEL = Label.label( "label" ); private static final Label LABEL = Label.label( "label" );
private static final RelationshipType RELTYPE = RelationshipType.withName( "type" ); private static final RelationshipType RELTYPE = RelationshipType.withName( "type" );


@Test @Test
public void shouldFindNodeWithString() throws Exception public void shouldFindNodeWithString() throws Exception
{ {
GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); GraphDatabaseAPI db = dbRule.withSetting( GraphDatabaseSettings.bloom_indexed_properties, "prop" ).getGraphDatabaseAPI();
try ( BloomIndex bloomIndex = new BloomIndex( fileSystemRule, testDirectory.graphDbDir(), "prop" ) ) Config config = db.getDependencyResolver().resolveDependency( Config.class );
config.augment( GraphDatabaseSettings.bloom_indexed_properties, "prop" );
try ( BloomIndex bloomIndex = new BloomIndex( fileSystemRule, testDirectory.graphDbDir(), config ) )
{ {
db.registerTransactionEventHandler( bloomIndex.getUpdater() ); db.registerTransactionEventHandler( bloomIndex.getUpdater() );


Expand Down Expand Up @@ -88,8 +92,10 @@ public void shouldFindNodeWithString() throws Exception
@Test @Test
public void shouldRepresentPropertyChanges() throws Exception public void shouldRepresentPropertyChanges() throws Exception
{ {
GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); GraphDatabaseAPI db = dbRule.withSetting( GraphDatabaseSettings.bloom_indexed_properties, "prop" ).getGraphDatabaseAPI();
try ( BloomIndex bloomIndex = new BloomIndex( fileSystemRule, testDirectory.graphDbDir(), "prop" ) ) Config config = db.getDependencyResolver().resolveDependency( Config.class );
config.augment( GraphDatabaseSettings.bloom_indexed_properties, "prop" );
try ( BloomIndex bloomIndex = new BloomIndex( fileSystemRule, testDirectory.graphDbDir(), config ) )
{ {
db.registerTransactionEventHandler( bloomIndex.getUpdater() ); db.registerTransactionEventHandler( bloomIndex.getUpdater() );


Expand Down Expand Up @@ -136,8 +142,10 @@ public void shouldRepresentPropertyChanges() throws Exception
@Test @Test
public void shouldNotFindRemovedNodes() throws Exception public void shouldNotFindRemovedNodes() throws Exception
{ {
GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); GraphDatabaseAPI db = dbRule.withSetting( GraphDatabaseSettings.bloom_indexed_properties, "prop" ).getGraphDatabaseAPI();
try ( BloomIndex bloomIndex = new BloomIndex( fileSystemRule, testDirectory.graphDbDir(), "prop" ) ) Config config = db.getDependencyResolver().resolveDependency( Config.class );
config.augment( GraphDatabaseSettings.bloom_indexed_properties, "prop" );
try ( BloomIndex bloomIndex = new BloomIndex( fileSystemRule, testDirectory.graphDbDir(), config ) )
{ {
db.registerTransactionEventHandler( bloomIndex.getUpdater() ); db.registerTransactionEventHandler( bloomIndex.getUpdater() );


Expand Down Expand Up @@ -178,8 +186,10 @@ public void shouldNotFindRemovedNodes() throws Exception
@Test @Test
public void shouldOnlyIndexIndexedProperties() throws Exception public void shouldOnlyIndexIndexedProperties() throws Exception
{ {
GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); GraphDatabaseAPI db = dbRule.withSetting( GraphDatabaseSettings.bloom_indexed_properties, "prop" ).getGraphDatabaseAPI();
try ( BloomIndex bloomIndex = new BloomIndex( fileSystemRule, testDirectory.graphDbDir(), "prop" ) ) Config config = db.getDependencyResolver().resolveDependency( Config.class );
config.augment( GraphDatabaseSettings.bloom_indexed_properties, "prop" );
try ( BloomIndex bloomIndex = new BloomIndex( fileSystemRule, testDirectory.graphDbDir(), config ) )
{ {
db.registerTransactionEventHandler( bloomIndex.getUpdater() ); db.registerTransactionEventHandler( bloomIndex.getUpdater() );


Expand Down Expand Up @@ -212,8 +222,10 @@ public void shouldOnlyIndexIndexedProperties() throws Exception
@Test @Test
public void shouldSearchAcrossMultipleProperties() throws Exception public void shouldSearchAcrossMultipleProperties() throws Exception
{ {
GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); GraphDatabaseAPI db = dbRule.withSetting( GraphDatabaseSettings.bloom_indexed_properties, "prop, prop2" ).getGraphDatabaseAPI();
try ( BloomIndex bloomIndex = new BloomIndex( fileSystemRule, testDirectory.graphDbDir(), "prop", "prop2" ) ) Config config = db.getDependencyResolver().resolveDependency( Config.class );
config.augment( GraphDatabaseSettings.bloom_indexed_properties, "prop, prop2" );
try ( BloomIndex bloomIndex = new BloomIndex( fileSystemRule, testDirectory.graphDbDir(), config ) )
{ {
db.registerTransactionEventHandler( bloomIndex.getUpdater() ); db.registerTransactionEventHandler( bloomIndex.getUpdater() );


Expand Down Expand Up @@ -250,8 +262,10 @@ public void shouldSearchAcrossMultipleProperties() throws Exception
@Test @Test
public void shouldOrderResultsBasedOnRelevance() throws Exception public void shouldOrderResultsBasedOnRelevance() throws Exception
{ {
GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); GraphDatabaseAPI db = dbRule.withSetting( GraphDatabaseSettings.bloom_indexed_properties, "first, last" ).getGraphDatabaseAPI();
try ( BloomIndex bloomIndex = new BloomIndex( fileSystemRule, testDirectory.graphDbDir(), "first", "last" ) ) Config config = db.getDependencyResolver().resolveDependency( Config.class );
config.augment( GraphDatabaseSettings.bloom_indexed_properties, "first, last" );
try ( BloomIndex bloomIndex = new BloomIndex( fileSystemRule, testDirectory.graphDbDir(), config ) )
{ {
db.registerTransactionEventHandler( bloomIndex.getUpdater() ); db.registerTransactionEventHandler( bloomIndex.getUpdater() );


Expand Down Expand Up @@ -296,8 +310,10 @@ public void shouldOrderResultsBasedOnRelevance() throws Exception
@Test @Test
public void shouldDifferentiateNodesAndRelationships() throws Exception public void shouldDifferentiateNodesAndRelationships() throws Exception
{ {
GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); GraphDatabaseAPI db = dbRule.withSetting( GraphDatabaseSettings.bloom_indexed_properties, "prop" ).getGraphDatabaseAPI();
try ( BloomIndex bloomIndex = new BloomIndex( fileSystemRule, testDirectory.graphDbDir(), "prop" ) ) Config config = db.getDependencyResolver().resolveDependency( Config.class );
config.augment( GraphDatabaseSettings.bloom_indexed_properties, "prop" );
try ( BloomIndex bloomIndex = new BloomIndex( fileSystemRule, testDirectory.graphDbDir(), config ) )
{ {
db.registerTransactionEventHandler( bloomIndex.getUpdater() ); db.registerTransactionEventHandler( bloomIndex.getUpdater() );


Expand Down

0 comments on commit fbc12d9

Please sign in to comment.