当前位置: 首页>>代码示例>>Java>>正文


Java ContentStream.getReader方法代码示例

本文整理汇总了Java中org.apache.solr.common.util.ContentStream.getReader方法的典型用法代码示例。如果您正苦于以下问题:Java ContentStream.getReader方法的具体用法?Java ContentStream.getReader怎么用?Java ContentStream.getReader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.solr.common.util.ContentStream的用法示例。


在下文中一共展示了ContentStream.getReader方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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());
}
 
开发者ID:NLP4L,项目名称:solr,代码行数:26,代码来源:FeaturesRequestHandler.java

示例2: 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 );
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:RawResponseWriter.java

示例3: 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);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:JsonLoader.java

示例4: handleRequestBody

import org.apache.solr.common.util.ContentStream; //导入方法依赖的package包/类
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException 
{
  // Show params
  rsp.add( "params", req.getParams().toNamedList() );
      
  // Write the streams...
  if( req.getContentStreams() != null ) {
    ArrayList<NamedList<Object>> streams = new ArrayList<>();
    // Cycle through each stream
    for( ContentStream content : req.getContentStreams() ) {
      NamedList<Object> stream = new SimpleOrderedMap<>();
      stream.add( "name", content.getName() );
      stream.add( "sourceInfo", content.getSourceInfo() );
      stream.add( "size", content.getSize() );
      stream.add( "contentType", content.getContentType() );
      Reader reader = content.getReader();
      try {
        stream.add( "stream", IOUtils.toString(reader) );
      } finally {
        reader.close();
      }
      streams.add( stream );
    }
    rsp.add( "streams", streams );
  }

  rsp.add("context", req.getContext());
}
 
开发者ID:europeana,项目名称:search,代码行数:30,代码来源:DumpRequestHandler.java

示例5: readCommandFromIncomingStream

import org.apache.solr.common.util.ContentStream; //导入方法依赖的package包/类
/**
 * Reads the incoming stream in order to build the wrapped operation.
 * 
 * @param stream the incoming content stream.
 * @return the incoming stream in order to build the wrapped operation.
 * @throws IOException in case of I/O failure.
 */
public static String readCommandFromIncomingStream(final ContentStream stream) throws IOException {
	final BufferedReader reader = new BufferedReader(stream.getReader());
	final StringBuilder builder = new StringBuilder();
	String actLine = null;
	try {
		while ( (actLine = reader.readLine()) != null) {
			builder.append(actLine).append(" ");
		}
		return builder.toString();
	} finally {
		IOUtils.closeQuietly(reader);
	}
}
 
开发者ID:spaziocodice,项目名称:SolRDF,代码行数:21,代码来源:F.java

示例6: handleRequestBody

import org.apache.solr.common.util.ContentStream; //导入方法依赖的package包/类
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException 
{
  // Show params
  rsp.add( "params", req.getParams().toNamedList() );
      
  // Write the streams...
  if( req.getContentStreams() != null ) {
    ArrayList<NamedList<Object>> streams = new ArrayList<NamedList<Object>>();
    // Cycle through each stream
    for( ContentStream content : req.getContentStreams() ) {
      NamedList<Object> stream = new SimpleOrderedMap<Object>();
      stream.add( "name", content.getName() );
      stream.add( "sourceInfo", content.getSourceInfo() );
      stream.add( "size", content.getSize() );
      stream.add( "contentType", content.getContentType() );
      Reader reader = content.getReader();
      try {
        stream.add( "stream", IOUtils.toString(reader) );
      } finally {
        reader.close();
      }
      streams.add( stream );
    }
    rsp.add( "streams", streams );
  }

  rsp.add("context", req.getContext());
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:30,代码来源:DumpRequestHandler.java

示例7: load

import org.apache.solr.common.util.ContentStream; //导入方法依赖的package包/类
@Override
public void load(final SolrQueryRequest req, final SolrQueryResponse rsp,
		final ContentStream stream, final UpdateRequestProcessor processor)
		throws Exception {
	BufferedReader reader = null;

	try {
		reader = new BufferedReader(stream.getReader());
		String actLine = null;
		while ((actLine = reader.readLine()) != null) {
			// 1. Sanity check: line must have a fixed length, otherwise
			// skip
			if (actLine.length() != 107) {
				continue;
			}

			// 2. parse and create the document
			final SolrInputDocument document = new SolrInputDocument();
			document.setField("id", actLine.substring(0, 8));
			document.setField("isbn", actLine.substring(8,21).trim());
			document.setField("title", actLine.substring(21, 65).trim());
			document.setField("author", actLine.substring(65).trim());				
			
			AddUpdateCommand command = getAddCommand(req);
			command.solrDoc = document;
			
			processor.processAdd(command);
		}
	} catch (Exception e) {
		// TODO: handle exception
	} finally {
		if (reader != null) {
			try {
				reader.close();
			} catch (Exception ignore) {
				// TODO: handle exception
			}
		}
	}
}
 
开发者ID:agazzarini,项目名称:apache-solr-essentials,代码行数:41,代码来源:FlatDataLoader.java

示例8: resolveAnalysisRequest

import org.apache.solr.common.util.ContentStream; //导入方法依赖的package包/类
/**
 * Resolves the AnalysisRequest based on the parameters in the given SolrParams.
 *
 * @param req the request
 *
 * @return AnalysisRequest containing all the information about what needs to be analyzed, and using what
 *         fields/types
 */
FieldAnalysisRequest resolveAnalysisRequest(SolrQueryRequest req) {
  SolrParams solrParams = req.getParams();
  FieldAnalysisRequest analysisRequest = new FieldAnalysisRequest();

  boolean useDefaultSearchField = true;
  if (solrParams.get(AnalysisParams.FIELD_TYPE) != null) {
    analysisRequest.setFieldTypes(Arrays.asList(solrParams.get(AnalysisParams.FIELD_TYPE).split(",")));
    useDefaultSearchField = false;
  }
  if (solrParams.get(AnalysisParams.FIELD_NAME) != null) {
    analysisRequest.setFieldNames(Arrays.asList(solrParams.get(AnalysisParams.FIELD_NAME).split(",")));
    useDefaultSearchField = false;
  }
  if (useDefaultSearchField)  {
    analysisRequest.addFieldName(req.getSchema().getDefaultSearchFieldName());
  }
  analysisRequest.setQuery(solrParams.get(AnalysisParams.QUERY, solrParams.get(CommonParams.Q)));

  String value = solrParams.get(AnalysisParams.FIELD_VALUE);
  if (analysisRequest.getQuery() == null && value == null)  {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
        "One of analysis.value or q or analysis.query parameters must be specified");
  }

  Iterable<ContentStream> streams = req.getContentStreams();
  if (streams != null) {
    // NOTE: Only the first content stream is currently processed
    for (ContentStream stream : streams) {
      Reader reader = null;
      try {
        reader = stream.getReader();
        value = IOUtils.toString(reader);
      } catch (IOException e) {
        // do nothing, leave value set to the request parameter
      }
      finally {
        IOUtils.closeQuietly(reader);
      }
      break;
    }
  }

  analysisRequest.setFieldValue(value);
  analysisRequest.setShowMatch(solrParams.getBool(AnalysisParams.SHOW_MATCH, false));
  return analysisRequest;
}
 
开发者ID:europeana,项目名称:search,代码行数:55,代码来源:FieldAnalysisRequestHandler.java

示例9: load

import org.apache.solr.common.util.ContentStream; //导入方法依赖的package包/类
/** load the CSV input */
@Override
public void load(SolrQueryRequest req, SolrQueryResponse rsp, ContentStream stream, UpdateRequestProcessor processor) throws IOException {
  errHeader = "CSVLoader: input=" + stream.getSourceInfo();
  Reader reader = null;
  try {
    reader = stream.getReader();
    if (skipLines>0) {
      if (!(reader instanceof BufferedReader)) {
        reader = new BufferedReader(reader);
      }
      BufferedReader r = (BufferedReader)reader;
      for (int i=0; i<skipLines; i++) {
        r.readLine();
      }
    }

    CSVParser parser = new CSVParser(reader, strategy);

    // parse the fieldnames from the header of the file
    if (fieldnames==null) {
      fieldnames = parser.getLine();
      if (fieldnames==null) {
        throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Expected fieldnames in CSV input");
      }
      prepareFields();
    }

    // read the rest of the CSV file
    for(;;) {
      int line = parser.getLineNumber();  // for error reporting in MT mode
      String[] vals = null;
      try {
        vals = parser.getLine();
      } catch (IOException e) {
        //Catch the exception and rethrow it with more line information
       input_err("can't read line: " + line, null, line, e);
      }
      if (vals==null) break;

      if (vals.length != fieldnames.length) {
        input_err("expected "+fieldnames.length+" values but got "+vals.length, vals, line);
      }

      addDoc(line,vals);
    }
  } finally{
    if (reader != null) {
      IOUtils.closeQuietly(reader);
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:53,代码来源:CSVLoaderBase.java

示例10: resolveAnalysisRequest

import org.apache.solr.common.util.ContentStream; //导入方法依赖的package包/类
/**
 * Resolves the AnalysisRequest based on the parameters in the given SolrParams.
 *
 * @param req the request
 *
 * @return AnalysisRequest containing all the information about what needs to be analyzed, and using what
 *         fields/types
 */
FieldAnalysisRequest resolveAnalysisRequest(SolrQueryRequest req) {
  SolrParams solrParams = req.getParams();
  FieldAnalysisRequest analysisRequest = new FieldAnalysisRequest();

  boolean useDefaultSearchField = true;
  if (solrParams.get(AnalysisParams.FIELD_TYPE) != null) {
    analysisRequest.setFieldTypes(Arrays.asList(solrParams.get(AnalysisParams.FIELD_TYPE).split(",")));
    useDefaultSearchField = false;
  }
  if (solrParams.get(AnalysisParams.FIELD_NAME) != null) {
    analysisRequest.setFieldNames(Arrays.asList(solrParams.get(AnalysisParams.FIELD_NAME).split(",")));
    useDefaultSearchField = false;
  }
  if (useDefaultSearchField)  {
    analysisRequest.addFieldName(req.getSchema().getDefaultSearchFieldName());
  }
  analysisRequest.setQuery(solrParams.get(AnalysisParams.QUERY, solrParams.get(CommonParams.Q)));

  String value = solrParams.get(AnalysisParams.FIELD_VALUE);

  Iterable<ContentStream> streams = req.getContentStreams();
  if (streams != null) {
    // NOTE: Only the first content stream is currently processed
    for (ContentStream stream : streams) {
      Reader reader = null;
      try {
        reader = stream.getReader();
        value = IOUtils.toString(reader);
      } catch (IOException e) {
        // do nothing, leave value set to the request parameter
      }
      finally {
        IOUtils.closeQuietly(reader);
      }
      break;
    }
  }

  analysisRequest.setFieldValue(value);
  analysisRequest.setShowMatch(solrParams.getBool(AnalysisParams.SHOW_MATCH, false));
  return analysisRequest;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:51,代码来源:FieldAnalysisRequestHandler.java

示例11: load

import org.apache.solr.common.util.ContentStream; //导入方法依赖的package包/类
/** load the CSV input */
@Override
public void load(SolrQueryRequest req, SolrQueryResponse rsp, ContentStream stream, UpdateRequestProcessor processor) throws IOException {
  errHeader = "CSVLoader: input=" + stream.getSourceInfo();
  Reader reader = null;
  try {
    reader = stream.getReader();
    if (skipLines>0) {
      if (!(reader instanceof BufferedReader)) {
        reader = new BufferedReader(reader);
      }
      BufferedReader r = (BufferedReader)reader;
      for (int i=0; i<skipLines; i++) {
        r.readLine();
      }
    }

    CSVParser parser = new CSVParser(reader, strategy);

    // parse the fieldnames from the header of the file
    if (fieldnames==null) {
      fieldnames = parser.getLine();
      if (fieldnames==null) {
        throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Expected fieldnames in CSV input");
      }
      prepareFields();
    }

    // read the rest of the CSV file
    for(;;) {
      int line = parser.getLineNumber();  // for error reporting in MT mode
      String[] vals = null;
      try {
        vals = parser.getLine();
      } catch (IOException e) {
        //Catch the exception and rethrow it with more line information
       input_err("can't read line: " + line, null, line, e);
      }
      if (vals==null) break;

      if (vals.length != fields.length) {
        input_err("expected "+fields.length+" values but got "+vals.length, vals, line);
      }

      addDoc(line,vals);
    }
  } finally{
    if (reader != null) {
      IOUtils.closeQuietly(reader);
    }
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:53,代码来源:CSVLoaderBase.java


注:本文中的org.apache.solr.common.util.ContentStream.getReader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。