本文整理汇总了Java中org.apache.solr.common.util.ContentStreamBase.StringStream方法的典型用法代码示例。如果您正苦于以下问题:Java ContentStreamBase.StringStream方法的具体用法?Java ContentStreamBase.StringStream怎么用?Java ContentStreamBase.StringStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.common.util.ContentStreamBase
的用法示例。
在下文中一共展示了ContentStreamBase.StringStream方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setProperties
import org.apache.solr.common.util.ContentStreamBase; //导入方法依赖的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.ContentStreamBase; //导入方法依赖的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: toContentStream
import org.apache.solr.common.util.ContentStreamBase; //导入方法依赖的package包/类
public ContentStream toContentStream(String docId, Object docObj) throws Exception {
if (docObj instanceof String) {
// already a string, so just stream it out directly
ContentStreamBase.StringStream ss = new ContentStreamBase.StringStream((String)docObj);
ss.setContentType(JSON_CONTENT_TYPE);
return ss;
}
// pipe the bytes written by the ObjectMapper during JSON serialization to the InputStream
PipedInputContentStream contentStream = new PipedInputContentStream(mapper, docObj);
contentStream.setContentType(JSON_CONTENT_TYPE);
Thread serThread = new Thread(contentStream);
serThread.start(); // start pumping bytes from the JSON serializer into the input stream using a separate thread
return contentStream;
}
示例4: toContentStreams
import org.apache.solr.common.util.ContentStreamBase; //导入方法依赖的package包/类
/**
* Take a string and make it an iterable ContentStream
*/
public static Collection<ContentStream> toContentStreams( final String str, final String contentType )
{
if( str == null )
return null;
ArrayList<ContentStream> streams = new ArrayList<>( 1 );
ContentStreamBase ccc = new ContentStreamBase.StringStream( str );
ccc.setContentType( contentType );
streams.add( ccc );
return streams;
}
示例5: toContentStreams
import org.apache.solr.common.util.ContentStreamBase; //导入方法依赖的package包/类
/**
* Take a string and make it an iterable ContentStream
*
* This should be moved to a helper class. (it is useful for the client too!)
*/
public static Collection<ContentStream> toContentStreams( final String str, final String contentType )
{
ArrayList<ContentStream> streams = new ArrayList<>();
ContentStreamBase stream = new ContentStreamBase.StringStream( str );
stream.setContentType( contentType );
streams.add( stream );
return streams;
}
示例6: createSolrRequest
import org.apache.solr.common.util.ContentStreamBase; //导入方法依赖的package包/类
private SolrRequest<UpdateResponse> createSolrRequest(String json) {
final ContentStreamUpdateRequest request = new ContentStreamUpdateRequest(jsonUpdateUrl);
final ContentStream cs = new ContentStreamBase.StringStream(json, CONTENT_TYPE);
request.addContentStream(cs);
LOG.debug("Request generated with JSON: {}", json);
return request;
}
示例7: testJSONAuthorityFilter
import org.apache.solr.common.util.ContentStreamBase; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes" })
private void testJSONAuthorityFilter(NamedList report, SolrCore core, String handler, String query, int count,
String sort, Integer[] sorted, Locale locale, Integer rows, Integer start, String json)
throws IOException
{
ContentStream stream = new ContentStreamBase.StringStream(json);
// Magic filter text to trigger usage of content stream.
String filter = "{!afts}AUTHORITY_FILTER_FROM_JSON";
testQueryByHandler(report, core, handler, query, count, sort, sorted, locale, rows, start, stream, filter);
}
示例8: areq
import org.apache.solr.common.util.ContentStreamBase; //导入方法依赖的package包/类
public SolrServletRequest areq(ModifiableSolrParams params, String json) {
if(params.get("wt" ) == null) params.add("wt","xml");
SolrServletRequest req = new SolrServletRequest(h.getCore(), null);
req.setParams(params);
if(json != null) {
ContentStream stream = new ContentStreamBase.StringStream(json);
ArrayList<ContentStream> streams = new ArrayList();
streams.add(stream);
req.setContentStreams(streams);
}
return req;
}
示例9: toContentStreams
import org.apache.solr.common.util.ContentStreamBase; //导入方法依赖的package包/类
/**
* Take a string and make it an iterable ContentStream
*/
public static Collection<ContentStream> toContentStreams( final String str, final String contentType )
{
if( str == null )
return null;
ArrayList<ContentStream> streams = new ArrayList<ContentStream>( 1 );
ContentStreamBase ccc = new ContentStreamBase.StringStream( str );
ccc.setContentType( contentType );
streams.add( ccc );
return streams;
}
示例10: toContentStreams
import org.apache.solr.common.util.ContentStreamBase; //导入方法依赖的package包/类
/**
* Take a string and make it an iterable ContentStream
*
* This should be moved to a helper class. (it is useful for the client too!)
*/
public static Collection<ContentStream> toContentStreams( final String str, final String contentType )
{
ArrayList<ContentStream> streams = new ArrayList<ContentStream>();
ContentStreamBase stream = new ContentStreamBase.StringStream( str );
stream.setContentType( contentType );
streams.add( stream );
return streams;
}
示例11: getContentStream
import org.apache.solr.common.util.ContentStreamBase; //导入方法依赖的package包/类
public ContentStream getContentStream(UpdateRequest req) throws IOException {
return new ContentStreamBase.StringStream(req.getXML());
}
示例12: testResolveAnalysisRequest
import org.apache.solr.common.util.ContentStreamBase; //导入方法依赖的package包/类
/**
* Tests the {@link DocumentAnalysisRequestHandler#resolveAnalysisRequest(org.apache.solr.request.SolrQueryRequest)}
*/
@Test
public void testResolveAnalysisRequest() throws Exception {
String docsInput =
"<docs>" +
"<doc>" +
"<field name=\"id\">1</field>" +
"<field name=\"whitetok\">The Whitetok</field>" +
"<field name=\"text\">The Text</field>" +
"</doc>" +
"</docs>";
final ContentStream cs = new ContentStreamBase.StringStream(docsInput);
ModifiableSolrParams params = new ModifiableSolrParams();
params.add("analysis.query", "The Query String");
params.add("analysis.showmatch", "true");
SolrQueryRequest req = new SolrQueryRequestBase(h.getCore(), params) {
@Override
public Iterable<ContentStream> getContentStreams() {
return Collections.singleton(cs);
}
};
DocumentAnalysisRequest request = handler.resolveAnalysisRequest(req);
assertNotNull(request);
assertTrue(request.isShowMatch());
assertNotNull(request.getQuery());
assertEquals("The Query String", request.getQuery());
List<SolrInputDocument> documents = request.getDocuments();
assertNotNull(documents);
assertEquals(1, documents.size());
SolrInputDocument document = documents.get(0);
SolrInputField field = document.getField("id");
assertNotNull(field);
assertEquals("1", field.getFirstValue());
field = document.getField("whitetok");
assertNotNull(field);
assertEquals("The Whitetok", field.getFirstValue());
field = document.getField("text");
assertNotNull(field);
assertEquals("The Text", field.getFirstValue());
req.close();
}
示例13: showFromZooKeeper
import org.apache.solr.common.util.ContentStreamBase; //导入方法依赖的package包/类
private void showFromZooKeeper(SolrQueryRequest req, SolrQueryResponse rsp,
CoreContainer coreContainer) throws KeeperException,
InterruptedException, UnsupportedEncodingException {
String adminFile = null;
SolrCore core = req.getCore();
SolrZkClient zkClient = coreContainer.getZkController().getZkClient();
final ZkSolrResourceLoader loader = (ZkSolrResourceLoader) core
.getResourceLoader();
String confPath = loader.getCollectionZkPath();
String fname = req.getParams().get("file", null);
if (fname == null) {
adminFile = confPath;
} else {
fname = fname.replace('\\', '/'); // normalize slashes
if (hiddenFiles.contains(fname.toUpperCase(Locale.ROOT))) {
rsp.setException(new SolrException(ErrorCode.FORBIDDEN, "Can not access: " + fname));
return;
}
if (fname.indexOf("..") >= 0) {
rsp.setException(new SolrException(ErrorCode.FORBIDDEN, "Invalid path: " + fname));
return;
}
if (fname.startsWith("/")) { // Only files relative to conf are valid
fname = fname.substring(1);
}
adminFile = confPath + "/" + fname;
}
// Make sure the file exists, is readable and is not a hidden file
if (!zkClient.exists(adminFile, true)) {
rsp.setException(new SolrException(ErrorCode.NOT_FOUND, "Can not find: "
+ adminFile));
return;
}
// Show a directory listing
List<String> children = zkClient.getChildren(adminFile, null, true);
if (children.size() > 0) {
NamedList<SimpleOrderedMap<Object>> files = new SimpleOrderedMap<SimpleOrderedMap<Object>>();
for (String f : children) {
if (hiddenFiles.contains(f.toUpperCase(Locale.ROOT))) {
continue; // don't show 'hidden' files
}
if (f.startsWith(".")) {
continue; // skip hidden system files...
}
SimpleOrderedMap<Object> fileInfo = new SimpleOrderedMap<Object>();
files.add(f, fileInfo);
List<String> fchildren = zkClient.getChildren(adminFile, null, true);
if (fchildren.size() > 0) {
fileInfo.add("directory", true);
} else {
// TODO? content type
fileInfo.add("size", f.length());
}
// TODO: ?
// fileInfo.add( "modified", new Date( f.lastModified() ) );
}
rsp.add("files", files);
} else {
// Include the file contents
// The file logic depends on RawResponseWriter, so force its use.
ModifiableSolrParams params = new ModifiableSolrParams(req.getParams());
params.set(CommonParams.WT, "raw");
req.setParams(params);
ContentStreamBase content = new ContentStreamBase.StringStream(
new String(zkClient.getData(adminFile, null, null, true), "UTF-8"));
content.setContentType(req.getParams().get(USE_CONTENT_TYPE));
rsp.add(RawResponseWriter.CONTENT, content);
}
rsp.setHttpCaching(false);
}
示例14: getContentStreams
import org.apache.solr.common.util.ContentStreamBase; //导入方法依赖的package包/类
@Override
public Collection<ContentStream> getContentStreams() {
ContentStreamBase.StringStream stringStream = new ContentStreamBase.StringStream(input);
stringStream.setContentType("text/plain; charset=UTF-8");
return Collections.singleton((ContentStream) stringStream);
}