Package org.apache.solr.client.solrj.impl

Examples of org.apache.solr.client.solrj.impl.CommonsHttpSolrServer


  private final QueryFilters filters;

  public SolrSearchBean(Configuration conf, String solrServer)
  throws IOException {
    solr = new CommonsHttpSolrServer(solrServer);
    filters = new QueryFilters(conf);
  }
View Full Code Here


  }

  @Override
  public void configure(JobConf job) {
    try {
      solr = new CommonsHttpSolrServer(job.get(SolrConstants.SERVER_URL));
    } catch (MalformedURLException e) {
      throw new RuntimeException(e);
    }
  }
View Full Code Here

  public static class SolrInputFormat implements InputFormat<Text, SolrRecord> {

    /** Return each index as a split. */
    public InputSplit[] getSplits(JobConf job, int numSplits) throws IOException {
      SolrServer solr = new CommonsHttpSolrServer(job.get(SolrConstants.SERVER_URL));

      final SolrQuery solrQuery = new SolrQuery(SOLR_GET_ALL_QUERY);
      solrQuery.setFields(SolrConstants.ID_FIELD);
      solrQuery.setRows(1);

      QueryResponse response;
      try {
        response = solr.query(solrQuery);
      } catch (final SolrServerException e) {
        throw new IOException(e);
      }

      int numResults = (int)response.getResults().getNumFound();
View Full Code Here

    public RecordReader<Text, SolrRecord> getRecordReader(final InputSplit split,
        final JobConf job,
        Reporter reporter)
        throws IOException {

      SolrServer solr = new CommonsHttpSolrServer(job.get(SolrConstants.SERVER_URL));
      SolrInputSplit solrSplit = (SolrInputSplit) split;
      final int numDocs = solrSplit.getNumDocs();
     
      SolrQuery solrQuery = new SolrQuery(SOLR_GET_ALL_QUERY);
      solrQuery.setFields(SolrConstants.ID_FIELD, SolrConstants.BOOST_FIELD,
                          SolrConstants.TIMESTAMP_FIELD,
                          SolrConstants.DIGEST_FIELD);
      solrQuery.setStart(solrSplit.getDocBegin());
      solrQuery.setRows(numDocs);

      QueryResponse response;
      try {
        response = solr.query(solrQuery);
      } catch (final SolrServerException e) {
        throw new IOException(e);
      }

      final SolrDocumentList solrDocs = response.getResults();
View Full Code Here

  private int commitSize;

  public void open(JobConf job, String name)
  throws IOException {
    solr = new CommonsHttpSolrServer(job.get(SolrConstants.SERVER_URL));
    commitSize = job.getInt(SolrConstants.COMMIT_SIZE, 1000);
  }
View Full Code Here

  private SolrServer createServer( String name )
  {
    try {
      // setup the server...
      String url = "http://localhost:"+port+context+"/"+name;
      CommonsHttpSolrServer s = new CommonsHttpSolrServer( url );
      s.setConnectionTimeout(100); // 1/10th sec
      s.setDefaultMaxConnectionsPerHost(100);
      s.setMaxTotalConnections(100);
      return s;
    }
    catch( Exception ex ) {
      throw new RuntimeException( ex );
    }
View Full Code Here

  protected SolrServer createNewSolrServer()
  {
    try {
      // setup the server...
      String url = "http://localhost:"+port+context;       // smaller queue size hits locks more often
      CommonsHttpSolrServer s = new StreamingUpdateSolrServer( url, 2, 5 ) {
        @Override
        public void handleError(Throwable ex) {
          // do somethign...
        }
      };
      s.setConnectionTimeout(100); // 1/10th sec
      s.setDefaultMaxConnectionsPerHost(100);
      s.setMaxTotalConnections(100);
      return s;
    }
    catch( Exception ex ) {
      throw new RuntimeException( ex );
    }
View Full Code Here

  @Override
  protected SolrServer createNewSolrServer() {
    try {
      // setup the server...
      String url = "http://localhost:" + port + context;
      CommonsHttpSolrServer s = new CommonsHttpSolrServer(url);
      s.setRequestWriter(new BinaryRequestWriter());
      s.setConnectionTimeout(100); // 1/10th sec
      s.setDefaultMaxConnectionsPerHost(100);
      s.setMaxTotalConnections(100);
      return s;
    }
    catch (Exception ex) {
      throw new RuntimeException(ex);
    }
View Full Code Here

          String url = "http://" + shard;

          params.remove(CommonParams.WT); // use default (currently javabin)
          params.remove(CommonParams.VERSION);

          SolrServer server = new CommonsHttpSolrServer(url, client);
          // SolrRequest req = new QueryRequest(SolrRequest.METHOD.POST, "/select");
          // use generic request to avoid extra processing of queries
          QueryRequest req = new QueryRequest(params);
          req.setMethod(SolrRequest.METHOD.POST);

          // no need to set the response parser as binary is the default
          // req.setResponseParser(new BinaryResponseParser());
          // srsp.rsp = server.request(req);
          // srsp.rsp = server.query(sreq.params);

          ssr.nl = server.request(req);
        } catch (Throwable th) {
          srsp.setException(th);
          if (th instanceof SolrException) {
            srsp.setResponseCode(((SolrException)th).code());
          } else {
View Full Code Here

    for (Cluster.Instance instance : instances) {
      String publicIp = instance.getPublicIp();

      LOG.info("Adding a document to instance " + instance.getId() + " @ " + publicIp);
     
      CommonsHttpSolrServer solrServer = new CommonsHttpSolrServer(String.format("http://%s:%s/solr/core0", instance.getPublicHostName(), SOLR_PORT));

      SolrInputDocument doc = new SolrInputDocument();
      doc.addField("name", "Apache Whirr");
      doc.addField("inceptionYear", "2010");

      solrServer.add(doc);
      solrServer.commit();

      LOG.info("Committed document to instance " + instance.getId() + " @ " + publicIp);

      LOG.info("Performing a search on instance " + instance.getId() + " @ " + publicIp);

      SolrQuery query = new SolrQuery("name:whirr");
      QueryResponse response = solrServer.query(query);
      SolrDocumentList results = response.getResults();
      assertEquals("Search on instance " + instance.getId() + " did NOT return a document!" , 1, results.size());

      SolrDocument resultDoc = results.get(0);
      assertEquals("name field on document of instance " + instance.getId() + " is incorrect", "Apache Whirr", resultDoc.get("name"));
View Full Code Here

TOP

Related Classes of org.apache.solr.client.solrj.impl.CommonsHttpSolrServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.