Class SolrProxy

java.lang.Object
org.opensextant.util.SolrUtil
org.opensextant.util.SolrProxy

public class SolrProxy extends SolrUtil
As Xponents is a multi-core instance of Solr, a single default solr home and default solr core does not make sense. Each wrapper around Solr (via SolrProxy) needs to name the solr home and an explicit core name.
Author:
ubaldino
  • Field Details

    • solrHome

      protected String solrHome
    • coreName

      protected String coreName
    • logger

      protected org.slf4j.Logger logger
    • solrClient

      protected org.apache.solr.client.solrj.SolrClient solrClient
    • server_url

      protected URL server_url
  • Constructor Details

    • SolrProxy

      public SolrProxy(URL url)
      Initializes a Solr server from a URL
    • SolrProxy

      public SolrProxy(String core) throws org.opensextant.ConfigException
      Initializes a Solr server from the SOLR_HOME environment variable.
      Parameters:
      core - name of solr core
      Throws:
      org.opensextant.ConfigException - cfg err
    • SolrProxy

      public SolrProxy(String solr_home, String core) throws org.opensextant.ConfigException
      Initializes a Solr server from the SOLR_HOME environment variable.
      Parameters:
      solr_home - the solr_home
      core - name of solr core
      Throws:
      org.opensextant.ConfigException - cfg err
  • Method Details

    • deriveSolrHome

      public static String deriveSolrHome(String given) throws org.opensextant.ConfigException
      A single method to help find a suitable value for SOLR HOME If given is null, then system variables are checked.
      Parameters:
      given - solr home.
      Throws:
      org.opensextant.ConfigException
    • setWritable

      public void setWritable(boolean b)
    • isWritable

      public boolean isWritable()
      Is Solr server instance allowed to write to index?
      Returns:
      true if index is intended to be writable.
    • initializeHTTP

      public static org.apache.solr.client.solrj.SolrClient initializeHTTP(URL url)
      Get an HTTP server for Solr.
      Parameters:
      url - server represented by URL
      Returns:
      Instance of a Solr server
    • setupCore

      public static org.apache.solr.client.solrj.embedded.EmbeddedSolrServer setupCore(String _solrHome, String _coreName) throws org.opensextant.ConfigException
      Creates an EmbeddedSolrServer given solr home & the core to use. These may be null and you get the default.
      Parameters:
      _solrHome - solr home
      _coreName - name of core
      Returns:
      the embedded solr server
      Throws:
      org.opensextant.ConfigException - on err
    • searchGazetteer

      public static List<org.opensextant.data.Place> searchGazetteer(org.apache.solr.client.solrj.SolrClient index, org.apache.solr.common.params.SolrParams qparams) throws org.apache.solr.client.solrj.SolrServerException, IOException
      Search an OpenSextant solr gazetteer.
      Parameters:
      index - solr server handle
      qparams - search parameters
      Returns:
      list of places
      Throws:
      org.apache.solr.client.solrj.SolrServerException - on err
      IOException
    • add

      public void add(org.apache.solr.common.SolrInputDocument solrRecord) throws Exception
      Add one solr record.
      Parameters:
      solrRecord - document/gazetteer or other entry to add to index
      Throws:
      Exception - on err ???
    • add

      public void add(Collection<org.apache.solr.common.SolrInputDocument> solrRecords) throws Exception
      Add many solr records.
      Parameters:
      solrRecords - array of records to add
      Throws:
      Exception - on err
    • openIndex

      public void openIndex() throws org.opensextant.ConfigException, IOException
      Reopen an existing solr proxy.
      Throws:
      org.opensextant.ConfigException - the config exception
      IOException - Signals that an I/O exception has occurred.
    • optimize

      public void optimize() throws IOException, org.apache.solr.client.solrj.SolrServerException
      Optimizes the Solr server.
      Throws:
      IOException - on err
      org.apache.solr.client.solrj.SolrServerException - the solr server exception
    • saveIndex

      public void saveIndex()
      Invokes saveIndex(false)
    • saveIndex

      public void saveIndex(boolean commit)
      Save and optionally records to server or index On failure, current accumulating request is cleared and nullified to avoid retransmitting bad data. In the event of a failure all records since last "saveIndex" would be lost and should be resubmitted.
      Parameters:
      commit - true, if we should commit updates
    • saveAndReopen

      public void saveAndReopen() throws org.opensextant.ConfigException, IOException
      Save and reopen.
      Throws:
      org.opensextant.ConfigException - the config exception
      IOException - on err
    • close

      public void close() throws IOException
      Throws:
      IOException
    • getInternalSolrClient

      public org.apache.solr.client.solrj.SolrClient getInternalSolrClient()