Skip to content

Commit

Permalink
javadoc for the fulltext addon
Browse files Browse the repository at this point in the history
  • Loading branch information
ragadeeshu committed Sep 12, 2017
1 parent 57aaa20 commit b42bc1f
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 30 deletions.
Expand Up @@ -34,13 +34,23 @@

import static org.neo4j.kernel.api.impl.index.LuceneKernelExtensions.directoryFactory;

/**
* Used for creating {@link LuceneFulltext} and registering those to a {@link FulltextProvider}.
*/
public class FulltextFactory
{
private final FileSystemAbstraction fileSystem;
private final WritableIndexPartitionFactory partitionFactory;
private final File storeDir;
private final Analyzer analyzer;

/**
* Creates a factory for the specified location and analyzer.
* @param fileSystem The filesystem to use.
* @param storeDir Store directory of the database.
* @param analyzer The Lucene analyzer to use for the {@link LuceneFulltext} created by this factory.
* @throws IOException
*/
public FulltextFactory( FileSystemAbstraction fileSystem, File storeDir, Analyzer analyzer ) throws IOException
{
this.analyzer = analyzer;
Expand All @@ -50,11 +60,20 @@ public FulltextFactory( FileSystemAbstraction fileSystem, File storeDir, Analyze
this.storeDir = storeDir;
}

public void createFulltextHelper( String identifier, FulltextProvider.FULLTEXT_HELPER_TYPE type, String[] properties, FulltextProvider provider ) throws IOException
/**
* Creates an instance of {@link LuceneFulltext} and registers it with the supplied {@link FulltextProvider}.
* @param identifier The identifier of the new fulltext helper
* @param type The type of the new fulltext helper
* @param properties The properties to index
* @param provider The provider to register with
* @throws IOException
*/
public void createFulltextHelper( String identifier, FulltextProvider.FULLTEXT_HELPER_TYPE type, String[] properties, FulltextProvider provider )
throws IOException
{
LuceneIndexStorageBuilder storageBuilder = LuceneIndexStorageBuilder.create();
storageBuilder.withFileSystem( fileSystem ).withIndexIdentifier(
identifier ).withDirectoryFactory( directoryFactory( false, this.fileSystem ) ).withIndexRootFolder( Paths.get( this.storeDir.getAbsolutePath(), "fulltext" ).toFile() );
storageBuilder.withFileSystem( fileSystem ).withIndexIdentifier( identifier ).withDirectoryFactory(
directoryFactory( false, this.fileSystem ) ).withIndexRootFolder( Paths.get( this.storeDir.getAbsolutePath(), "fulltext" ).toFile() );
provider.register( new LuceneFulltext( storageBuilder.build(), partitionFactory, properties, analyzer, identifier, type ) );
}
}
Expand Up @@ -67,7 +67,8 @@ public synchronized void close()
{
closed = true;
db.unregisterTransactionEventHandler( fulltextTransactionEventUpdater );
nodeIndices.values().forEach( luceneFulltextHelper -> {
nodeIndices.values().forEach( luceneFulltextHelper ->
{
try
{
luceneFulltextHelper.close();
Expand All @@ -77,7 +78,8 @@ public synchronized void close()
e.printStackTrace();
}
} );
relationshipIndices.values().forEach( luceneFulltextHelper -> {
relationshipIndices.values().forEach( luceneFulltextHelper ->
{
try
{
luceneFulltextHelper.close();
Expand Down
Expand Up @@ -34,7 +34,7 @@
import org.neo4j.graphdb.event.TransactionData;
import org.neo4j.graphdb.event.TransactionEventHandler;

public class FulltextTransactionEventUpdater implements TransactionEventHandler<Object>
class FulltextTransactionEventUpdater implements TransactionEventHandler<Object>
{

private FulltextProvider fulltextProvider;
Expand Down
Expand Up @@ -97,7 +97,7 @@ PartitionedIndexWriter getIndexWriter( WritableFulltext writableIndex ) throws I
return new PartitionedIndexWriter( writableIndex );
}

public ReadOnlyFulltext getIndexReader() throws IOException
ReadOnlyFulltext getIndexReader() throws IOException
{
ensureOpen();
List<AbstractIndexPartition> partitions = getPartitions();
Expand Down
Expand Up @@ -55,15 +55,15 @@ private PartitionedFulltextReader( List<ReadOnlyFulltext> readers )
}

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

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

private PrimitiveLongIterator innerQuery( ReadOnlyFulltext reader, String... query )
Expand Down
Expand Up @@ -23,6 +23,19 @@

public interface ReadOnlyFulltext extends AutoCloseable
{
PrimitiveLongIterator query( String... query );
PrimitiveLongIterator fuzzyQuery( String... query );
/**
* Searches the fulltext helper for any exact match of any of the given terms against any token in any of the indexed properties.
*
* @param terms The terms to query for.
* @return An iterator over the matching entityIDs, ordered by lucene scoring of the match.
*/
PrimitiveLongIterator query( String... terms );

/**
* Searches the fulltext helper for any fuzzy match of any of the given terms against any token in any of the indexed properties.
*
* @param terms The terms to query for.
* @return An iterator over the matching entityIDs, ordered by lucene scoring of the match.
*/
PrimitiveLongIterator fuzzyQuery( String... terms );
}
Expand Up @@ -57,18 +57,18 @@ class SimpleFulltextReader implements ReadOnlyFulltext
}

@Override
public PrimitiveLongIterator query( String... tokens )
public PrimitiveLongIterator query( String... terms )
{
MultiFieldQueryParser multiFieldQueryParser = new MultiFieldQueryParser( properties, analyzer );
multiFieldQueryParser.setDefaultOperator( QueryParser.Operator.OR );
Query query;
try
{
query = multiFieldQueryParser.parse( String.join( " ", tokens ) );
query = multiFieldQueryParser.parse( String.join( " ", terms ) );
}
catch ( ParseException e )
{
query = parseFallbackBooleanQuery( multiFieldQueryParser, tokens );
query = parseFallbackBooleanQuery( multiFieldQueryParser, terms );
}
return query( query );
}
Expand All @@ -93,18 +93,18 @@ private Query parseFallbackBooleanQuery( MultiFieldQueryParser multiFieldQueryPa
}

@Override
public PrimitiveLongIterator fuzzyQuery( String... tokens )
public PrimitiveLongIterator fuzzyQuery( String... terms )
{
MultiFieldQueryParser multiFieldQueryParser = new MultiFieldQueryParser( properties, analyzer );
multiFieldQueryParser.setDefaultOperator( QueryParser.Operator.OR );
Query query;
try
{
query = multiFieldQueryParser.parse( String.join( "~ ", tokens ) + "~" );
query = multiFieldQueryParser.parse( String.join( "~ ", terms ) + "~" );
}
catch ( ParseException e )
{
query = parseFallbackBooleanQuery( multiFieldQueryParser, tokens );
query = parseFallbackBooleanQuery( multiFieldQueryParser, terms );
}
return query( query );
}
Expand Down
Expand Up @@ -42,16 +42,6 @@ PartitionedIndexWriter getIndexWriter() throws IOException
return luceneFulltext.getIndexWriter( this );
}

public boolean hasSinglePartition( List<AbstractIndexPartition> partitions )
{
return luceneIndex.hasSinglePartition( partitions );
}

public AbstractIndexPartition getFirstPartition( List<AbstractIndexPartition> partitions )
{
return luceneIndex.getFirstPartition( partitions );
}

Set<String> properties()
{
return luceneIndex.getProperties();
Expand Down
Expand Up @@ -27,6 +27,12 @@
import org.neo4j.kernel.impl.spi.KernelContext;
import org.neo4j.kernel.lifecycle.Lifecycle;

/**
* A {@link KernelExtensionFactory} for the bloom fulltext addon.
*
* @see BloomProcedure
* @see LoadableBloomFulltextConfig
*/
public class BloomKernelExtensionFactory extends KernelExtensionFactory<BloomKernelExtensionFactory.Dependencies>
{

Expand Down
Expand Up @@ -34,6 +34,9 @@

import static org.neo4j.kernel.api.proc.ProcedureSignature.procedureSignature;

/**
* Procedures for querying the bloom fulltext addon.
*/
public class BloomProcedure extends CallableProcedure.BasicProcedure
{
private static final String OUTPUT_NAME = "entityid";
Expand All @@ -43,6 +46,12 @@ public class BloomProcedure extends CallableProcedure.BasicProcedure
private final FulltextProvider provider;
private FulltextProvider.FULLTEXT_HELPER_TYPE type;

/**
* Creates a procedure for querying the bloom fulltext addon.
* @param type The type of fulltext helper to be queried.
* @param identifier The identifier of the fulltext helper.
* @param provider The provider of the fulltext helper.
*/
public BloomProcedure( FulltextProvider.FULLTEXT_HELPER_TYPE type, String identifier, FulltextProvider provider )
{
super( procedureSignature( new QualifiedName( PROCEDURE_NAMESPACE, PROCEDURE_NAME + type ) ).in( "terms",
Expand Down
@@ -1,3 +1,22 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* 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 Affero General Public License for more details.
*
* 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.integrations.bloom;

import java.util.List;
Expand All @@ -12,6 +31,9 @@
import static org.neo4j.kernel.configuration.Settings.STRING_LIST;
import static org.neo4j.kernel.configuration.Settings.setting;

/**
* Configuration parameters for the bloom fulltext addon.
*/
public class LoadableBloomFulltextConfig implements LoadableConfig
{

Expand Down
Expand Up @@ -119,4 +119,4 @@ public void shouldBeAbleToSpecifySwedishAnalyzer() throws Exception
}
}
}
}
}

0 comments on commit b42bc1f

Please sign in to comment.