Search code examples
postgresqljdbcsolrsolrcloud

Could not initialize class JdbcSynonymFilterFactory


I'm new to solr, I want to add a field type with JdbcSynonymFilter and JdbcStopFilter to solr schema. I added my data source same as instruction in this link: Loading stopwords from Postgresql to Solr6

then i configured managed-schema with code below:

<fieldType name="new_string" class="solr.TextField">
     <analyzer>
        <tokenizer class="solr.PatternTokenizerFactory" pattern="[\s]+" />
        <filter class="com.s24.search.solr.analysis.jdbc.JdbcSynonymFilterFactory"   
           sql="SELECT concat(term, '=>', use) as line FROM thesaurus;" 
           dataSource="jdbc/dsTest" ignoreCase="false" expand="true" />
        <filter class="com.s24.search.solr.analysis.jdbc.JdbcStopFilterFactory"   
        sql="SELECT stopword FROM stopwords" 
        dataSource="jdbc/dsTest"/>
     </analyzer>
    </fieldType>

I added solr-jdbc to dist folder, postgressql driver, beanutils and dbutils to contrib/jdbc/lib folder. Then, I included libs in solrconfig.xml of data_driven_schema_configs:

<lib dir="${solr.install.dir:../../../..}/contrib/jdbc/lib" regex=".*\.jar" />
  <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-jdbc-\d.*\.jar" />

I encountered the following error when I was trying to start SolrCloud.

"Could not initialize class com.s24.search.solr.analysis.jdbc.JdbcSynonymFilterFactory,trace=java.lang.NoClassDefFoundError: Could not initialize class com.s24.search.solr.analysis.jdbc.JdbcSynonymFilterFactory"


Solution

  • I'm one of the developer from the solr-jdbc project, tried to integrate our project into the current solr version 6.5.1 and followed these steps:

    1. Download solr zip and extract it

    2. Place your fieldtype into the managed-schema file: ~/.../solr-6.5.1/example/example-DIH/solr/solr/conf

    <fieldType name="new_string" class="solr.TextField">
       <analyzer>
          <tokenizer class="solr.PatternTokenizerFactory" pattern="[\s]+" />
          <filter class="com.s24.search.solr.analysis.jdbc.JdbcSynonymFilterFactory"   
             sql="SELECT concat(term, '=>', use) as line FROM thesaurus;" 
             dataSource="jdbc/dsTest" ignoreCase="false" expand="true" />
          <filter class="com.s24.search.solr.analysis.jdbc.JdbcStopFilterFactory"   
             sql="SELECT stopword FROM stopwords" 
             dataSource="jdbc/dsTest"/>
       </analyzer>
    </fieldType>

    1. Add the following line to: ~/.../solr-6.5.1/example/example-DIH/solr/solr/conf/solrconfig.xml

    <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-jdbc-2.3.7.jar" />

    1. Compile the unpacked solr-jdbc release: Run "mvn clean install" in the solr-jdbc-2.3.7 folder

    2. Place the compiled jar (solr-jdbc-2.3.7/target/solr-jdbc-2.3.7.jar) into the ~/.../solr-6.5.1/dist/ folder

    3. Run the Solr DIH example "~/.../solr-6.5.1/bin/solr -e dih"

    Now there is no NoClassDefFound exception.

    After that you have to create a jndi resource in your jetty and everything should run fine.

    Greetings, Tobias