Skip to content

Commit

Permalink
Fulltext addon removal of unused code + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ragadeeshu committed Sep 12, 2017
1 parent 4c208da commit 8dc8c7e
Show file tree
Hide file tree
Showing 18 changed files with 143 additions and 394 deletions.
Expand Up @@ -203,4 +203,14 @@ public List<AbstractIndexPartition> getPartitions()
{
return luceneIndex.getPartitions();
}

public boolean hasSinglePartition( List<AbstractIndexPartition> partitions )
{
return luceneIndex.hasSinglePartition( partitions );
}

public AbstractIndexPartition getFirstPartition( List<AbstractIndexPartition> partitions )
{
return luceneIndex.getFirstPartition( partitions );
}
}
Expand Up @@ -27,6 +27,7 @@
import java.io.IOException;
import java.util.List;

import org.neo4j.kernel.api.impl.index.WritableAbstractDatabaseIndex;
import org.neo4j.kernel.api.impl.index.partition.AbstractIndexPartition;
import org.neo4j.kernel.api.impl.schema.WritableDatabaseSchemaIndex;

Expand All @@ -40,14 +41,14 @@
*/
public class PartitionedIndexWriter implements LuceneIndexWriter
{
private final WritableDatabaseSchemaIndex index;
private final WritableAbstractDatabaseIndex index;

// by default we still keep a spare of 10% to the maximum partition size: During concurrent updates
// it could happen that 2 threads reserve space in a partition (without claiming it by doing addDocument):
private final Integer MAXIMUM_PARTITION_SIZE = Integer.getInteger( "luceneSchemaIndex.maxPartitionSize",
IndexWriter.MAX_DOCS - (IndexWriter.MAX_DOCS / 10) );

public PartitionedIndexWriter( WritableDatabaseSchemaIndex index ) throws IOException
public PartitionedIndexWriter( WritableAbstractDatabaseIndex index ) throws IOException
{
this.index = index;
}
Expand Down
6 changes: 3 additions & 3 deletions enterprise/fulltext-addon/pom.xml
Expand Up @@ -10,15 +10,15 @@
<relativePath>../..</relativePath>
</parent>

<artifactId>neo4j-fulltext-helper</artifactId>
<artifactId>neo4j-fulltext-addon</artifactId>
<version>3.3.0-SNAPSHOT</version>

<name>Neo4j - Bloom index</name>
<name>Neo4j - Fulltext add-on</name>
<description>Fulltext helper addon for neo4j</description>
<packaging>jar</packaging>

<scm>
<url>https://github.com/neo4j/neo4j/tree/3.3/enterprise/fulltext-helper</url>
<url>https://github.com/neo4j/neo4j/tree/3.3/enterprise/fulltext-addon</url>
</scm>

<licenses>
Expand Down
Expand Up @@ -36,7 +36,7 @@

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

public class FulltextHelperFactory
public class FulltextFactory
{
private final FileSystemAbstraction fileSystem;
private final String[] properties;
Expand All @@ -59,7 +59,7 @@ public enum FULLTEXT_HELPER_TYPE
RELATIONSHIPS
}

public FulltextHelperFactory( FileSystemAbstraction fileSystem, File storeDir, Config config ) throws IOException
public FulltextFactory( FileSystemAbstraction fileSystem, File storeDir, Config config ) throws IOException
{
this.fileSystem = fileSystem;
this.properties = config.get( GraphDatabaseSettings.bloom_indexed_properties ).toArray( new String[0] );
Expand Down

This file was deleted.

Expand Up @@ -28,34 +28,34 @@

import org.neo4j.graphdb.GraphDatabaseService;

public class FulltextHelperProvider implements AutoCloseable
public class FulltextProvider implements AutoCloseable
{
private static FulltextHelperProvider instance;
private static FulltextProvider instance;
private final GraphDatabaseService db;
private final FulltextHelperTransactionEventUpdater fulltextHelperTransactionEventUpdater;
private final FulltextTransactionEventUpdater fulltextTransactionEventUpdater;
private boolean closed;
private Set<String> nodeProperties;
private Set<String> relationshipProperties;
private Map<String,LuceneFulltextHelper> nodeIndices;
private Map<String,LuceneFulltextHelper> relationshipIndices;

private FulltextHelperProvider( GraphDatabaseService db )
private FulltextProvider( GraphDatabaseService db )
{
this.db = db;
closed = false;
fulltextHelperTransactionEventUpdater = new FulltextHelperTransactionEventUpdater( this );
db.registerTransactionEventHandler( fulltextHelperTransactionEventUpdater );
fulltextTransactionEventUpdater = new FulltextTransactionEventUpdater( this );
db.registerTransactionEventHandler( fulltextTransactionEventUpdater );
nodeProperties = new HashSet<>();
relationshipProperties = new HashSet<>();
nodeIndices = new HashMap<>();
relationshipIndices = new HashMap<>();
}

public static synchronized FulltextHelperProvider instance( GraphDatabaseService db )
public static synchronized FulltextProvider instance( GraphDatabaseService db )
{
if ( instance == null || instance.closed )
{
instance = new FulltextHelperProvider( db );
instance = new FulltextProvider( db );
}
return instance;
}
Expand All @@ -66,7 +66,7 @@ public synchronized void close()
if ( !closed )
{
closed = true;
db.unregisterTransactionEventHandler( fulltextHelperTransactionEventUpdater );
db.unregisterTransactionEventHandler( fulltextTransactionEventUpdater );
nodeIndices.values().forEach( luceneFulltextHelper ->
{
try
Expand Down Expand Up @@ -95,7 +95,7 @@ public synchronized void close()
public synchronized void register( LuceneFulltextHelper fulltextHelper ) throws IOException
{
fulltextHelper.open();
if ( fulltextHelper.getType() == FulltextHelperFactory.FULLTEXT_HELPER_TYPE.NODES )
if ( fulltextHelper.getType() == FulltextFactory.FULLTEXT_HELPER_TYPE.NODES )
{
nodeIndices.put( fulltextHelper.getIdentifier(), fulltextHelper );
nodeProperties.addAll( fulltextHelper.getProperties() );
Expand All @@ -117,19 +117,19 @@ public String[] getRelationshipProperties()
return relationshipProperties.toArray( new String[0] );
}

public Set<WritableDatabaseBloomIndex> nodeIndices()
public Set<WritableDatabaseFulltext> nodeIndices()
{
return nodeIndices.values().stream().map( WritableDatabaseBloomIndex::new ).collect( Collectors.toSet() );
return nodeIndices.values().stream().map( WritableDatabaseFulltext::new ).collect( Collectors.toSet() );
}

public Set<WritableDatabaseBloomIndex> relationshipIndices()
public Set<WritableDatabaseFulltext> relationshipIndices()
{
return relationshipIndices.values().stream().map( WritableDatabaseBloomIndex::new ).collect( Collectors.toSet() );
return relationshipIndices.values().stream().map( WritableDatabaseFulltext::new ).collect( Collectors.toSet() );
}

public BloomIndexReader getReader( String identifier, FulltextHelperFactory.FULLTEXT_HELPER_TYPE type ) throws IOException
public FulltextReader getReader( String identifier, FulltextFactory.FULLTEXT_HELPER_TYPE type ) throws IOException
{
if ( type == FulltextHelperFactory.FULLTEXT_HELPER_TYPE.NODES )
if ( type == FulltextFactory.FULLTEXT_HELPER_TYPE.NODES )
{
return nodeIndices.get( identifier ).getIndexReader();
}
Expand Down
Expand Up @@ -21,7 +21,7 @@

import org.neo4j.collection.primitive.PrimitiveLongIterator;

public interface BloomIndexReader extends AutoCloseable
public interface FulltextReader extends AutoCloseable
{
PrimitiveLongIterator query( String... query );
}
Expand Up @@ -34,20 +34,20 @@
import org.neo4j.graphdb.event.TransactionData;
import org.neo4j.graphdb.event.TransactionEventHandler;

public class FulltextHelperTransactionEventUpdater implements TransactionEventHandler<Object>
public class FulltextTransactionEventUpdater implements TransactionEventHandler<Object>
{

private FulltextHelperProvider fulltextHelperProvider;
private FulltextProvider fulltextProvider;

public FulltextHelperTransactionEventUpdater( FulltextHelperProvider fulltextHelperProvider )
public FulltextTransactionEventUpdater( FulltextProvider fulltextProvider )
{
this.fulltextHelperProvider = fulltextHelperProvider;
this.fulltextProvider = fulltextProvider;
}

@Override
public Object beforeCommit( TransactionData data ) throws Exception
{
String[] nodeProperties = fulltextHelperProvider.getNodeProperties();
String[] nodeProperties = fulltextProvider.getNodeProperties();
Map<Long,Map<String,Object>> nodeMap = new HashMap<Long,Map<String,Object>>();
data.removedNodeProperties().forEach( propertyEntry ->
{
Expand All @@ -63,7 +63,7 @@ public Object beforeCommit( TransactionData data ) throws Exception
data.assignedNodeProperties().forEach(
propertyEntry -> nodeMap.put( propertyEntry.entity().getId(), propertyEntry.entity().getProperties( nodeProperties ) ) );

String[] relationshipProperties = fulltextHelperProvider.getRelationshipProperties();
String[] relationshipProperties = fulltextProvider.getRelationshipProperties();
Map<Long,Map<String,Object>> relationshipMap = new HashMap<Long,Map<String,Object>>();
data.removedRelationshipProperties().forEach( propertyEntry ->
{
Expand All @@ -87,15 +87,15 @@ public void afterCommit( TransactionData data, Object state )
//update node indices
try
{
for ( WritableDatabaseBloomIndex nodeIndex : fulltextHelperProvider.nodeIndices() )
for ( WritableDatabaseFulltext nodeIndex : fulltextProvider.nodeIndices() )
{
Map<Long,Map<String,Object>> nodeMap = ((Map<Long,Map<String,Object>>[]) state)[0];
removePropertyData( data.removedNodeProperties(), nodeMap, nodeIndex );
updatePropertyData( nodeMap, nodeIndex );
refreshIndex( nodeIndex );
}
//update relationship indices
for ( WritableDatabaseBloomIndex relationshipIndex : fulltextHelperProvider.relationshipIndices() )
for ( WritableDatabaseFulltext relationshipIndex : fulltextProvider.relationshipIndices() )
{
Map<Long,Map<String,Object>> relationshipMap = ((Map<Long,Map<String,Object>>[]) state)[1];
removePropertyData( data.removedRelationshipProperties(), relationshipMap, relationshipIndex );
Expand All @@ -109,7 +109,7 @@ public void afterCommit( TransactionData data, Object state )
}
}

private <E extends Entity> void updatePropertyData( Map<Long,Map<String,Object>> state, WritableDatabaseBloomIndex index ) throws IOException
private <E extends Entity> void updatePropertyData( Map<Long,Map<String,Object>> state, WritableDatabaseFulltext index ) throws IOException
{
for ( Map.Entry<Long,Map<String,Object>> stateEntry : state.entrySet() )
{
Expand All @@ -122,15 +122,15 @@ private <E extends Entity> void updatePropertyData( Map<Long,Map<String,Object>>
Collectors.toMap( entry -> entry.getKey(), entry -> entry.getValue() ) );
if ( !allProperties.isEmpty() )
{
Document document = FulltextHelperDocumentStructure.documentRepresentingProperties( entityId, allProperties );
index.getIndexWriter().updateDocument( FulltextHelperDocumentStructure.newTermForChangeOrRemove( entityId ), document );
Document document = LuceneFulltextDocumentStructure.documentRepresentingProperties( entityId, allProperties );
index.getIndexWriter().updateDocument( LuceneFulltextDocumentStructure.newTermForChangeOrRemove( entityId ), document );
}
}
}
}

private <E extends Entity> void removePropertyData( Iterable<PropertyEntry<E>> propertyEntries, Map<Long,Map<String,Object>> state,
WritableDatabaseBloomIndex index ) throws IOException
WritableDatabaseFulltext index ) throws IOException
{
for ( PropertyEntry<E> propertyEntry : propertyEntries )
{
Expand All @@ -140,13 +140,13 @@ private <E extends Entity> void removePropertyData( Iterable<PropertyEntry<E>> p
Map<String,Object> allProperties = state.get( entityId );
if ( allProperties == null || allProperties.isEmpty() )
{
index.getIndexWriter().deleteDocuments( FulltextHelperDocumentStructure.newTermForChangeOrRemove( entityId ) );
index.getIndexWriter().deleteDocuments( LuceneFulltextDocumentStructure.newTermForChangeOrRemove( entityId ) );
}
}
}
}

private void refreshIndex( WritableDatabaseBloomIndex index )
private void refreshIndex( WritableDatabaseFulltext index )
{
try
{
Expand Down
Expand Up @@ -33,15 +33,14 @@
import org.neo4j.values.storable.Values;

import static org.apache.lucene.document.Field.Store.NO;
import static org.apache.lucene.document.Field.Store.YES;

class FulltextHelperDocumentStructure
class LuceneFulltextDocumentStructure
{
static final String ID_KEY = "id";

private static final ThreadLocal<DocWithId> perThreadDocument = ThreadLocal.withInitial( DocWithId::new );

private FulltextHelperDocumentStructure()
private LuceneFulltextDocumentStructure()
{
}

Expand All @@ -61,7 +60,7 @@ public static Document documentRepresentingProperties( long id, Map<String,Objec

static Field encodeValueField( String propertyKey, Value value )
{
return BloomFieldEncoding.encodeField( propertyKey, value );
return LuceneFulltextFieldEncoding.encodeField( propertyKey, value );
}

private static class DocWithId
Expand Down
Expand Up @@ -24,7 +24,7 @@

import org.neo4j.values.storable.Value;

class BloomFieldEncoding
class LuceneFulltextFieldEncoding
{
public static Field encodeField( String name, Value value )
{
Expand Down

0 comments on commit 8dc8c7e

Please sign in to comment.