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.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* 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/>.
*/
package org.neo4j.kernel.api.impl.fulltext;

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

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_PROPERTIES;
import static org.neo4j.kernel.api.impl.fulltext.FulltextProvider.FIELD_METADATA_DOC;
Expand All @@ -44,7 +43,7 @@ class FulltextIndexConfiguration

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 );
}

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

class WritableFulltext extends WritableAbstractDatabaseIndex<LuceneFulltext>
{

private PartitionedIndexWriter indexWriter;

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

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

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

PartitionedIndexWriter getIndexWriter()
{
return indexWriter;
Expand Down
Expand Up @@ -36,28 +36,31 @@
import org.neo4j.logging.Log;
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
{
public static final String BLOOM_RELATIONSHIPS = "bloomRelationships";
public static final String BLOOM_NODES = "bloomNodes";
private final File storeDir;
private final Config config;
private final FileSystemAbstraction fileSystemAbstraction;
private final FileSystemAbstraction fileSystem;
private final GraphDatabaseService db;
private final Procedures procedures;
private LogService logService;
private final AvailabilityGuard availabilityGuard;
private final JobScheduler scheduler;
private FulltextProvider provider;

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

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

provider.init();
procedures.registerComponent( FulltextProvider.class, context -> provider, true );
Expand Down
Expand Up @@ -43,7 +43,9 @@
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
{
Expand Down
Expand Up @@ -36,8 +36,8 @@
import org.neo4j.procedure.Name;
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.BloomKernelExtension.BLOOM_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;
import static org.neo4j.procedure.Mode.READ;

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

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.integrations.bloom.BloomKernelExtensionFactory.BLOOM_NODES;

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

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

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

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

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

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

try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( LABEL );
Node node2 = db.createNode( LABEL );
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." );
firstID = createNodeIndexableByPropertyValue( "Hello and hello again, in the end." );
secondID = createNodeIndexableByPropertyValue( "En apa och en tomte bodde i ett hus." );

tx.success();
}

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

assertFalse( reader.query( "and" ).hasNext() );
assertFalse( reader.query( "in" ).hasNext() );
assertFalse( reader.query( "the" ).hasNext() );
assertEquals( secondID, reader.query( "en" ).next() );
assertEquals( secondID, reader.query( "och" ).next() );
assertEquals( secondID, reader.query( "ett" ).next() );
assertExactQueryFindsNothing( reader, "and" );
assertExactQueryFindsNothing( reader, "in" );
assertExactQueryFindsNothing( reader, "the" );
assertExactQueryFindsIds( reader, "en", secondID );
assertExactQueryFindsIds( reader, "och", secondID );
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.createFulltextIndex( "bloomNodes", NODES, singletonList( "prop" ) );
FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, SWEDISH, provider );
fulltextFactory.createFulltextIndex( BLOOM_NODES, NODES, singletonList( "prop" ) );
provider.init();
provider.awaitPopulation();

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

0 comments on commit 296aad8

Please sign in to comment.