Package org.apache.solr.client.solrj

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


    try
    {
      String result = null;
     
      // Establish Connection
      SolrServer server = new SolrConnection().getSolrServer(solrLocation);
     
      // Create Solr Query
      String fileLocation = null;
     
      // Crete SolrQuery Object
      SolrQuery query = new SolrQuery();
   
      // Construct queryString
      StringBuffer queryString = new StringBuffer("record-uri:");
     
      queryString.append('"');
      queryString.append(recordUri);
      queryString.append('"');
     
      // Set queryString to query Object
      query.setQuery(queryString.toString());
     
      // Get QueryResponse from Server
        QueryResponse rsp = server.query(query);
       
        // Get records from QueryResponse Object
        SolrDocumentList docs = rsp.getResults();
       
        // If doc size is greater than 1 then throw Exception
View Full Code Here


   */
  private void addStashDocumentToSOLRIndex(String solrLocation, List<Pointer> pointers) throws SSAFSolrException {
    try {
     
      // Establish Connection
      SolrServer server = new SolrConnection().getSolrServer(solrLocation);
     
      // Create List of SolrInputDocuments Object
      List<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
     
      // Iterate through pointers
      for (int j=0 ; j < pointers.size(); j++) {
       
        // Get a Pointer Object
        Pointer pointer = pointers.get(j);
       
        // Create SolrInputDocument Object
        SolrInputDocument doc = new SolrInputDocument();
       
        // Get values from Pointer Values into local Variables
        String recordUri = pointer.getRecordUri();
        String stashFilePath = pointer.getStashFilepath();
        String stashType = pointer.getStashType();
        XMLGregorianCalendar stashDate = pointer.getStashDatetime();
        String pointerFilePath = pointer.getPointerFilepath();
        PointerItems pointerItems = pointer.getPointerItems();
       
        // Peform Mandatory Check
        if ( recordUri != null && 
           stashFilePath != null &&
           stashType != null &&
           stashDate != null &&
           pointerItems != null &&
           pointerFilePath != null)
        {
       
          // Add local Variables values to SolrInputDocument
            doc.addField( "record-uri", recordUri);
            doc.addField("stash-filepath", stashFilePath);
            doc.addField("stash-type", stashType);
            doc.addField("stash-date", stashDate);
            doc.addField("pointer-filepath", pointerFilePath);
           
            List<PointerItem> pointerItemList = pointerItems.getPointerItem();
           
            // Get Pointer Items and add to SolrInputDocument
            for (int i = 0; i < pointerItemList.size(); i++)
            {
              PointerItem pointerItem = pointerItemList.get(i);
             
              if (pointerItem != null && (pointerItem.isIndexed()!=null && pointerItem.isIndexed() ))
              {
                if ((pointerItem.getPointerValue() != null) && (pointerItem.getPointerName() != null)) {
                  doc.addField("stash-content", pointerItem.getPointerName().toLowerCase().replace(' ', '_')+"_"+pointerItem.getPointerValue().toLowerCase().replace(' ', '_'));
                } else {
                  if ( (pointerItem.getPointerBase64Value() != null) ||
                      (pointerItem.getPointerHexValue() != null) ||
                          (pointerItem.getPointerUriValue() != null)
                     )
                  {
                    throw new SSAFSolrException();
                  }
                }
               
              }
            }
 
        } else {
          SSAFSolrException ssafException =  new SSAFSolrException();
          ssafException.setFatalError(SSAFSolrErrorCodes.MISSING_DATA_ERROR);
          throw ssafException;
        }
        docs.add(doc);
     
     
      // Add Docs to Server & Commit
      // Records will not be stored into Index until commit is performed.
      server.add(docs);
      server.commit();
    }
    catch (Exception e)
    {
      SSAFSolrException ssafException =  new SSAFSolrException();
      ssafException.setFatalError(SSAFSolrErrorCodes.UNABLE_TO_STASH);
View Full Code Here

    try
    {
      List<String> result = new ArrayList<String>();
     
      // Establish Connection
      SolrServer server = new SolrConnection().getSolrServer(solrLocation);
     
      // Create Solr Query
      String fileLocation = null;
     
      // Get File system location from Solr Results
      SolrQuery query = new SolrQuery();
     
      query.setQuery(queryString.toString());
      query.setStart(start);
      query.setRows(rows);

      // Get QueryResponse from Server
        QueryResponse rsp = server.query(query);
       
        // Get SolrDocumentList
        SolrDocumentList docs = rsp.getResults();
       
        long size = docs.getNumFound();
View Full Code Here

    FileOutputFormat.setOutputPath(job, tmp);
    try {
      JobClient.runJob(job);
      // do the commits once and for all the reducers in one go
      SolrServer solr =  new CommonsHttpSolrServer(solrUrl);
      solr.commit();
    }
    catch (Exception e){
      LOG.error(e);
    } finally {
      FileSystem.get(job).delete(tmp, true);
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

    public SolrServer[] getServices() {
        ServiceReference[] refs = getServiceReferences();
        Collection<SolrServer> servers = new ArrayList<SolrServer>(refs.length);
        if(refs != null){
            for(ServiceReference ref : refs){
                SolrServer server = getService(ref);
                if(server != null){
                    servers.add(server);
                } //else null ... ignore
            }
        }
View Full Code Here

    FileOutputFormat.setOutputPath(job, tmp);
    try {
      JobClient.runJob(job);
      // do the commits once and for all the reducers in one go
      SolrServer solr =  SolrUtils.getCommonsHttpSolrServer(job);

      if (!noCommit) {
        solr.commit();
      }
      long end = System.currentTimeMillis();
      LOG.info("SolrIndexer: finished at " + sdf.format(end) + ", elapsed: " + TimingUtil.elapsedTime(start, end));
    }
    catch (Exception 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 = SolrUtils.getCommonsHttpSolrServer(job);

      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 = SolrUtils.getCommonsHttpSolrServer(job);
      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

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.