Skip to content

Commit

Permalink
Update fulltext addon after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ragadeeshu committed Sep 29, 2017
1 parent 8460094 commit e00c640
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 32 deletions.
Expand Up @@ -22,6 +22,7 @@
import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.Analyzer;


import java.io.IOException; import java.io.IOException;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
Expand Down Expand Up @@ -55,27 +56,27 @@ private PartitionedFulltextReader( List<ReadOnlyFulltext> readers )
} }


@Override @Override
public PrimitiveLongIterator query( boolean matchAll, String... terms ) public PrimitiveLongIterator query( Collection<String> terms, boolean matchAll )
{ {
return partitionedOperation( reader -> innerQuery( reader, matchAll, terms ) ); return partitionedOperation( reader -> innerQuery( reader, matchAll, terms ) );
} }


@Override @Override
public PrimitiveLongIterator fuzzyQuery( boolean matchAll, String... terms ) public PrimitiveLongIterator fuzzyQuery( Collection<String> terms, boolean matchAll )
{ {
return partitionedOperation( reader -> innerFuzzyQuery( reader, matchAll, terms ) ); return partitionedOperation( reader -> innerFuzzyQuery( reader, matchAll, terms ) );
} }


private PrimitiveLongIterator innerQuery( ReadOnlyFulltext reader, boolean matchAll, String... query ) private PrimitiveLongIterator innerQuery( ReadOnlyFulltext reader, boolean matchAll, Collection<String> query )
{ {


return reader.query( matchAll, query ); return reader.query( query, matchAll );
} }


private PrimitiveLongIterator innerFuzzyQuery( ReadOnlyFulltext reader, boolean matchAll, String... query ) private PrimitiveLongIterator innerFuzzyQuery( ReadOnlyFulltext reader, boolean matchAll, Collection<String> query )
{ {


return reader.fuzzyQuery( matchAll, query ); return reader.fuzzyQuery( query, matchAll );
} }


public void close() public void close()
Expand Down
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.kernel.api.impl.fulltext; package org.neo4j.kernel.api.impl.fulltext;


import java.io.IOException; import java.io.IOException;
import java.util.Collection;


import org.neo4j.collection.primitive.PrimitiveLongIterator; import org.neo4j.collection.primitive.PrimitiveLongIterator;


Expand All @@ -29,21 +30,21 @@ public interface ReadOnlyFulltext extends AutoCloseable
* Searches the fulltext index for any exact match of any of the given terms against any token in any of the indexed properties. * Searches the fulltext index for any exact match of any of the given terms against any token in any of the indexed properties.
* *
* *
* @param matchAll If true, only resluts that match all the given terms will be returned
* @param terms The terms to query for. * @param terms The terms to query for.
* @param matchAll If true, only resluts that match all the given terms will be returned
* @return An iterator over the matching entityIDs, ordered by lucene scoring of the match. * @return An iterator over the matching entityIDs, ordered by lucene scoring of the match.
*/ */
PrimitiveLongIterator query( boolean matchAll, String... terms ); PrimitiveLongIterator query( Collection<String> terms, boolean matchAll );


/** /**
* Searches the fulltext index for any fuzzy match of any of the given terms against any token in any of the indexed properties. * Searches the fulltext index for any fuzzy match of any of the given terms against any token in any of the indexed properties.
* *
* *
* @param matchAll If true, only resluts that match all the given terms will be returned
* @param terms The terms to query for. * @param terms The terms to query for.
* @param matchAll If true, only resluts that match all the given terms will be returned
* @return An iterator over the matching entityIDs, ordered by lucene scoring of the match. * @return An iterator over the matching entityIDs, ordered by lucene scoring of the match.
*/ */
PrimitiveLongIterator fuzzyQuery( boolean matchAll, String... terms ); PrimitiveLongIterator fuzzyQuery( Collection<String> terms, boolean matchAll );


@Override @Override
void close(); void close();
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.TopDocs;


import java.io.IOException; import java.io.IOException;
import java.util.Collection;


import org.neo4j.collection.primitive.PrimitiveLongCollections; import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.collection.primitive.PrimitiveLongIterator; import org.neo4j.collection.primitive.PrimitiveLongIterator;
Expand Down Expand Up @@ -60,16 +61,16 @@ class SimpleFulltextReader implements ReadOnlyFulltext
} }


@Override @Override
public PrimitiveLongIterator query( boolean matchAll, String... terms ) public PrimitiveLongIterator query( Collection<String> terms, boolean matchAll )
{ {
String query = stream( terms ).map( QueryParser::escape ).collect( joining( " " ) ); String query = terms.stream().map( QueryParser::escape ).collect( joining( " " ) );
return innerQuery( query, matchAll ); return innerQuery( query, matchAll );
} }


@Override @Override
public PrimitiveLongIterator fuzzyQuery( boolean matchAll, String... terms ) public PrimitiveLongIterator fuzzyQuery( Collection<String> terms, boolean matchAll )
{ {
String query = stream( terms ).map( QueryParser::escape ).collect( joining( "~ ", "", "~" ) ); String query = terms.stream().map( QueryParser::escape ).collect( joining( "~ ", "", "~" ) );
return innerQuery( query, matchAll ); return innerQuery( query, matchAll );
} }


Expand Down
Expand Up @@ -101,11 +101,11 @@ private Stream<EntityOutput> queryAsStream( List<String> terms, ReadOnlyFulltext
PrimitiveLongIterator primitiveLongIterator; PrimitiveLongIterator primitiveLongIterator;
if ( fuzzy ) if ( fuzzy )
{ {
primitiveLongIterator = indexReader.fuzzyQuery( matchAll, terms.toArray( new String[0] ) ); primitiveLongIterator = indexReader.fuzzyQuery( terms, matchAll );
} }
else else
{ {
primitiveLongIterator = indexReader.query( matchAll, terms.toArray( new String[0] ) ); primitiveLongIterator = indexReader.query( terms, matchAll );
} }
Iterator<EntityOutput> iterator = PrimitiveLongCollections.map( EntityOutput::new, primitiveLongIterator ); Iterator<EntityOutput> iterator = PrimitiveLongCollections.map( EntityOutput::new, primitiveLongIterator );
return StreamSupport.stream( Spliterators.spliteratorUnknownSize( iterator, Spliterator.ORDERED ), false ); return StreamSupport.stream( Spliterators.spliteratorUnknownSize( iterator, Spliterator.ORDERED ), false );
Expand Down
Expand Up @@ -27,6 +27,7 @@
import java.io.IOException; import java.io.IOException;
import java.time.Clock; import java.time.Clock;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;


import org.neo4j.collection.primitive.PrimitiveLongCollections; import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.collection.primitive.PrimitiveLongIterator; import org.neo4j.collection.primitive.PrimitiveLongIterator;
Expand Down Expand Up @@ -115,37 +116,37 @@ protected void assertExactQueryFindsNothing( ReadOnlyFulltext reader, String que
assertExactQueryFindsIds( reader, query, false ); assertExactQueryFindsIds( reader, query, false );
} }


protected void assertExactQueryFindsIds( ReadOnlyFulltext reader, String[] query, boolean matchAll, long... ids ) protected void assertExactQueryFindsIds( ReadOnlyFulltext reader, Collection<String> query, boolean matchAll, long... ids )
{ {
PrimitiveLongIterator result = reader.query( matchAll, query ); PrimitiveLongIterator result = reader.query( query, matchAll );
assertQueryResultsMatch( result, ids ); assertQueryResultsMatch( result, ids );
} }


protected void assertExactQueryFindsIdsInOrder( ReadOnlyFulltext reader, String[] query, boolean matchAll, long... ids ) protected void assertExactQueryFindsIdsInOrder( ReadOnlyFulltext reader, Collection<String> query, boolean matchAll, long... ids )
{ {
PrimitiveLongIterator result = reader.query( matchAll, query ); PrimitiveLongIterator result = reader.query( query, matchAll );
assertQueryResultsMatchInOrder( result, ids ); assertQueryResultsMatchInOrder( result, ids );
} }


protected void assertExactQueryFindsIds( ReadOnlyFulltext reader, String query, boolean matchAll, long... ids ) protected void assertExactQueryFindsIds( ReadOnlyFulltext reader, String query, boolean matchAll, long... ids )
{ {
assertExactQueryFindsIds( reader, new String[]{query}, matchAll, ids ); assertExactQueryFindsIds( reader, Arrays.asList( query ), matchAll, ids );
} }


protected void assertFuzzyQueryFindsIds( ReadOnlyFulltext reader, String query, boolean matchAll, long... ids ) protected void assertFuzzyQueryFindsIds( ReadOnlyFulltext reader, String query, boolean matchAll, long... ids )
{ {
assertFuzzyQueryFindsIds( reader, new String[]{query}, matchAll, ids ); assertFuzzyQueryFindsIds( reader, Arrays.asList( query ), matchAll, ids );
} }


protected void assertFuzzyQueryFindsIds( ReadOnlyFulltext reader, String[] query, boolean matchAll, long... ids ) protected void assertFuzzyQueryFindsIds( ReadOnlyFulltext reader, Collection<String> query, boolean matchAll, long... ids )
{ {
PrimitiveLongIterator result = reader.fuzzyQuery( matchAll, query ); PrimitiveLongIterator result = reader.fuzzyQuery( query, matchAll );
assertQueryResultsMatch( result, ids ); assertQueryResultsMatch( result, ids );
} }


protected void assertFuzzyQueryFindsIdsInOrder( ReadOnlyFulltext reader, String query, boolean matchAll, long... ids ) protected void assertFuzzyQueryFindsIdsInOrder( ReadOnlyFulltext reader, String query, boolean matchAll, long... ids )
{ {
PrimitiveLongIterator result = reader.fuzzyQuery( matchAll, query ); PrimitiveLongIterator result = reader.fuzzyQuery( Arrays.asList( query ), matchAll );
assertQueryResultsMatchInOrder( result, ids ); assertQueryResultsMatchInOrder( result, ids );
} }


Expand Down
Expand Up @@ -140,7 +140,7 @@ public void shouldFindNodeWithArrays() throws Exception
{ {
assertExactQueryFindsIds( reader, "live", false, firstID ); assertExactQueryFindsIds( reader, "live", false, firstID );
assertExactQueryFindsIds( reader, "27", false, secondID ); assertExactQueryFindsIds( reader, "27", false, secondID );
assertExactQueryFindsIds( reader, new String[]{"1", "2"}, false, secondID, thirdID ); assertExactQueryFindsIds( reader, Arrays.asList( "1", "2" ), false, secondID, thirdID );
} }
} }
} }
Expand Down Expand Up @@ -330,7 +330,7 @@ public void shouldSearchAcrossMultipleProperties() throws Exception


try ( ReadOnlyFulltext reader = provider.getReader( "nodes", NODES ) ) try ( ReadOnlyFulltext reader = provider.getReader( "nodes", NODES ) )
{ {
assertExactQueryFindsIds( reader, new String[]{"tomtar", "karl"}, false, firstID, secondID, thirdID ); assertExactQueryFindsIds( reader, Arrays.asList( "tomtar", "karl" ), false, firstID, secondID, thirdID );
} }
} }
} }
Expand Down Expand Up @@ -367,7 +367,7 @@ public void shouldOrderResultsBasedOnRelevance() throws Exception


try ( ReadOnlyFulltext reader = provider.getReader( "nodes", NODES ) ) try ( ReadOnlyFulltext reader = provider.getReader( "nodes", NODES ) )
{ {
assertExactQueryFindsIdsInOrder( reader, new String[]{"Tom", "Hanks"}, false, fourthID, thirdID, firstID, secondID ); assertExactQueryFindsIdsInOrder( reader, Arrays.asList( "Tom", "Hanks" ), false, fourthID, thirdID, firstID, secondID );
} }
} }
} }
Expand Down Expand Up @@ -624,7 +624,7 @@ public void exactMatchAllShouldOnlyReturnStuffThatMatchesAll() throws Exception


try ( ReadOnlyFulltext reader = provider.getReader( "nodes", NODES ) ) try ( ReadOnlyFulltext reader = provider.getReader( "nodes", NODES ) )
{ {
assertExactQueryFindsIds( reader, new String[]{"Tom", "Hanks"}, true, thirdID, fourthID, fifthID ); assertExactQueryFindsIds( reader, Arrays.asList( "Tom", "Hanks" ), true, thirdID, fourthID, fifthID );
} }
} }
} }
Expand Down Expand Up @@ -665,7 +665,7 @@ public void fuzzyMatchAllShouldOnlyReturnStuffThatKindaMatchesAll() throws Excep


try ( ReadOnlyFulltext reader = provider.getReader( "nodes", NODES ) ) try ( ReadOnlyFulltext reader = provider.getReader( "nodes", NODES ) )
{ {
assertFuzzyQueryFindsIds( reader, new String[]{"Tom", "Hanks"}, true, thirdID, fourthID, fifthID ); assertFuzzyQueryFindsIds( reader, Arrays.asList( "Tom", "Hanks" ), true, thirdID, fourthID, fifthID );
} }
} }
} }
Expand Down
Expand Up @@ -120,7 +120,7 @@ public void shouldPopulateAndQueryIndexes() throws Exception
public void exactQueryShouldBeExact() throws Exception public void exactQueryShouldBeExact() throws Exception
{ {
builder.setConfig( bloom_indexed_properties, "prop" ); builder.setConfig( bloom_indexed_properties, "prop" );
db = builder.newGraphDatabase(); db = getDb();
try ( Transaction transaction = db.beginTx() ) try ( Transaction transaction = db.beginTx() )
{ {
Node node1 = db.createNode(); Node node1 = db.createNode();
Expand All @@ -142,7 +142,7 @@ public void exactQueryShouldBeExact() throws Exception
public void matchAllQueryShouldMatchAll() throws Exception public void matchAllQueryShouldMatchAll() throws Exception
{ {
builder.setConfig( bloom_indexed_properties, "prop" ); builder.setConfig( bloom_indexed_properties, "prop" );
db = builder.newGraphDatabase(); db = getDb();
try ( Transaction transaction = db.beginTx() ) try ( Transaction transaction = db.beginTx() )
{ {
Node node1 = db.createNode(); Node node1 = db.createNode();
Expand Down

0 comments on commit e00c640

Please sign in to comment.