Skip to content

Commit

Permalink
Merge pull request #10977 from ragadeeshu/3.3-bloom-small-fixes
Browse files Browse the repository at this point in the history
Small fixes for bloom
  • Loading branch information
ragadeeshu committed Feb 14, 2018
2 parents 493cfe5 + 0b9d762 commit 3c0202d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
*/
package org.neo4j.kernel.api.impl.fulltext.integrations.bloom;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.neo4j.kernel.api.impl.fulltext.FulltextProvider;
Expand Down Expand Up @@ -89,9 +91,9 @@ public void setIndexedRelationshipPropertyKeys( @Name( "propertyKeys" ) List<Str
@Procedure( name = "bloom.indexStatus", mode = READ )
public Stream<StatusOutput> indexStatus() throws Exception
{
InternalIndexState nodeIndexState = provider.getState( BLOOM_NODES, NODES );
InternalIndexState relationshipIndexState = provider.getState( BLOOM_RELATIONSHIPS, RELATIONSHIPS );
return Stream.of( nodeIndexState, relationshipIndexState ).map( StatusOutput::new );
StatusOutput nodeIndexState = new StatusOutput( BLOOM_NODES, provider.getState( BLOOM_NODES, NODES ) );
StatusOutput relationshipIndexState = new StatusOutput( BLOOM_RELATIONSHIPS, provider.getState( BLOOM_RELATIONSHIPS, RELATIONSHIPS ) );
return Stream.of( nodeIndexState, relationshipIndexState );
}

@Description( "Query the Bloom fulltext index for nodes" )
Expand Down Expand Up @@ -122,6 +124,7 @@ public Stream<EntityOutput> bloomFulltextRelationships(

private Stream<EntityOutput> queryAsStream( List<String> terms, ReadOnlyFulltext indexReader, boolean fuzzy, boolean matchAll )
{
terms = terms.stream().flatMap( s -> Arrays.stream( s.split( "\\s+" ) ) ).collect( Collectors.toList() );
ScoreEntityIterator resultIterator;
if ( fuzzy )
{
Expand Down Expand Up @@ -158,10 +161,12 @@ public static class PropertyOutput

public class StatusOutput
{
public final String name;
public final String state;

StatusOutput( InternalIndexState internalIndexState )
StatusOutput( String name, InternalIndexState internalIndexState )
{
this.name = name;
switch ( internalIndexState )
{
case POPULATING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,31 @@ public void exactMatchShouldScoreMuchBetterThatAlmostNotMatching() throws Except
assertThat( (double) firstResult.get( SCORE ), greaterThan( (double) secondResult.get( SCORE ) * 10 ) );
}

@Test
public void unsplitTokensShouldNotBreakFuzzyQuery() throws Exception
{
db = getDb();
db.execute( String.format( SET_NODE_KEYS, "\"prop\"" ) );
try ( Transaction transaction = db.beginTx() )
{
Node node1 = db.createNode();
node1.setProperty( "prop", "This is a integration test that involves scoring and thus needs a longer sentence." );
Node node2 = db.createNode();
node2.setProperty( "prop", "tase" );
transaction.success();
}

Result result = db.execute( String.format( NODES, "\"integration test involves scoring needs sentence\"" ) );
assertTrue( result.hasNext() );
Map<String,Object> firstResult = result.next();
assertTrue( result.hasNext() );
Map<String,Object> secondResult = result.next();
assertFalse( result.hasNext() );
assertEquals( 0L, firstResult.get( ENTITYID ) );
assertEquals( 1L, secondResult.get( ENTITYID ) );
assertThat( (double) firstResult.get( SCORE ), greaterThan( (double) secondResult.get( SCORE ) * 10 ) );
}

@Test
public void shouldBeAbleToConfigureAnalyzer() throws Exception
{
Expand Down Expand Up @@ -629,8 +654,12 @@ public void onlineIndexShouldBeReportedAsOnline() throws Exception

db.execute( AWAIT_POPULATION );
Result result = db.execute( STATUS );
assertEquals( "ONLINE", result.next().get( "state" ) );
assertEquals( "ONLINE", result.next().get( "state" ) );
Map<String,Object> output = result.next();
assertEquals( "ONLINE", output.get( "state" ) );
assertEquals( "bloomNodes", output.get( "name" ) );
output = result.next();
assertEquals( "ONLINE", output.get( "state" ) );
assertEquals( "bloomRelationships", output.get( "name" ) );
assertFalse( result.hasNext() );
}

Expand Down

0 comments on commit 3c0202d

Please sign in to comment.