Package org.apache.solr.client.solrj

Examples of org.apache.solr.client.solrj.SolrServer


  private int commitSize;
  private int numDeletes = 0;
  private boolean delete = false;

  public void open(JobConf job, String name) throws IOException {
    SolrServer server = SolrUtils.getCommonsHttpSolrServer(job);
    init(server, job);
  }
View Full Code Here


    @Override
    public List<InputSplit> getSplits(JobContext context)
    throws IOException, InterruptedException {
      Configuration conf = context.getConfiguration();
      int numSplits = context.getNumReduceTasks();
      SolrServer solr = new CommonsHttpSolrServer(conf.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

    @Override
    public RecordReader<Text, SolrRecord> createRecordReader(InputSplit split,
        TaskAttemptContext context) throws IOException, InterruptedException {
      Configuration conf = context.getConfiguration();
      SolrServer solr = new CommonsHttpSolrServer(conf.get(SolrConstants.SERVER_URL));
      SolrInputSplit solrSplit = (SolrInputSplit) split;
      final int numDocs = (int) solrSplit.getLength();
     
      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

    run(ToolUtil.toArgMap(
        Nutch.ARG_SOLR, solrUrl,
        Nutch.ARG_BATCH, batchId));
    // do the commits once and for all the reducers in one go
    SolrServer solr = new CommonsHttpSolrServer(solrUrl);
    if (getConf().getBoolean(SolrConstants.COMMIT_INDEX, true)) {
      solr.commit();
    }
    LOG.info("SolrIndexerJob: done.");
  }
View Full Code Here

    @Override
    public List<InputSplit> getSplits(JobContext context)
    throws IOException, InterruptedException {
      Configuration conf = context.getConfiguration();
      int numSplits = context.getNumReduceTasks();
      SolrServer solr = SolrUtils.getCommonsHttpSolrServer(conf);

      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

    @Override
    public RecordReader<Text, SolrRecord> createRecordReader(InputSplit split,
        TaskAttemptContext context) throws IOException, InterruptedException {
      Configuration conf = context.getConfiguration();
      SolrServer solr = SolrUtils.getCommonsHttpSolrServer(conf);
      SolrInputSplit solrSplit = (SolrInputSplit) split;
      final int numDocs = (int) solrSplit.getLength();
     
      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

     */
    @Override
    public String put(ContentItem ci, String ldProgramName) throws StoreException {
        SolrInputDocument doc = new SolrInputDocument();
        addDefaultFields(ci, doc);
        SolrServer solrServer;
        if (ldProgramName == null || ldProgramName.isEmpty()
            || ldProgramName.equals(SolrCoreManager.CONTENTHUB_DEFAULT_INDEX_NAME)) {

            addSolrSpecificFields(ci, doc);
            solrServer = SolrCoreManager.getInstance(bundleContext, managedSolrServer).getServer();
        } else {
            addSolrSpecificFields(ci, doc, ldProgramName);
            solrServer = SolrCoreManager.getInstance(bundleContext, managedSolrServer).getServer(
                ldProgramName);
        }
        updateEnhancementGraph(ci);
        try {
            solrServer.add(doc);
            solrServer.commit();
            log.debug("Documents are committed to Solr Server successfully.");
        } catch (SolrServerException e) {
            log.error("Solr Server Exception", e);
            throw new StoreException(e.getMessage(), e);
        } catch (IOException e) {
View Full Code Here

    @Override
    public ContentItem get(String id, String ldProgramName) throws StoreException {
        if (id == null) {
            throw new IllegalArgumentException("Id of the requested ContentItem cannot be null");
        }
        SolrServer solrServer = SolrCoreManager.getInstance(bundleContext, managedSolrServer).getServer(
            ldProgramName);
        byte[] content = null;
        String mimeType = null;

        SolrQuery query = new SolrQuery();
        StringBuilder queryString = new StringBuilder();
        queryString.append(SolrFieldName.ID.toString());
        queryString.append(":\"");
        queryString.append(id);
        queryString.append('\"');
        query.setQuery(queryString.toString());
        QueryResponse response;
        try {
            response = solrServer.query(query);
            SolrDocumentList results = response.getResults();
            if (results != null && results.size() > 0) {
                SolrDocument result = results.get(0);
                content = (byte[]) result.getFieldValue(SolrFieldName.BINARYCONTENT.toString());
                mimeType = (String) result.getFieldValue(SolrFieldName.MIMETYPE.toString());
View Full Code Here

    }

    @Override
    public void deleteById(String id, String ldProgramName) throws StoreException {
        if (id == null || id.isEmpty()) return;
        SolrServer solrServer = SolrCoreManager.getInstance(bundleContext, managedSolrServer).getServer(
            ldProgramName);
        removeEnhancements(id);
        try {
            solrServer.deleteById(id);
            solrServer.commit();
        } catch (SolrServerException e) {
            log.error("Solr Server Exception", e);
            throw new StoreException(e.getMessage(), e);
        } catch (IOException e) {
            log.error("IOException", e);
View Full Code Here

        deleteById(id, SolrCoreManager.CONTENTHUB_DEFAULT_INDEX_NAME);
    }

    @Override
    public void deleteById(List<String> idList, String ldProgramName) throws StoreException {
        SolrServer solrServer = SolrCoreManager.getInstance(bundleContext, managedSolrServer).getServer(
            ldProgramName);
        for (int i = 0; i < idList.size(); i++) {
            String id = idList.get(i);
            idList.remove(i);
            idList.add(i, id);
        }
        try {
            solrServer.deleteById(idList);
            solrServer.commit();
        } catch (SolrServerException e) {
            log.error("Solr Server Exception", e);
            throw new StoreException(e.getMessage(), e);
        } catch (IOException e) {
            log.error("IOException", e);
View Full Code Here

TOP

Related Classes of org.apache.solr.client.solrj.SolrServer

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.