Package org.apache.solr.client.solrj.request

Examples of org.apache.solr.client.solrj.request.ContentStreamUpdateRequest


            throw new IOException(e);
        }
    }

    public void add(final File file, final String solrId) throws IOException {
        final ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update/extract");
        up.addFile(file);
        up.setParam("literal.id", solrId);
        up.setParam("uprefix", "attr_");
        up.setParam("fmap.content", "attr_content");
        //up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
        try {
            this.server.request(up);
            this.server.commit();
        } catch (final SolrServerException e) {
View Full Code Here


        }

        if (body instanceof File) {
            MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
            String mimeType = mimeTypesMap.getContentType((File)body);
            ContentStreamUpdateRequest updateRequest = new ContentStreamUpdateRequest(getRequestHandler());
            updateRequest.addFile((File) body, mimeType);

            for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) {
                if (entry.getKey().startsWith(SolrConstants.PARAM)) {
                    String paramName = entry.getKey().substring(SolrConstants.PARAM.length());
                    updateRequest.setParam(paramName, entry.getValue().toString());
                }
            }

            updateRequest.process(solrServer);

        } else if (body instanceof SolrInputDocument) {

            UpdateRequest updateRequest = new UpdateRequest(getRequestHandler());
            updateRequest.add((SolrInputDocument) body);

            updateRequest.process(solrServer);

        } else {

            boolean hasSolrHeaders = false;
            for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) {
                if (entry.getKey().startsWith(SolrConstants.FIELD)) {
                    hasSolrHeaders = true;
                    break;
                }
            }

            if (hasSolrHeaders) {

                UpdateRequest updateRequest = new UpdateRequest(getRequestHandler());

                SolrInputDocument doc = new SolrInputDocument();
                for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) {
                    if (entry.getKey().startsWith(SolrConstants.FIELD)) {
                        String fieldName = entry.getKey().substring(SolrConstants.FIELD.length());
                        doc.setField(fieldName, entry.getValue());
                    }
                }
                updateRequest.add(doc);
                updateRequest.process(solrServer);

            } else if (body instanceof String) {

                String bodyAsString = (String) body;
View Full Code Here

        long fullStartTime = System.currentTimeMillis();

        // Open a socket to ingest, and to the response stream to get the post result
        try
        {
          ContentStreamUpdateRequest contentStreamUpdateRequest = new ContentStreamUpdateRequest(postUpdateAction);
         
          ModifiableSolrParams out = new ModifiableSolrParams();
         
          // Write the id field
          writeField(out,LITERAL+idAttributeName,documentURI);
          // Write the rest of the attributes
          if (modifiedDateAttributeName != null)
          {
            Date date = document.getModifiedDate();
            if (date != null)
              // Write value
              writeField(out,LITERAL+modifiedDateAttributeName,DateParser.formatISO8601Date(date));
          }
          if (createdDateAttributeName != null)
          {
            Date date = document.getCreatedDate();
            if (date != null)
              // Write value
              writeField(out,LITERAL+createdDateAttributeName,DateParser.formatISO8601Date(date));
          }
          if (indexedDateAttributeName != null)
          {
            Date date = document.getIndexingDate();
            if (date != null)
              // Write value
              writeField(out,LITERAL+indexedDateAttributeName,DateParser.formatISO8601Date(date));
          }
          if (fileNameAttributeName != null)
          {
            String fileName = document.getFileName();
            if (fileName != null)
              writeField(out,LITERAL+fileNameAttributeName,fileName);
          }
          if (mimeTypeAttributeName != null)
          {
            String mimeType = document.getMimeType();
            if (mimeType != null)
              writeField(out,LITERAL+mimeTypeAttributeName,mimeType);
          }
         
          // Write the access token information
          writeACLs(out,"share",shareAcls,shareDenyAcls);
          writeACLs(out,"document",acls,denyAcls);

          // Write the arguments
          for (String name : arguments.keySet())
          {
            List<String> values = arguments.get(name);
            writeField(out,name,values);
          }

          // Write the metadata, each in a field by itself
          Iterator<String> iter = document.getFields();
          while (iter.hasNext())
          {
            String fieldName = iter.next();
            List<String> mapping = sourceTargets.get(fieldName);
            if(mapping != null) {
              for(String newFieldName : mapping) {
                if(newFieldName != null && !newFieldName.isEmpty()) {
                  if (newFieldName.toLowerCase(Locale.ROOT).equals(idAttributeName.toLowerCase(Locale.ROOT))) {
                    newFieldName = ID_METADATA;
                  }
                  String[] values = document.getFieldAsStrings(fieldName);
                  writeField(out,LITERAL+newFieldName,values);
                }
              }
            } else {
              String newFieldName = fieldName;
              if (!newFieldName.isEmpty()) {
                if (newFieldName.toLowerCase(Locale.ROOT).equals(idAttributeName.toLowerCase(Locale.ROOT))) {
                  newFieldName = ID_METADATA;
                }
                String[] values = document.getFieldAsStrings(fieldName);
                writeField(out,LITERAL+newFieldName,values);
              }
            }
          }
            
          // These are unnecessary now in the case of non-solrcloud setups, because we overrode the SolrJ posting method to use multipart.
          //writeField(out,LITERAL+"stream_size",String.valueOf(length));
          //writeField(out,LITERAL+"stream_name",document.getFileName());
         
          // General hint for Tika
          if (document.getFileName() != null)
            writeField(out,"resource.name",document.getFileName());
         
          // Write the commitWithin parameter
          if (commitWithin != null)
            writeField(out,COMMITWITHIN_METADATA,commitWithin);

          contentStreamUpdateRequest.setParams(out);
         
          contentStreamUpdateRequest.addContentStream(new RepositoryDocumentStream(is,length,contentType,contentName));

          // Fire off the request.
          // Note: I need to know whether the document has been permanently rejected or not, but we currently have
          // no means to determine that.  Analysis of SolrServerExceptions that have been thrown is likely needed.
          try
          {
            readFromDocumentStreamYet = true;
            UpdateResponse response = contentStreamUpdateRequest.process(solrServer);
           
            // Successful completion
            activityStart = new Long(fullStartTime);
            activityBytes = new Long(length);
            activityCode = "OK";
View Full Code Here

        long fullStartTime = System.currentTimeMillis();

        // Open a socket to ingest, and to the response stream to get the post result
        try
        {
          ContentStreamUpdateRequest contentStreamUpdateRequest = new ContentStreamUpdateRequest(postUpdateAction);
         
          ModifiableSolrParams out = new ModifiableSolrParams();
         
          // Write the id field
          writeField(out,LITERAL+idAttributeName,documentURI);
          // Write the rest of the attributes
          if (modifiedDateAttributeName != null)
          {
            Date date = document.getModifiedDate();
            if (date != null)
              // Write value
              writeField(out,LITERAL+modifiedDateAttributeName,DateParser.formatISO8601Date(date));
          }
          if (createdDateAttributeName != null)
          {
            Date date = document.getCreatedDate();
            if (date != null)
              // Write value
              writeField(out,LITERAL+createdDateAttributeName,DateParser.formatISO8601Date(date));
          }
          if (indexedDateAttributeName != null)
          {
            Date date = document.getIndexingDate();
            if (date != null)
              // Write value
              writeField(out,LITERAL+indexedDateAttributeName,DateParser.formatISO8601Date(date));
          }
          if (fileNameAttributeName != null)
          {
            String fileName = document.getFileName();
            if (fileName != null)
              writeField(out,LITERAL+fileNameAttributeName,fileName);
          }
          if (mimeTypeAttributeName != null)
          {
            String mimeType = document.getMimeType();
            if (mimeType != null)
              writeField(out,LITERAL+mimeTypeAttributeName,mimeType);
          }
         
          // Write the access token information
          writeACLs(out,"share",shareAcls,shareDenyAcls);
          writeACLs(out,"document",acls,denyAcls);

          // Write the arguments
          for (String name : arguments.keySet())
          {
            List<String> values = arguments.get(name);
            writeField(out,name,values);
          }

          // Write the metadata, each in a field by itself
           buildSolrParamsFromMetadata(out);
            
          // These are unnecessary now in the case of non-solrcloud setups, because we overrode the SolrJ posting method to use multipart.
          //writeField(out,LITERAL+"stream_size",String.valueOf(length));
          //writeField(out,LITERAL+"stream_name",document.getFileName());
         
          // General hint for Tika
          if (document.getFileName() != null)
            writeField(out,"resource.name",document.getFileName());
         
          // Write the commitWithin parameter
          if (commitWithin != null)
            writeField(out,COMMITWITHIN_METADATA,commitWithin);

          contentStreamUpdateRequest.setParams(out);
         
          contentStreamUpdateRequest.addContentStream(new RepositoryDocumentStream(is,length,contentType,contentName));

          // Fire off the request.
          // Note: I need to know whether the document has been permanently rejected or not, but we currently have
          // no means to determine that.  Analysis of SolrServerExceptions that have been thrown is likely needed.
          try
          {
            readFromDocumentStreamYet = true;
            UpdateResponse response = contentStreamUpdateRequest.process(solrServer);
           
            // Successful completion
            activityStart = new Long(fullStartTime);
            activityBytes = new Long(length);
            activityCode = "OK";
View Full Code Here

            body = ((WrappedFile)body).getFile();
        }

        if (body instanceof File) {

            ContentStreamUpdateRequest updateRequest = new ContentStreamUpdateRequest(getRequestHandler());
            updateRequest.addFile((File) body);

            for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) {
                if (entry.getKey().startsWith(SolrConstants.PARAM)) {
                    String paramName = entry.getKey().substring(SolrConstants.PARAM.length());
                    updateRequest.setParam(paramName, entry.getValue().toString());
                }
            }

            if (isStreaming) {
                updateRequest.process(streamingSolrServer);
            } else {
                updateRequest.process(solrServer);
            }

        } else if (body instanceof SolrInputDocument) {

            UpdateRequest updateRequest = new UpdateRequest(getRequestHandler());
            updateRequest.add((SolrInputDocument) body);

            if (isStreaming) {
                updateRequest.process(streamingSolrServer);
            } else {
                updateRequest.process(solrServer);
            }

        } else {

            boolean hasSolrHeaders = false;
            Map<String, Object> headers = exchange.getIn().getHeaders();
            for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) {
                if (entry.getKey().startsWith(SolrConstants.FIELD)) {
                    hasSolrHeaders = true;
                    break;
                }
            }

            if (hasSolrHeaders) {

                UpdateRequest updateRequest = new UpdateRequest(getRequestHandler());

                SolrInputDocument doc = new SolrInputDocument();
                for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) {
                    if (entry.getKey().startsWith(SolrConstants.FIELD)) {
                        String fieldName = entry.getKey().substring(SolrConstants.FIELD.length());
                        doc.setField(fieldName, entry.getValue());
                    }
                }
                updateRequest.add(doc);

                if (isStreaming) {
                    updateRequest.process(streamingSolrServer);
                } else {
                    updateRequest.process(solrServer);
                }

            } else if (body instanceof String) {

                String bodyAsString = (String) body;
View Full Code Here

        long fullStartTime = System.currentTimeMillis();

        // Open a socket to ingest, and to the response stream to get the post result
        try
        {
          ContentStreamUpdateRequest contentStreamUpdateRequest = new ContentStreamUpdateRequest(postUpdateAction);
         
          ModifiableSolrParams out = new ModifiableSolrParams();
         
          // Write the id field
          writeField(out,LITERAL+idAttributeName,documentURI);
          // Write the rest of the attributes
          if (modifiedDateAttributeName != null)
          {
            Date date = document.getModifiedDate();
            if (date != null)
              // Write value
              writeField(out,LITERAL+modifiedDateAttributeName,DateParser.formatISO8601Date(date));
          }
          if (createdDateAttributeName != null)
          {
            Date date = document.getCreatedDate();
            if (date != null)
              // Write value
              writeField(out,LITERAL+createdDateAttributeName,DateParser.formatISO8601Date(date));
          }
          if (indexedDateAttributeName != null)
          {
            Date date = document.getIndexingDate();
            if (date != null)
              // Write value
              writeField(out,LITERAL+indexedDateAttributeName,DateParser.formatISO8601Date(date));
          }
          if (fileNameAttributeName != null)
          {
            String fileName = document.getFileName();
            if (fileName != null)
              writeField(out,LITERAL+fileNameAttributeName,fileName);
          }
          if (mimeTypeAttributeName != null)
          {
            String mimeType = document.getMimeType();
            if (mimeType != null)
              writeField(out,LITERAL+mimeTypeAttributeName,mimeType);
          }
         
          // Write the access token information
          writeACLs(out,"share",shareAcls,shareDenyAcls);
          writeACLs(out,"document",acls,denyAcls);

          // Write the arguments
          for (String name : arguments.keySet())
          {
            List<String> values = arguments.get(name);
            writeField(out,name,values);
          }

          // Write the metadata, each in a field by itself
           buildSolrParamsFromMetadata(out);
            
          // These are unnecessary now in the case of non-solrcloud setups, because we overrode the SolrJ posting method to use multipart.
          //writeField(out,LITERAL+"stream_size",String.valueOf(length));
          //writeField(out,LITERAL+"stream_name",document.getFileName());
         
          // General hint for Tika
          if (document.getFileName() != null)
            writeField(out,"resource.name",document.getFileName());
         
          // Write the commitWithin parameter
          if (commitWithin != null)
            writeField(out,COMMITWITHIN_METADATA,commitWithin);

          contentStreamUpdateRequest.setParams(out);
         
          contentStreamUpdateRequest.addContentStream(new RepositoryDocumentStream(is,length,contentType,contentName));

          // Fire off the request.
          // Note: I need to know whether the document has been permanently rejected or not, but we currently have
          // no means to determine that.  Analysis of SolrServerExceptions that have been thrown is likely needed.
          try
          {
            readFromDocumentStreamYet = true;
            UpdateResponse response = contentStreamUpdateRequest.process(solrServer);
           
            // Successful completion
            activityStart = new Long(fullStartTime);
            activityBytes = new Long(length);
            activityCode = "OK";
View Full Code Here

    server.deleteByQuery( "*:*" );// delete everything!
    server.commit();
    QueryResponse rsp = server.query( new SolrQuery( "*:*") );
    Assert.assertEquals( 0, rsp.getResults().getNumFound() );

    ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update/csv");
    up.addFile(getFile("books.csv"));
    up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
    NamedList<Object> result = server.request(up);
    assertNotNull("Couldn't upload books.csv", result);
    rsp = server.query( new SolrQuery( "*:*") );
    Assert.assertEquals( 10, rsp.getResults().getNumFound() );
  }
View Full Code Here

    server.deleteByQuery( "*:*" );// delete everything!
    server.commit();
    QueryResponse rsp = server.query( new SolrQuery( "*:*") );
    Assert.assertEquals( 0, rsp.getResults().getNumFound() );

    ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update/csv");
    up.addFile(new File("books.csv"));
    up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
    NamedList<Object> result = server.request(up);
    assertNotNull("Couldn't upload books.csv", result);
    rsp = server.query( new SolrQuery( "*:*") );
    Assert.assertEquals( 10, rsp.getResults().getNumFound() );

    server.deleteByQuery( "*:*" );// delete everything!
    server.commit();
    rsp = server.query( new SolrQuery( "*:*") );
    Assert.assertEquals( 0, rsp.getResults().getNumFound() );

    up = new ContentStreamUpdateRequest("/update/extract");
    up.addFile(new File("mailing_lists.pdf"));
    up.setParam("literal.id", "mailing_lists.pdf");
    up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
    result = server.request(up);
    assertNotNull("Couldn't upload mailing_lists.pdf", result);
    rsp = server.query( new SolrQuery( "*:*") );
    Assert.assertEquals( 1, rsp.getResults().getNumFound() );

View Full Code Here

        long fullStartTime = System.currentTimeMillis();

        // Open a socket to ingest, and to the response stream to get the post result
        try
        {
          ContentStreamUpdateRequest contentStreamUpdateRequest = new ContentStreamUpdateRequest(postUpdateAction);
         
          ModifiableSolrParams out = new ModifiableSolrParams();
         
          // Write the id field
          writeField(out,LITERAL+idAttributeName,documentURI);

          // Write the access token information
          writeACLs(out,"share",shareAcls,shareDenyAcls);
          writeACLs(out,"document",acls,denyAcls);

          // Write the arguments
          for (String name : arguments.keySet())
          {
            List<String> values = arguments.get(name);
            writeField(out,name,values);
          }

          // Write the metadata, each in a field by itself
          Iterator<String> iter = document.getFields();
          while (iter.hasNext())
          {
            String fieldName = iter.next();
            String newFieldName = sourceTargets.get(fieldName);
            if (newFieldName == null)
              newFieldName = fieldName;
            if (newFieldName.length() > 0)
            {
              if (newFieldName.toLowerCase(Locale.ROOT).equals(idAttributeName.toLowerCase(Locale.ROOT)))
                newFieldName = ID_METADATA;
              String[] values = document.getFieldAsStrings(fieldName);
              writeField(out,LITERAL+newFieldName,values);
            }
          }
              
          writeField(out,LITERAL+"stream_size",String.valueOf(length));
          writeField(out,LITERAL+"stream_name",document.getFileName());
         
          // Write the commitWithin parameter
          if (commitWithin != null)
            writeField(out,COMMITWITHIN_METADATA,commitWithin);

          contentStreamUpdateRequest.setParams(out);
         
          contentStreamUpdateRequest.addContentStream(new RepositoryDocumentStream(is,length,contentType,contentName));

          // Fire off the request.
          // Note: I need to know whether the document has been permanently rejected or not, but we currently have
          // no means to determine that.  Analysis of SolrServerExceptions that have been thrown is likely needed.
          try
          {
            readFromDocumentStreamYet = true;
            UpdateResponse response = contentStreamUpdateRequest.process(solrServer);
           
            // Successful completion
            activityStart = new Long(fullStartTime);
            activityBytes = new Long(length);
            activityCode = "OK";
View Full Code Here

        Object body = exchange.getIn().getBody();

        if (body instanceof File) {

            ContentStreamUpdateRequest updateRequest = new ContentStreamUpdateRequest(getRequestHandler());
            updateRequest.addFile((File) body);

            for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) {
                if (entry.getKey().startsWith(SolrConstants.PARAM)) {
                    String paramName = entry.getKey().substring(SolrConstants.PARAM.length());
                    updateRequest.setParam(paramName, entry.getValue().toString());
                }
            }

            if (isStreaming) {
                updateRequest.process(streamingSolrServer);
            } else {
                updateRequest.process(solrServer);
            }

        } else if (body instanceof SolrInputDocument) {

            UpdateRequest updateRequest = new UpdateRequest(getRequestHandler());
            updateRequest.add((SolrInputDocument) body);

            if (isStreaming) {
                updateRequest.process(streamingSolrServer);
            } else {
                updateRequest.process(solrServer);
            }

        } else {

            boolean hasSolrHeaders = false;
            Map<String, Object> headers = exchange.getIn().getHeaders();
            for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) {
                if (entry.getKey().startsWith(SolrConstants.FIELD)) {
                    hasSolrHeaders = true;
                    break;
                }
            }

            if (hasSolrHeaders) {

                UpdateRequest updateRequest = new UpdateRequest(getRequestHandler());

                SolrInputDocument doc = new SolrInputDocument();
                for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) {
                    if (entry.getKey().startsWith(SolrConstants.FIELD)) {
                        String fieldName = entry.getKey().substring(SolrConstants.FIELD.length());
                        doc.setField(fieldName, entry.getValue());
                    }
                }
                updateRequest.add(doc);

                if (isStreaming) {
                    updateRequest.process(streamingSolrServer);
                } else {
                    updateRequest.process(solrServer);
                }

            } else if (body instanceof String) {

                String bodyAsString = (String) body;
View Full Code Here

TOP

Related Classes of org.apache.solr.client.solrj.request.ContentStreamUpdateRequest

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.