Register custom TokenizerFactory with Maven

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Register custom TokenizerFactory with Maven

Pachzelt, Adrian
Hi everybody,

I am currently writing a custom TokenizerFactory for Lucene. However, as far as I understood, Tokenizer are called by their name like this for the StandardTokenizer: tokenizerFactory("Standard").create(newAttributeFactory());

Accordingly, my code looks like this: tokenizerFactory("TaggedText").create(newAttributeFactory());

I apply Maven for compiling my code. Where do I need to register my Factory class, since, as expected, I get the compiling error:

“ A SPI class of type org.apache.lucene.analysis.util.TokenizerFactory with name ‘TaggedText’ does not exist. You need to add the corresponding JAR file supporting this SPI to your classpath.”

How can I do this?

I am glad for any advice!

Thanks a lot!

Cheers,

Adrian
Reply | Threaded
Open this post in threaded view
|

Re: Register custom TokenizerFactory with Maven

Uwe Schindler
Hi,

You have to add a META-INF/services file into the JAR file with all factories contained in the JAR file listed. More info in the documentation of java.util.ServiceLoader: https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html

The name to use for lookup is generated from the simple class name, basically it lowercases and removes "(Token)FilterFactory" from it.

Uwe

Am March 22, 2018 12:25:41 PM UTC schrieb "Pachzelt, Adrian" <[hidden email]>:

>Hi everybody,
>
>I am currently writing a custom TokenizerFactory for Lucene. However,
>as far as I understood, Tokenizer are called by their name like this
>for the StandardTokenizer:
>tokenizerFactory("Standard").create(newAttributeFactory());
>
>Accordingly, my code looks like this:
>tokenizerFactory("TaggedText").create(newAttributeFactory());
>
>I apply Maven for compiling my code. Where do I need to register my
>Factory class, since, as expected, I get the compiling error:
>
>“ A SPI class of type org.apache.lucene.analysis.util.TokenizerFactory
>with name ‘TaggedText’ does not exist. You need to add the
>corresponding JAR file supporting this SPI to your classpath.”
>
>How can I do this?
>
>I am glad for any advice!
>
>Thanks a lot!
>
>Cheers,
>
>Adrian

--
Uwe Schindler
Achterdiek 19, 28357 Bremen
https://www.thetaphi.de