Skip to content

Commit

Permalink
Preparations for configurable bloom index analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
ragadeeshu committed Sep 12, 2017
1 parent fbc12d9 commit 8fca632
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
Expand Up @@ -34,13 +34,13 @@


import static org.apache.lucene.document.Field.Store.YES; import static org.apache.lucene.document.Field.Store.YES;


class BloomInsightDocumentStructure class BloomDocumentStructure
{ {
static final String ID_KEY = "id"; static final String ID_KEY = "id";


private static final ThreadLocal<DocWithId> perThreadDocument = ThreadLocal.withInitial( DocWithId::new ); private static final ThreadLocal<DocWithId> perThreadDocument = ThreadLocal.withInitial( DocWithId::new );


private BloomInsightDocumentStructure() private BloomDocumentStructure()
{ {
} }


Expand Down
Expand Up @@ -45,21 +45,24 @@ public class BloomIndex implements AutoCloseable
public BloomIndex( FileSystemAbstraction fileSystem, File file, Config config ) throws IOException public BloomIndex( FileSystemAbstraction fileSystem, File file, Config config ) throws IOException
{ {
this.properties = config.get( GraphDatabaseSettings.bloom_indexed_properties ).toArray( new String[0] ); this.properties = config.get( GraphDatabaseSettings.bloom_indexed_properties ).toArray( new String[0] );
Factory<IndexWriterConfig> population = () -> IndexWriterConfigs.population( new EnglishAnalyzer() ); EnglishAnalyzer analyzer = new EnglishAnalyzer();
Factory<IndexWriterConfig> population = () -> {
return IndexWriterConfigs.population( analyzer );
};
WritableIndexPartitionFactory partitionFactory = new WritableIndexPartitionFactory( population ); WritableIndexPartitionFactory partitionFactory = new WritableIndexPartitionFactory( population );


LuceneIndexStorageBuilder storageBuilder = LuceneIndexStorageBuilder.create(); LuceneIndexStorageBuilder storageBuilder = LuceneIndexStorageBuilder.create();
storageBuilder.withFileSystem( fileSystem ).withIndexIdentifier( "insightNodes" ) storageBuilder.withFileSystem( fileSystem ).withIndexIdentifier( "insightNodes" )
.withDirectoryFactory( directoryFactory( false, fileSystem ) ) .withDirectoryFactory( directoryFactory( false, fileSystem ) )
.withIndexRootFolder( Paths.get( file.getAbsolutePath(),"insightindex" ).toFile() ); .withIndexRootFolder( Paths.get( file.getAbsolutePath(),"insightindex" ).toFile() );
nodeIndex = new BloomLuceneIndex( storageBuilder.build(), partitionFactory, this.properties ); nodeIndex = new BloomLuceneIndex( storageBuilder.build(), partitionFactory, this.properties, analyzer);
nodeIndex.open(); nodeIndex.open();


storageBuilder = LuceneIndexStorageBuilder.create(); storageBuilder = LuceneIndexStorageBuilder.create();
storageBuilder.withFileSystem( fileSystem ).withIndexIdentifier( "insightRelationships" ) storageBuilder.withFileSystem( fileSystem ).withIndexIdentifier( "insightRelationships" )
.withDirectoryFactory( directoryFactory( false, fileSystem ) ) .withDirectoryFactory( directoryFactory( false, fileSystem ) )
.withIndexRootFolder( Paths.get( file.getAbsolutePath(),"insightindex" ).toFile() ); .withIndexRootFolder( Paths.get( file.getAbsolutePath(),"insightindex" ).toFile() );
relationshipIndex = new BloomLuceneIndex( storageBuilder.build(), partitionFactory, properties ); relationshipIndex = new BloomLuceneIndex( storageBuilder.build(), partitionFactory, properties, analyzer);
relationshipIndex.open(); relationshipIndex.open();
} }


Expand Down
Expand Up @@ -103,10 +103,10 @@ private void updatePropertyData( Iterable<PropertyEntry<Node>> propertyEntries,
return; return;
} }


Document document = BloomInsightDocumentStructure.documentRepresentingProperties( nodeId, allProperties ); Document document = BloomDocumentStructure.documentRepresentingProperties( nodeId, allProperties );
try try
{ {
nodeIndex.getIndexWriter().updateDocument( BloomInsightDocumentStructure.newTermForChangeOrRemove( nodeId ), document ); nodeIndex.getIndexWriter().updateDocument( BloomDocumentStructure.newTermForChangeOrRemove( nodeId ), document );
} }
catch ( IOException e ) catch ( IOException e )
{ {
Expand All @@ -129,7 +129,7 @@ private void deleteIndexData( Iterable<Node> nodes, WritableDatabaseBloomIndex n
{ {
try try
{ {
nodeIndex.getIndexWriter().deleteDocuments( BloomInsightDocumentStructure.newTermForChangeOrRemove( node.getId() ) ); nodeIndex.getIndexWriter().deleteDocuments( BloomDocumentStructure.newTermForChangeOrRemove( node.getId() ) );
} }
catch ( IOException e ) catch ( IOException e )
{ {
Expand Down
Expand Up @@ -19,6 +19,7 @@
*/ */
package org.neo4j.kernel.api.impl.bloom; package org.neo4j.kernel.api.impl.bloom;


import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
Expand All @@ -41,12 +42,13 @@ class BloomLuceneIndex extends AbstractLuceneIndex
{ {


private String[] properties; private String[] properties;
private final Analyzer analyzer;


BloomLuceneIndex( PartitionedIndexStorage indexStorage, IndexPartitionFactory partitionFactory, BloomLuceneIndex( PartitionedIndexStorage indexStorage, IndexPartitionFactory partitionFactory, String[] properties, Analyzer analyzer )
String[] properties )
{ {
super( indexStorage, partitionFactory ); super( indexStorage, partitionFactory );
this.properties = properties; this.properties = properties;
this.analyzer = analyzer;
} }


private static final String KEY_STATUS = "status"; private static final String KEY_STATUS = "status";
Expand Down Expand Up @@ -129,14 +131,14 @@ public void markAsFailed( String failure ) throws IOException
private SimpleBloomIndexReader createSimpleReader( List<AbstractIndexPartition> partitions ) throws IOException private SimpleBloomIndexReader createSimpleReader( List<AbstractIndexPartition> partitions ) throws IOException
{ {
AbstractIndexPartition singlePartition = getFirstPartition( partitions ); AbstractIndexPartition singlePartition = getFirstPartition( partitions );
return new SimpleBloomIndexReader( singlePartition.acquireSearcher(), properties ); return new SimpleBloomIndexReader( singlePartition.acquireSearcher(), properties, analyzer );
} }


private PartitionedBloomIndexReader createPartitionedReader( List<AbstractIndexPartition> partitions ) private PartitionedBloomIndexReader createPartitionedReader( List<AbstractIndexPartition> partitions )
throws IOException throws IOException
{ {
List<PartitionSearcher> searchers = acquireSearchers( partitions ); List<PartitionSearcher> searchers = acquireSearchers( partitions );
return new PartitionedBloomIndexReader( searchers, properties ); return new PartitionedBloomIndexReader( searchers, properties, analyzer );
} }


} }
Expand Up @@ -19,6 +19,8 @@
*/ */
package org.neo4j.kernel.api.impl.bloom; package org.neo4j.kernel.api.impl.bloom;


import org.apache.lucene.analysis.Analyzer;

import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
Expand All @@ -41,10 +43,9 @@ class PartitionedBloomIndexReader implements BloomIndexReader


private final List<BloomIndexReader> indexReaders; private final List<BloomIndexReader> indexReaders;


PartitionedBloomIndexReader( List<PartitionSearcher> partitionSearchers, String[] properties ) PartitionedBloomIndexReader( List<PartitionSearcher> partitionSearchers, String[] properties, Analyzer analyzer )
{ {
this( partitionSearchers.stream().map( partitionSearcher -> new SimpleBloomIndexReader( partitionSearcher, this( partitionSearchers.stream().map( partitionSearcher -> new SimpleBloomIndexReader( partitionSearcher, properties, analyzer ) )
properties ) )
.collect( Collectors.toList() ) ); .collect( Collectors.toList() ) );
} }


Expand Down
Expand Up @@ -19,7 +19,7 @@
*/ */
package org.neo4j.kernel.api.impl.bloom; package org.neo4j.kernel.api.impl.bloom;


import org.apache.lucene.analysis.en.EnglishAnalyzer; import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.queryparser.classic.MultiFieldQueryParser; import org.apache.lucene.queryparser.classic.MultiFieldQueryParser;
import org.apache.lucene.queryparser.classic.QueryParser; import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanClause;
Expand All @@ -45,22 +45,21 @@
class SimpleBloomIndexReader implements BloomIndexReader class SimpleBloomIndexReader implements BloomIndexReader
{ {
private final PartitionSearcher partitionSearcher; private final PartitionSearcher partitionSearcher;
private final EnglishAnalyzer analyzer; private final Analyzer analyzer;
private String[] properties; private String[] properties;
private final QueryParser multiFieldQueryParser;


SimpleBloomIndexReader( PartitionSearcher partitionSearcher, String[] properties ) SimpleBloomIndexReader( PartitionSearcher partitionSearcher, String[] properties, Analyzer analyzer )
{ {
this.partitionSearcher = partitionSearcher; this.partitionSearcher = partitionSearcher;
this.properties = properties; this.properties = properties;
analyzer = new EnglishAnalyzer(); this.analyzer = analyzer;
multiFieldQueryParser = new MultiFieldQueryParser( properties, analyzer );
multiFieldQueryParser.setDefaultOperator( QueryParser.Operator.OR );
} }


public PrimitiveLongIterator query( String... query ) public PrimitiveLongIterator query( String... query )
{ {
BooleanQuery.Builder builder = new BooleanQuery.Builder(); BooleanQuery.Builder builder = new BooleanQuery.Builder();
QueryParser multiFieldQueryParser = new MultiFieldQueryParser( properties, analyzer );
multiFieldQueryParser.setDefaultOperator( QueryParser.Operator.OR );
for ( String s : query ) for ( String s : query )
{ {
for ( String property : properties ) for ( String property : properties )
Expand Down

0 comments on commit 8fca632

Please sign in to comment.