Loading stopwords from Postgresql to Solr6

2019-07-28 20:28发布

问题:

I am new to solr. I want to load synonyms or stopwords from DB instead of txt file to solr at analyzing phase. How can I acheive it in solr 6.

I tried porting Solr-JDBC(https://github.com/shopping24/solr-jdbc), and I configured web.xml with code below:

<resource-ref>
        <description>my datasource</description>
        <res-ref-name>jdbc/dsTest</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

and solr-jetty-context.xml with:

<New id="dsTest" class="org.eclipse.jetty.plus.jndi.Resource">
     <Arg></Arg>
     <Arg>jdbc/dsTest</Arg>
     <Arg>
        <New class="org.postgresql.ds.PGSimpleDataSource">
           <Set name="User">username</Set>
           <Set name="Password">password</Set>
           <Set name="DatabaseName">DBName</Set>
           <Set name="ServerName">localhost</Set>
           <Set name="PortNumber">5432</Set>
        </New>
     </Arg>
  </New>

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

Error: did not see solr at http://localhost:8983/solr come online within 30

Also, the needed libraries are added to the correct folder.

回答1:

Honestly I think this solution is a mess, I strongly suggest to export your synonyms and stopwords in a text file and save them overwriting your old configuration files.

After that, maybe you already know, you have to reload the core/collection configuration and, depending from your analyzer chain, reindex all the documents involved.

On the other hand, if you really want follow this way, looking at your question I can give you the following suggestion, you have to double check:

  • jdbc driver (check you copied postgresql-xxxxx.jdbc.jar to $JETTY_HOME/lib/ext)
  • network (check that postgres instance is up and listening on localhost:5432)
  • account (check username and password are correct)
  • db name (check the such db is present and the user has the permission)


回答2:

Yes, it is fixed, I have downloaded jetty-jndi.jar but forgot to add it in lib folder.

  • So do not forget add postgresql-xxxx, jetty-jndi and jetty-plus to server/lib