本文整理汇总了Java中org.apache.solr.common.util.ContentStream类的典型用法代码示例。如果您正苦于以下问题:Java ContentStream类的具体用法?Java ContentStream怎么用?Java ContentStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContentStream类属于org.apache.solr.common.util包,在下文中一共展示了ContentStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setProperties
import org.apache.solr.common.util.ContentStream; //导入依赖的package包/类
/**
* Set the given properties and values using the config API.
* @param props properties to set.
* @throws IOException network error.
* @throws SolrServerException solr error.
*/
public void setProperties(Map<String, String> props) throws SolrServerException, IOException
{
// Solrj does not support the config API yet.
StringBuilder command = new StringBuilder("{\"set-property\": {");
for (Map.Entry<String, String> entry: props.entrySet())
{
command.append('"').append(entry.getKey()).append('"').append(':');
command.append(entry.getValue()).append(',');
}
command.setLength(command.length()-1); // remove last comma
command.append("}}");
GenericSolrRequest rq = new GenericSolrRequest(SolrRequest.METHOD.POST, "/config", null);
ContentStream content = new ContentStreamBase.StringStream(command.toString());
rq.setContentStreams(Collections.singleton(content));
rq.process(solrClient);
}
示例2: unsetProperties
import org.apache.solr.common.util.ContentStream; //导入依赖的package包/类
/**
* Unset the given properties that have been previously set with {@link #setProperties(Map)}.
* @param props properties to unset.
* @throws IOException network error.
* @throws SolrServerException solr error.
*/
public void unsetProperties(Set<String> props) throws SolrServerException, IOException
{
// Solrj does not support the config API yet.
StringBuilder command = new StringBuilder("{\"unset-property\": [");
for (String prop: props)
{
command.append('"').append(prop).append('"').append(',');
}
command.setLength(command.length()-1); // remove last comma
command.append("]}");
GenericSolrRequest rq = new GenericSolrRequest(SolrRequest.METHOD.POST, "/config", null);
ContentStream content = new ContentStreamBase.StringStream(command.toString());
rq.setContentStreams(Collections.singleton(content));
rq.process(solrClient);
}
示例3: handleExtract
import org.apache.solr.common.util.ContentStream; //导入依赖的package包/类
public void handleExtract(SolrQueryRequest req, Iterable<ContentStream> ite, SimpleOrderedMap<Object> results)
throws Exception {
FeaturesConfigReader fcReader = new FeaturesConfigReader(req.getCore().getResourceLoader(),
req.getParams().required().get("conf"));
FeaturesConfigReader.FeatureDesc[] featureDescs = fcReader.getFeatureDescs();
List<FieldFeatureExtractorFactory> featuresSpec = new ArrayList<FieldFeatureExtractorFactory>();
for(FeaturesConfigReader.FeatureDesc featureDesc: featureDescs){
FieldFeatureExtractorFactory dfeFactory = FeaturesConfigReader.loadFactory(featureDesc);
featuresSpec.add(dfeFactory);
}
StringBuilder queries = new StringBuilder();
for(ContentStream cs: ite){
Reader reader = cs.getReader();
try{
queries.append(IOUtils.toString(reader));
}
finally{
IOUtils.closeQuietly(reader);
}
}
long procId = startExtractor(req, featuresSpec, queries.toString());
FeaturesExtractorManager manager = getManager(procId);
results.add("procId", procId);
results.add("progress", manager.getProgress());
}
示例4: getPostString
import org.apache.solr.common.util.ContentStream; //导入依赖的package包/类
private String getPostString(SolrQueryRequest request) throws IOException {
Reader inputReader = null;
Iterable<ContentStream> streams = request.getContentStreams();
if (streams != null) {
Iterator<ContentStream> iter = streams.iterator();
if (iter.hasNext()) {
inputReader = iter.next().getReader();
}
if (iter.hasNext()) {
throwWithClassName(" does not support multiple ContentStreams");
}
}
if (inputReader == null) {
throwWithClassName(" requires POST data");
}
String inputString;
inputString = CharStreams.toString(inputReader);
inputReader.close();
if(inputString.equals("") || inputString == null) {
throwWithClassName(" requires POST data");
}
return inputString;
}
示例5: getContentStreams
import org.apache.solr.common.util.ContentStream; //导入依赖的package包/类
@Override
public Collection<ContentStream> getContentStreams(SolrRequest req) throws IOException {
if (req instanceof UpdateRequest) {
UpdateRequest updateRequest = (UpdateRequest) req;
if (isNull(updateRequest.getDocuments()) &&
isNull(updateRequest.getDeleteByIdMap()) &&
isNull(updateRequest.getDeleteQuery())
&& (updateRequest.getDocIterator() == null) ) {
return null;
}
List<ContentStream> l = new ArrayList<>();
l.add(new LazyContentStream(updateRequest));
return l;
} else {
return super.getContentStreams(req);
}
}
示例6: parse
import org.apache.solr.common.util.ContentStream; //导入依赖的package包/类
public SolrQueryRequest parse( SolrCore core, String path, HttpServletRequest req ) throws Exception
{
SolrRequestParser parser = standard;
// TODO -- in the future, we could pick a different parser based on the request
// Pick the parser from the request...
ArrayList<ContentStream> streams = new ArrayList<>(1);
SolrParams params = parser.parseParamsAndFillStreams( req, streams );
SolrQueryRequest sreq = buildRequestFrom( core, params, streams );
// Handlers and login will want to know the path. If it contains a ':'
// the handler could use it for RESTful URLs
sreq.getContext().put( "path", path );
if(addHttpRequestToContext) {
sreq.getContext().put("httpRequest", req);
}
return sreq;
}
示例7: parseParamsAndFillStreams
import org.apache.solr.common.util.ContentStream; //导入依赖的package包/类
@Override
public SolrParams parseParamsAndFillStreams(
final HttpServletRequest req, ArrayList<ContentStream> streams ) throws Exception
{
String method = req.getMethod().toUpperCase(Locale.ROOT);
if ("GET".equals(method) || "HEAD".equals(method)
|| (("PUT".equals(method) || "DELETE".equals(method))
&& (req.getRequestURI().contains("/schema")
|| req.getRequestURI().contains("/config")))) {
return parseQueryString(req.getQueryString());
}
if ("POST".equals( method ) ) {
if (formdata.isFormData(req)) {
return formdata.parseParamsAndFillStreams(req, streams);
}
if (ServletFileUpload.isMultipartContent(req)) {
return multipart.parseParamsAndFillStreams(req, streams);
}
if (req.getContentType() != null) {
return raw.parseParamsAndFillStreams(req, streams);
}
throw new SolrException(ErrorCode.UNSUPPORTED_MEDIA_TYPE, "Must specify a Content-Type header with POST requests");
}
throw new SolrException(ErrorCode.BAD_REQUEST, "Unsupported method: " + method + " for request " + req);
}
示例8: write
import org.apache.solr.common.util.ContentStream; //导入依赖的package包/类
@Override
public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse response) throws IOException
{
Object obj = response.getValues().get( CONTENT );
if( obj != null && (obj instanceof ContentStream ) ) {
// copy the contents to the writer...
ContentStream content = (ContentStream)obj;
Reader reader = content.getReader();
try {
IOUtils.copy( reader, writer );
} finally {
reader.close();
}
}
else {
getBaseWriter( request ).write( writer, request, response );
}
}
示例9: extractSingleContentStream
import org.apache.solr.common.util.ContentStream; //导入依赖的package包/类
/**
* Extracts the only content stream from the request. {@link org.apache.solr.common.SolrException.ErrorCode#BAD_REQUEST}
* error is thrown if the request doesn't hold any content stream or holds more than one.
*
* @param req The solr request.
*
* @return The single content stream which holds the documents to be analyzed.
*/
private ContentStream extractSingleContentStream(SolrQueryRequest req) {
Iterable<ContentStream> streams = req.getContentStreams();
String exceptionMsg = "DocumentAnalysisRequestHandler expects a single content stream with documents to analyze";
if (streams == null) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, exceptionMsg);
}
Iterator<ContentStream> iter = streams.iterator();
if (!iter.hasNext()) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, exceptionMsg);
}
ContentStream stream = iter.next();
if (iter.hasNext()) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, exceptionMsg);
}
return stream;
}
示例10: load
import org.apache.solr.common.util.ContentStream; //导入依赖的package包/类
@Override
public void load(SolrQueryRequest req,
SolrQueryResponse rsp,
ContentStream stream,
UpdateRequestProcessor processor) throws Exception {
Reader reader = null;
try {
reader = stream.getReader();
if (log.isTraceEnabled()) {
String body = IOUtils.toString(reader);
log.trace("body", body);
reader = new StringReader(body);
}
parser = new JSONParser(reader);
this.processUpdate();
}
finally {
IOUtils.closeQuietly(reader);
}
}
示例11: load
import org.apache.solr.common.util.ContentStream; //导入依赖的package包/类
@Override
public void load(SolrQueryRequest req, SolrQueryResponse rsp,
ContentStream stream, UpdateRequestProcessor processor) throws Exception {
String type = req.getParams().get(UpdateParams.ASSUME_CONTENT_TYPE);
if(type == null) {
type = stream.getContentType();
}
if( type == null ) { // Normal requests will not get here.
throw new SolrException(ErrorCode.UNSUPPORTED_MEDIA_TYPE, "Missing ContentType");
}
int idx = type.indexOf(';');
if(idx>0) {
type = type.substring(0,idx);
}
ContentStreamLoader loader = loaders.get(type);
if(loader==null) {
throw new SolrException(ErrorCode.UNSUPPORTED_MEDIA_TYPE, "Unsupported ContentType: "
+type+ " Not in: "+loaders.keySet());
}
if(loader.getDefaultWT()!=null) {
setDefaultWT(req,loader);
}
loader.load(req, rsp, stream, processor);
}
示例12: testParameterIncompatibilityException1
import org.apache.solr.common.util.ContentStream; //导入依赖的package包/类
@Test
public void testParameterIncompatibilityException1() throws Exception
{
HttpServletRequest request = createMock(HttpServletRequest.class);
expect(request.getMethod()).andReturn("POST").anyTimes();
expect(request.getContentType()).andReturn("application/x-www-form-urlencoded").anyTimes();
expect(request.getContentLength()).andReturn(100).anyTimes();
expect(request.getQueryString()).andReturn(null).anyTimes();
// we emulate Jetty that returns empty stream when parameters were parsed before:
expect(request.getInputStream()).andReturn(new ServletInputStream() {
@Override public int read() { return -1; }
});
replay(request);
FormDataRequestParser formdata = new FormDataRequestParser( 2048 );
try {
formdata.parseParamsAndFillStreams(request, new ArrayList<ContentStream>());
fail("should throw SolrException");
} catch (SolrException solre) {
assertTrue(solre.getMessage().startsWith("Solr requires that request parameters"));
assertEquals(500, solre.code());
}
}
示例13: testParameterIncompatibilityException2
import org.apache.solr.common.util.ContentStream; //导入依赖的package包/类
@Test
public void testParameterIncompatibilityException2() throws Exception
{
HttpServletRequest request = createMock(HttpServletRequest.class);
expect(request.getMethod()).andReturn("POST").anyTimes();
expect(request.getContentType()).andReturn("application/x-www-form-urlencoded").anyTimes();
expect(request.getContentLength()).andReturn(100).anyTimes();
expect(request.getQueryString()).andReturn(null).anyTimes();
// we emulate Tomcat that throws IllegalStateException when parameters were parsed before:
expect(request.getInputStream()).andThrow(new IllegalStateException());
replay(request);
FormDataRequestParser formdata = new FormDataRequestParser( 2048 );
try {
formdata.parseParamsAndFillStreams(request, new ArrayList<ContentStream>());
fail("should throw SolrException");
} catch (SolrException solre) {
assertTrue(solre.getMessage().startsWith("Solr requires that request parameters"));
assertEquals(500, solre.code());
}
}
示例14: addDoc
import org.apache.solr.common.util.ContentStream; //导入依赖的package包/类
static void addDoc(String doc, String chain) throws Exception {
Map<String, String[]> params = new HashMap<>();
MultiMapSolrParams mmparams = new MultiMapSolrParams(params);
params.put(UpdateParams.UPDATE_CHAIN, new String[] { chain });
SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(),
(SolrParams) mmparams) {
};
UpdateRequestHandler handler = new UpdateRequestHandler();
handler.init(null);
ArrayList<ContentStream> streams = new ArrayList<>(2);
streams.add(new ContentStreamBase.StringStream(doc));
req.setContentStreams(streams);
handler.handleRequestBody(req, new SolrQueryResponse());
req.close();
}
示例15: addDoc
import org.apache.solr.common.util.ContentStream; //导入依赖的package包/类
private void addDoc(String doc) throws Exception {
Map<String, String[]> params = new HashMap<>();
MultiMapSolrParams mmparams = new MultiMapSolrParams(params);
params.put(UpdateParams.UPDATE_CHAIN, new String[] { "uniq-fields" });
SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(),
(SolrParams) mmparams) {
};
UpdateRequestHandler handler = new UpdateRequestHandler();
handler.init(null);
ArrayList<ContentStream> streams = new ArrayList<>(2);
streams.add(new ContentStreamBase.StringStream(doc));
req.setContentStreams(streams);
handler.handleRequestBody(req, new SolrQueryResponse());
req.close();
}