How to add custom Lucene analyzer?


(Wergeland) #1

According to the Neo4j 3.5.0 announcement, it should be possible to add custom Lucene analyzer, but I am not able to find more information on this in the documentation or the forum.

The analyzer we need should actually be included in Lucene (the SimpleAnalyzer - case insensitive without stop words), but it is not listed by call db.index.fulltext.listAvailableAnalyzers. As I understand it, all we need to do is to register it in the list of available analyzers. Another option would be to override the stopwords for the standard analyzer

I would be very happy if someone can point me in the correct direction or provide an example!

Best regards,

√ėyvind Wergeland

(Stefan Armbruster) #2

Registration of custom analyzers is simple. Just create a java class extending AnalyzerProvider that provides the internal name and implementation of the custom analyzer.
As an example take a look at

Note that the @Service.Implementation annotation might not work without some tweaks to your build system. Instead make sure you have a service loader file in place:
META-INF/services/org.neo4j.graphdb.index.fulltext.AnalyzerProvider listing your analyzer provider classes and bundle this with your implementation into a jar file.
That jar file needs to be dropped into neo4j's /plugins folder.

(Wergeland) #3

That worked like a charm - thank you very much!

I noted that @org.neo4j.helpers.Service.Implementation is deprecated. We use to create service loader configuration.