Skip to content

Commit

Permalink
Fulltext addon cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ragadeeshu committed Sep 12, 2017
1 parent 8dc8c7e commit b1eccb9
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 63 deletions.
Expand Up @@ -45,12 +45,12 @@ public class FulltextFactory
private final File storeDir;
private final Analyzer analyzer;

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

public enum FULLTEXT_HELPER_TYPE
Expand Down
Expand Up @@ -36,8 +36,8 @@ public class FulltextProvider implements AutoCloseable
private boolean closed;
private Set<String> nodeProperties;
private Set<String> relationshipProperties;
private Map<String,LuceneFulltextHelper> nodeIndices;
private Map<String,LuceneFulltextHelper> relationshipIndices;
private Map<String,LuceneFulltext> nodeIndices;
private Map<String,LuceneFulltext> relationshipIndices;

private FulltextProvider( GraphDatabaseService db )
{
Expand Down Expand Up @@ -92,7 +92,7 @@ public synchronized void close()
}
}

public synchronized void register( LuceneFulltextHelper fulltextHelper ) throws IOException
public synchronized void register( LuceneFulltext fulltextHelper ) throws IOException
{
fulltextHelper.open();
if ( fulltextHelper.getType() == FulltextFactory.FULLTEXT_HELPER_TYPE.NODES )
Expand Down
Expand Up @@ -40,7 +40,7 @@

import static java.util.Collections.singletonMap;

public class LuceneFulltextHelper extends AbstractLuceneIndex
public class LuceneFulltext extends AbstractLuceneIndex
{

private static final String KEY_STATUS = "status";
Expand All @@ -52,7 +52,7 @@ public class LuceneFulltextHelper extends AbstractLuceneIndex
private final TaskCoordinator taskCoordinator = new TaskCoordinator( 10, TimeUnit.MILLISECONDS );
private final Set<String> properties;

LuceneFulltextHelper( PartitionedIndexStorage indexStorage, IndexPartitionFactory partitionFactory, String[] properties, Analyzer analyzer,
LuceneFulltext( PartitionedIndexStorage indexStorage, IndexPartitionFactory partitionFactory, String[] properties, Analyzer analyzer,
String identifier, FulltextFactory.FULLTEXT_HELPER_TYPE type )
{
super( indexStorage, partitionFactory );
Expand All @@ -74,7 +74,7 @@ public boolean equals( Object o )
return false;
}

LuceneFulltextHelper that = (LuceneFulltextHelper) o;
LuceneFulltext that = (LuceneFulltext) o;

if ( !identifier.equals( that.identifier ) )
{
Expand Down
Expand Up @@ -46,7 +46,7 @@ class SimpleFulltextReader implements FulltextReader
{
private final PartitionSearcher partitionSearcher;
private final Analyzer analyzer;
private String[] properties;
private final String[] properties;

SimpleFulltextReader( PartitionSearcher partitionSearcher, String[] properties, Analyzer analyzer )
{
Expand Down
Expand Up @@ -27,19 +27,19 @@
import org.neo4j.kernel.api.impl.index.partition.AbstractIndexPartition;
import org.neo4j.kernel.api.impl.schema.writer.PartitionedIndexWriter;

class WritableDatabaseFulltext extends WritableAbstractDatabaseIndex<LuceneFulltextHelper>
class WritableDatabaseFulltext extends WritableAbstractDatabaseIndex<LuceneFulltext>
{
private LuceneFulltextHelper luceneFulltextHelper;
private final LuceneFulltext luceneFulltext;

WritableDatabaseFulltext( LuceneFulltextHelper luceneFulltextHelper )
WritableDatabaseFulltext( LuceneFulltext luceneFulltext )
{
super( luceneFulltextHelper );
this.luceneFulltextHelper = luceneFulltextHelper;
super( luceneFulltext );
this.luceneFulltext = luceneFulltext;
}

public PartitionedIndexWriter getIndexWriter() throws IOException
{
return luceneFulltextHelper.getIndexWriter( this );
return luceneFulltext.getIndexWriter( this );
}

public boolean hasSinglePartition( List<AbstractIndexPartition> partitions )
Expand Down
Expand Up @@ -27,7 +27,7 @@
import org.neo4j.kernel.api.exceptions.ProcedureException;
import org.neo4j.kernel.api.impl.fulltext.FulltextFactory;
import org.neo4j.kernel.api.impl.fulltext.FulltextProvider;
import org.neo4j.kernel.api.impl.fulltext.LuceneFulltextHelper;
import org.neo4j.kernel.api.impl.fulltext.LuceneFulltext;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.proc.Procedures;
import org.neo4j.kernel.lifecycle.LifecycleAdapter;
Expand Down Expand Up @@ -55,8 +55,8 @@ public void init() throws IOException, ProcedureException
{
FulltextProvider provider = FulltextProvider.instance( db );
fulltextFactory = new FulltextFactory( fileSystemAbstraction, storeDir, config );
LuceneFulltextHelper nodes = fulltextFactory.createFulltextHelper( "bloomNodes", FulltextFactory.FULLTEXT_HELPER_TYPE.NODES );
LuceneFulltextHelper relationships =
LuceneFulltext nodes = fulltextFactory.createFulltextHelper( "bloomNodes", FulltextFactory.FULLTEXT_HELPER_TYPE.NODES );
LuceneFulltext relationships =
fulltextFactory.createFulltextHelper( "bloomRelationships", FulltextFactory.FULLTEXT_HELPER_TYPE.RELATIONSHIPS );
provider.register( nodes );
provider.register( relationships );
Expand Down
Expand Up @@ -26,7 +26,7 @@
import org.neo4j.kernel.api.exceptions.ProcedureException;
import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.api.impl.fulltext.FulltextReader;
import org.neo4j.kernel.api.impl.fulltext.LuceneFulltextHelper;
import org.neo4j.kernel.api.impl.fulltext.LuceneFulltext;
import org.neo4j.kernel.api.proc.CallableProcedure;
import org.neo4j.kernel.api.proc.Context;
import org.neo4j.kernel.api.proc.Neo4jTypes;
Expand All @@ -39,23 +39,23 @@ public class BloomProcedure extends CallableProcedure.BasicProcedure
private static final String PROCEDURE_NAME = "bloomFulltext";

private static final String[] PROCEDURE_NAMESPACE = {"dbms", "fulltext"};
private final LuceneFulltextHelper luceneFulltextHelper;
private final LuceneFulltext luceneFulltext;
private String type;

BloomProcedure( String type, LuceneFulltextHelper luceneFulltextHelper )
BloomProcedure( String type, LuceneFulltext luceneFulltext )
{
super( procedureSignature( new QualifiedName( PROCEDURE_NAMESPACE, PROCEDURE_NAME + type ) ).in( "terms",
Neo4jTypes.NTList( Neo4jTypes.NTString ) ).out( "entityid", Neo4jTypes.NTInteger ).description(
String.format( "Queries the bloom index for %s.", type ) ).build() );
this.luceneFulltextHelper = luceneFulltextHelper;
this.luceneFulltext = luceneFulltext;
this.type = type;
}

@Override
public RawIterator<Object[],ProcedureException> apply( Context ctx, Object[] input ) throws ProcedureException
{
String[] query = Arrays.stream( input ).map( Object::toString ).toArray( String[]::new );
try ( FulltextReader indexReader = luceneFulltextHelper.getIndexReader() )
try ( FulltextReader indexReader = luceneFulltext.getIndexReader() )
{
PrimitiveLongIterator primitiveLongIterator = indexReader.query( query );
return new RawIterator<Object[],ProcedureException>()
Expand Down
Expand Up @@ -42,7 +42,7 @@
import static org.junit.Assert.assertFalse;
import static org.neo4j.kernel.api.impl.fulltext.FulltextFactory.FULLTEXT_HELPER_TYPE;

public class LuceneFulltextHelperUpdaterTest
public class LuceneFulltextUpdaterTest
{
@ClassRule
public static FileSystemRule fileSystemRule = new DefaultFileSystemRule();
Expand Down Expand Up @@ -70,10 +70,10 @@ public void shouldFindNodeWithString() throws Exception
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( LABEL );
firstID = node.getId();
node.setProperty( "prop", "Hello. Hello again." );
Node node2 = db.createNode( LABEL );
firstID = node.getId();
secondID = node2.getId();
node.setProperty( "prop", "Hello. Hello again." );
node2.setProperty( "prop", "A zebroid (also zedonk, zorse, zebra mule, zonkey, and zebmule) is the offspring of any cross " +
"between a zebra and any other equine: essentially, a zebra hybrid." );

Expand Down Expand Up @@ -108,23 +108,23 @@ public void shouldFindNodeWithNumber() throws Exception
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( LABEL );
firstID = node.getId();
node.setProperty( "prop", 1 );
Node node2 = db.createNode( LABEL );
firstID = node.getId();
secondID = node2.getId();
node.setProperty( "prop", 1 );
node2.setProperty( "prop", 234 );

tx.success();
}

try ( FulltextReader reader = provider.getReader( "bloomNodes", FULLTEXT_HELPER_TYPE.NODES ) )
{
PrimitiveLongIterator one = reader.query( "1" );
assertEquals( firstID, one.next() );
assertFalse( one.hasNext() );
PrimitiveLongIterator twohundredthirtyfour = reader.query( "234" );
assertEquals( secondID, twohundredthirtyfour.next() );
assertFalse( twohundredthirtyfour.hasNext() );
PrimitiveLongIterator node1prop = reader.query( "1" );
assertEquals( firstID, node1prop.next() );
assertFalse( node1prop.hasNext() );
PrimitiveLongIterator node2prop = reader.query( "234" );
assertEquals( secondID, node2prop.next() );
assertFalse( node2prop.hasNext() );
}
}
}
Expand All @@ -145,10 +145,10 @@ public void shouldFindNodeWithBoolean() throws Exception
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( LABEL );
firstID = node.getId();
node.setProperty( "prop", true );
Node node2 = db.createNode( LABEL );
firstID = node.getId();
secondID = node2.getId();
node.setProperty( "prop", true );
node2.setProperty( "prop", false );

tx.success();
Expand Down Expand Up @@ -182,10 +182,10 @@ public void shouldFindNodeWithArrays() throws Exception
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( LABEL );
firstID = node.getId();
node.setProperty( "prop", new String[]{"hello", "I", "live", "here"} );
Node node2 = db.createNode( LABEL );
firstID = node.getId();
secondID = node2.getId();
node.setProperty( "prop", new String[]{"hello", "I", "live", "here"} );
node2.setProperty( "prop", new int[]{1, 27, 48} );

tx.success();
Expand Down Expand Up @@ -219,10 +219,10 @@ public void shouldRepresentPropertyChanges() throws Exception
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( LABEL );
firstID = node.getId();
node.setProperty( "prop", "Hello. Hello again." );
Node node2 = db.createNode( LABEL );
firstID = node.getId();
secondID = node2.getId();
node.setProperty( "prop", "Hello. Hello again." );
node2.setProperty( "prop", "A zebroid (also zedonk, zorse, zebra mule, zonkey, and zebmule) is the offspring of any cross " +
"between a zebra and any other equine: essentially, a zebra hybrid." );

Expand Down Expand Up @@ -270,10 +270,10 @@ public void shouldNotFindRemovedNodes() throws Exception
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( LABEL );
firstID = node.getId();
node.setProperty( "prop", "Hello. Hello again." );
Node node2 = db.createNode( LABEL );
firstID = node.getId();
secondID = node2.getId();
node.setProperty( "prop", "Hello. Hello again." );
node2.setProperty( "prop", "A zebroid (also zedonk, zorse, zebra mule, zonkey, and zebmule) is the offspring of any cross " +
"between a zebra and any other equine: essentially, a zebra hybrid." );

Expand Down Expand Up @@ -316,10 +316,10 @@ public void shouldNotFindRemovedProperties() throws Exception
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( LABEL );
firstID = node.getId();
Node node2 = db.createNode( LABEL );
secondID = node2.getId();
Node node3 = db.createNode( LABEL );
firstID = node.getId();
secondID = node2.getId();
thirdID = node3.getId();

node.setProperty( "prop", "Hello. Hello again." );
Expand Down Expand Up @@ -376,14 +376,13 @@ public void shouldOnlyIndexIndexedProperties() throws Exception
provider.register( fulltextFactory.createFulltextHelper( "bloomNodes", FULLTEXT_HELPER_TYPE.NODES ) );

long firstID;
long secondID;
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( LABEL );
Node node2 = db.createNode( LABEL );
firstID = node.getId();
node.setProperty( "prop", "Hello. Hello again." );
node.setProperty( "prop2", "zebra" );
Node node2 = db.createNode( LABEL );
node2.setProperty( "prop2", "zebra" );
node2.setProperty( "prop3", "hello" );

Expand Down Expand Up @@ -418,14 +417,14 @@ public void shouldSearchAcrossMultipleProperties() throws Exception
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( LABEL );
firstID = node.getId();
node.setProperty( "prop", "Tomtar tomtar oftsat i tomteutstyrsel." );
Node node2 = db.createNode( LABEL );
Node node3 = db.createNode( LABEL );
firstID = node.getId();
secondID = node2.getId();
thirdID = node3.getId();
node.setProperty( "prop", "Tomtar tomtar oftsat i tomteutstyrsel." );
node2.setProperty( "prop", "Olof och Hans tomtar med karl som tomtar ofta" );
node2.setProperty( "prop2", "karl tomtar" );
Node node3 = db.createNode( LABEL );
thirdID = node3.getId();
node3.setProperty( "prop", "Tomtar som inte tomtar ser upp till tomtar som tomtar." );

tx.success();
Expand Down Expand Up @@ -461,19 +460,19 @@ public void shouldOrderResultsBasedOnRelevance() throws Exception
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( LABEL );
Node node2 = db.createNode( LABEL );
Node node3 = db.createNode( LABEL );
Node node4 = db.createNode( LABEL );
firstID = node.getId();
secondID = node2.getId();
thirdID = node3.getId();
fourthID = node4.getId();
node.setProperty( "first", "Full" );
node.setProperty( "last", "Hanks" );
Node node2 = db.createNode( LABEL );
secondID = node2.getId();
node2.setProperty( "first", "Tom" );
node2.setProperty( "last", "Hunk" );
Node node3 = db.createNode( LABEL );
thirdID = node3.getId();
node3.setProperty( "first", "Tom" );
node3.setProperty( "last", "Hanks" );
Node node4 = db.createNode( LABEL );
fourthID = node4.getId();
node4.setProperty( "first", "Tom Hanks" );
node4.setProperty( "last", "Tom Hanks" );

Expand Down Expand Up @@ -511,17 +510,17 @@ public void shouldDifferentiateNodesAndRelationships() throws Exception
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( LABEL );
firstNodeID = node.getId();
node.setProperty( "prop", "Hello. Hello again." );
Node node2 = db.createNode( LABEL );
Relationship rel1 = node.createRelationshipTo( node2, RELTYPE );
Relationship rel2 = node2.createRelationshipTo( node, RELTYPE );
firstNodeID = node.getId();
secondNodeID = node2.getId();
firstRelID = rel1.getId();
secondRelID = rel2.getId();
node.setProperty( "prop", "Hello. Hello again." );
node2.setProperty( "prop", "A zebroid (also zedonk, zorse, zebra mule, zonkey, and zebmule) is the offspring of any cross " +
"between a zebra and any other equine: essentially, a zebra hybrid." );
Relationship rel1 = node.createRelationshipTo( node2, RELTYPE );
firstRelID = rel1.getId();
rel1.setProperty( "prop", "Hello. Hello again." );
Relationship rel2 = node2.createRelationshipTo( node, RELTYPE );
secondRelID = rel2.getId();
rel2.setProperty( "prop", "And now, something completely different" );

tx.success();
Expand Down
Expand Up @@ -34,7 +34,9 @@
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.rule.fs.DefaultFileSystemRule;
import org.neo4j.test.rule.fs.EphemeralFileSystemRule;
import org.neo4j.test.rule.fs.FileSystemRule;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -45,7 +47,7 @@ public class BloomIT
public static final String RELS = "CALL dbms.fulltext.bloomFulltextRelationships([\"%s\"])";
public static final String ENTITYID = "entityid";
@Rule
public final EphemeralFileSystemRule fs = new EphemeralFileSystemRule();
public final FileSystemRule fs = new DefaultFileSystemRule();

private TestGraphDatabaseFactory factory;
private GraphDatabaseService db;
Expand Down

0 comments on commit b1eccb9

Please sign in to comment.