Skip to content

Commit

Permalink
Update fulltext addon test after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ragadeeshu authored and chrisvest committed Sep 25, 2017
1 parent 0d9f217 commit 296aad8
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 55 deletions.
Expand Up @@ -5,17 +5,17 @@
* This file is part of Neo4j. * This file is part of Neo4j.
* *
* Neo4j is free software: you can redistribute it and/or modify * Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU Affero General Public License as
* the Free Software Foundation, either version 3 of the License, or * published by the Free Software Foundation, either version 3 of the
* (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.neo4j.kernel.api.impl.fulltext; package org.neo4j.kernel.api.impl.fulltext;


Expand All @@ -30,7 +30,6 @@
import java.util.Set; import java.util.Set;


import static org.apache.lucene.document.Field.Store.NO; import static org.apache.lucene.document.Field.Store.NO;
import static org.apache.lucene.document.Field.Store.YES;
import static org.neo4j.kernel.api.impl.fulltext.FulltextProvider.FIELD_CONFIG_ANALYZER; import static org.neo4j.kernel.api.impl.fulltext.FulltextProvider.FIELD_CONFIG_ANALYZER;
import static org.neo4j.kernel.api.impl.fulltext.FulltextProvider.FIELD_CONFIG_PROPERTIES; import static org.neo4j.kernel.api.impl.fulltext.FulltextProvider.FIELD_CONFIG_PROPERTIES;
import static org.neo4j.kernel.api.impl.fulltext.FulltextProvider.FIELD_METADATA_DOC; import static org.neo4j.kernel.api.impl.fulltext.FulltextProvider.FIELD_METADATA_DOC;
Expand All @@ -44,7 +43,7 @@ class FulltextIndexConfiguration


FulltextIndexConfiguration( Document doc ) FulltextIndexConfiguration( Document doc )
{ {
properties = new HashSet<String>( Arrays.asList( doc.getValues( FIELD_CONFIG_PROPERTIES ) ) ); properties = new HashSet<>( Arrays.asList( doc.getValues( FIELD_CONFIG_PROPERTIES ) ) );
analyzerClassName = doc.get( FIELD_CONFIG_ANALYZER ); analyzerClassName = doc.get( FIELD_CONFIG_ANALYZER );
} }


Expand Down
Expand Up @@ -27,15 +27,27 @@


class WritableFulltext extends WritableAbstractDatabaseIndex<LuceneFulltext> class WritableFulltext extends WritableAbstractDatabaseIndex<LuceneFulltext>
{ {

private PartitionedIndexWriter indexWriter; private PartitionedIndexWriter indexWriter;


WritableFulltext( LuceneFulltext luceneFulltext ) throws IOException WritableFulltext( LuceneFulltext luceneFulltext ) throws IOException
{ {
super( luceneFulltext ); super( luceneFulltext );
}

@Override
public void open() throws IOException
{
super.open();
indexWriter = luceneIndex.getIndexWriter( this ); indexWriter = luceneIndex.getIndexWriter( this );
} }


@Override
public void drop() throws IOException
{
super.drop();
indexWriter = null;
}

PartitionedIndexWriter getIndexWriter() PartitionedIndexWriter getIndexWriter()
{ {
return indexWriter; return indexWriter;
Expand Down
Expand Up @@ -36,28 +36,31 @@
import org.neo4j.logging.Log; import org.neo4j.logging.Log;
import org.neo4j.scheduler.JobScheduler; import org.neo4j.scheduler.JobScheduler;


import static org.neo4j.kernel.api.impl.fulltext.FulltextProvider.FulltextIndexType.NODES;
import static org.neo4j.kernel.api.impl.fulltext.FulltextProvider.FulltextIndexType.RELATIONSHIPS;
import static org.neo4j.kernel.api.impl.fulltext.integrations.bloom.BloomKernelExtensionFactory.BLOOM_NODES;
import static org.neo4j.kernel.api.impl.fulltext.integrations.bloom.BloomKernelExtensionFactory.BLOOM_RELATIONSHIPS;

class BloomKernelExtension extends LifecycleAdapter class BloomKernelExtension extends LifecycleAdapter
{ {
public static final String BLOOM_RELATIONSHIPS = "bloomRelationships";
public static final String BLOOM_NODES = "bloomNodes";
private final File storeDir; private final File storeDir;
private final Config config; private final Config config;
private final FileSystemAbstraction fileSystemAbstraction; private final FileSystemAbstraction fileSystem;
private final GraphDatabaseService db; private final GraphDatabaseService db;
private final Procedures procedures; private final Procedures procedures;
private LogService logService; private LogService logService;
private final AvailabilityGuard availabilityGuard; private final AvailabilityGuard availabilityGuard;
private final JobScheduler scheduler; private final JobScheduler scheduler;
private FulltextProvider provider; private FulltextProvider provider;


BloomKernelExtension( FileSystemAbstraction fileSystemAbstraction, File storeDir, Config config, BloomKernelExtension( FileSystemAbstraction fileSystem, File storeDir, Config config,
GraphDatabaseService db, Procedures procedures, GraphDatabaseService db, Procedures procedures,
LogService logService, AvailabilityGuard availabilityGuard, LogService logService, AvailabilityGuard availabilityGuard,
JobScheduler scheduler ) JobScheduler scheduler )
{ {
this.storeDir = storeDir; this.storeDir = storeDir;
this.config = config; this.config = config;
this.fileSystemAbstraction = fileSystemAbstraction; this.fileSystem = fileSystem;
this.db = db; this.db = db;
this.procedures = procedures; this.procedures = procedures;
this.logService = logService; this.logService = logService;
Expand All @@ -70,14 +73,14 @@ public void init() throws IOException, KernelException
{ {
if ( config.get( LoadableBloomFulltextConfig.bloom_enabled ) ) if ( config.get( LoadableBloomFulltextConfig.bloom_enabled ) )
{ {
List<String> properties = getProperties( ); List<String> properties = getProperties();
String analyzer = config.get( LoadableBloomFulltextConfig.bloom_analyzer); String analyzer = config.get( LoadableBloomFulltextConfig.bloom_analyzer );


Log log = logService.getInternalLog( FulltextProvider.class ); Log log = logService.getInternalLog( FulltextProvider.class );
provider = new FulltextProvider( db, log, availabilityGuard, scheduler ); provider = new FulltextProvider( db, log, availabilityGuard, scheduler );
FulltextFactory fulltextFactory = new FulltextFactory( fileSystemAbstraction, storeDir, analyzer, provider ); FulltextFactory fulltextFactory = new FulltextFactory( fileSystem, storeDir, analyzer, provider );
fulltextFactory.createFulltextIndex( BLOOM_NODES, FulltextProvider.FulltextIndexType.NODES, properties ); fulltextFactory.createFulltextIndex( BLOOM_NODES, NODES, properties );
fulltextFactory.createFulltextIndex( BLOOM_RELATIONSHIPS, FulltextProvider.FulltextIndexType.RELATIONSHIPS, properties ); fulltextFactory.createFulltextIndex( BLOOM_RELATIONSHIPS, RELATIONSHIPS, properties );


provider.init(); provider.init();
procedures.registerComponent( FulltextProvider.class, context -> provider, true ); procedures.registerComponent( FulltextProvider.class, context -> provider, true );
Expand Down
Expand Up @@ -43,7 +43,9 @@
public class BloomKernelExtensionFactory extends KernelExtensionFactory<BloomKernelExtensionFactory.Dependencies> public class BloomKernelExtensionFactory extends KernelExtensionFactory<BloomKernelExtensionFactory.Dependencies>
{ {


private static final String SERVICE_NAME = "bloom"; public static final String SERVICE_NAME = "bloom";
public static final String BLOOM_RELATIONSHIPS = "bloomRelationships";
public static final String BLOOM_NODES = "bloomNodes";


public interface Dependencies public interface Dependencies
{ {
Expand Down
Expand Up @@ -36,8 +36,8 @@
import org.neo4j.procedure.Name; import org.neo4j.procedure.Name;
import org.neo4j.procedure.Procedure; import org.neo4j.procedure.Procedure;


import static org.neo4j.kernel.api.impl.fulltext.integrations.bloom.BloomKernelExtension.BLOOM_NODES; import static org.neo4j.kernel.api.impl.fulltext.integrations.bloom.BloomKernelExtensionFactory.BLOOM_NODES;
import static org.neo4j.kernel.api.impl.fulltext.integrations.bloom.BloomKernelExtension.BLOOM_RELATIONSHIPS; import static org.neo4j.kernel.api.impl.fulltext.integrations.bloom.BloomKernelExtensionFactory.BLOOM_RELATIONSHIPS;
import static org.neo4j.procedure.Mode.READ; import static org.neo4j.procedure.Mode.READ;


/** /**
Expand Down
Expand Up @@ -27,6 +27,7 @@


import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import static org.neo4j.kernel.api.impl.fulltext.FulltextProvider.FulltextIndexType.NODES; import static org.neo4j.kernel.api.impl.fulltext.FulltextProvider.FulltextIndexType.NODES;
import static org.neo4j.kernel.api.impl.fulltext.integrations.bloom.BloomKernelExtensionFactory.BLOOM_NODES;


public class FulltextAnalyzerTest extends LuceneFulltextTestSupport public class FulltextAnalyzerTest extends LuceneFulltextTestSupport
{ {
Expand All @@ -39,7 +40,7 @@ public void shouldBeAbleToSpecifyEnglishAnalyzer() throws Exception
try ( FulltextProvider provider = createProvider() ) try ( FulltextProvider provider = createProvider() )
{ {
FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ENGLISH, provider ); FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ENGLISH, provider );
fulltextFactory.createFulltextIndex( "bloomNodes", NODES, singletonList( "prop" ) ); fulltextFactory.createFulltextIndex( BLOOM_NODES, NODES, singletonList( "prop" ) );
provider.init(); provider.init();


long id; long id;
Expand All @@ -51,7 +52,7 @@ public void shouldBeAbleToSpecifyEnglishAnalyzer() throws Exception
tx.success(); tx.success();
} }


try ( ReadOnlyFulltext reader = provider.getReader( "bloomNodes", NODES ) ) try ( ReadOnlyFulltext reader = provider.getReader( BLOOM_NODES, NODES ) )
{ {
assertExactQueryFindsNothing( reader, "and" ); assertExactQueryFindsNothing( reader, "and" );
assertExactQueryFindsNothing( reader, "in" ); assertExactQueryFindsNothing( reader, "in" );
Expand All @@ -69,7 +70,7 @@ public void shouldBeAbleToSpecifySwedishAnalyzer() throws Exception
try ( FulltextProvider provider = createProvider(); ) try ( FulltextProvider provider = createProvider(); )
{ {
FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, SWEDISH, provider ); FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, SWEDISH, provider );
fulltextFactory.createFulltextIndex( "bloomNodes", NODES, singletonList( "prop" ) ); fulltextFactory.createFulltextIndex( BLOOM_NODES, NODES, singletonList( "prop" ) );
provider.init(); provider.init();


long id; long id;
Expand All @@ -81,7 +82,7 @@ public void shouldBeAbleToSpecifySwedishAnalyzer() throws Exception
tx.success(); tx.success();
} }


try ( ReadOnlyFulltext reader = provider.getReader( "bloomNodes", NODES ) ) try ( ReadOnlyFulltext reader = provider.getReader( BLOOM_NODES, NODES ) )
{ {
assertExactQueryFindsIds( reader, "and", id ); assertExactQueryFindsIds( reader, "and", id );
assertExactQueryFindsIds( reader, "in", id ); assertExactQueryFindsIds( reader, "in", id );
Expand All @@ -96,56 +97,49 @@ public void shouldBeAbleToSpecifySwedishAnalyzer() throws Exception
@Test @Test
public void shouldReindexNodesWhenAnalyzerIsChanged() throws Exception public void shouldReindexNodesWhenAnalyzerIsChanged() throws Exception
{ {
GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
File storeDir = testDirectory.graphDbDir();

long firstID; long firstID;
long secondID; long secondID;
try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) try ( FulltextProvider provider = createProvider() )
{ {
FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, storeDir, ENGLISH, provider ); FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ENGLISH, provider );
fulltextFactory.createFulltextIndex( "bloomNodes", NODES, singletonList( "prop" ) ); fulltextFactory.createFulltextIndex( BLOOM_NODES, NODES, singletonList( "prop" ) );
provider.init(); provider.init();


try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
{ {
Node node = db.createNode( LABEL ); firstID = createNodeIndexableByPropertyValue( "Hello and hello again, in the end." );
Node node2 = db.createNode( LABEL ); secondID = createNodeIndexableByPropertyValue( "En apa och en tomte bodde i ett hus." );
firstID = node.getId();
secondID = node2.getId();
node.setProperty( "prop", "Hello and hello again, in the end." );
node2.setProperty( "prop", "En apa och en tomte bodde i ett hus." );


tx.success(); tx.success();
} }


try ( ReadOnlyFulltext reader = provider.getReader( "bloomNodes", NODES ) ) try ( ReadOnlyFulltext reader = provider.getReader( BLOOM_NODES, NODES ) )
{ {


assertFalse( reader.query( "and" ).hasNext() ); assertExactQueryFindsNothing( reader, "and" );
assertFalse( reader.query( "in" ).hasNext() ); assertExactQueryFindsNothing( reader, "in" );
assertFalse( reader.query( "the" ).hasNext() ); assertExactQueryFindsNothing( reader, "the" );
assertEquals( secondID, reader.query( "en" ).next() ); assertExactQueryFindsIds( reader, "en", secondID );
assertEquals( secondID, reader.query( "och" ).next() ); assertExactQueryFindsIds( reader, "och", secondID );
assertEquals( secondID, reader.query( "ett" ).next() ); assertExactQueryFindsIds( reader, "ett", secondID );
} }
} }


try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ); ) try ( FulltextProvider provider = createProvider() )
{ {
FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, storeDir, SWEDISH, provider ); FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, SWEDISH, provider );
fulltextFactory.createFulltextIndex( "bloomNodes", NODES, singletonList( "prop" ) ); fulltextFactory.createFulltextIndex( BLOOM_NODES, NODES, singletonList( "prop" ) );
provider.init(); provider.init();
provider.awaitPopulation(); provider.awaitPopulation();


try ( ReadOnlyFulltext reader = provider.getReader( "bloomNodes", NODES ) ) try ( ReadOnlyFulltext reader = provider.getReader( BLOOM_NODES, NODES ) )
{ {
assertEquals( firstID, reader.query( "and" ).next() ); assertExactQueryFindsIds( reader, "and", firstID );
assertEquals( firstID, reader.query( "in" ).next() ); assertExactQueryFindsIds( reader, "in", firstID );
assertEquals( firstID, reader.query( "the" ).next() ); assertExactQueryFindsIds( reader, "the", firstID );
assertFalse( reader.query( "en" ).hasNext() ); assertExactQueryFindsNothing( reader, "en" );
assertFalse( reader.query( "och" ).hasNext() ); assertExactQueryFindsNothing( reader, "och" );
assertFalse( reader.query( "ett" ).hasNext() ); assertExactQueryFindsNothing( reader, "ett" );
} }
} }
} }
Expand Down

0 comments on commit 296aad8

Please sign in to comment.