本文整理汇总了Java中org.apache.solr.client.solrj.util.ClientUtils.writeXML方法的典型用法代码示例。如果您正苦于以下问题:Java ClientUtils.writeXML方法的具体用法?Java ClientUtils.writeXML怎么用?Java ClientUtils.writeXML使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.client.solrj.util.ClientUtils
的用法示例。
在下文中一共展示了ClientUtils.writeXML方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getXML
import org.apache.solr.client.solrj.util.ClientUtils; //导入方法依赖的package包/类
/**
* Returns the xml be be set as the request body.
*
* @return The xml be be set as the request body.
*
* @throws IOException When constructing the xml fails
*/
String getXML() throws IOException {
StringWriter writer = new StringWriter();
writer.write("<docs>");
for (SolrInputDocument document : documents) {
ClientUtils.writeXML(document, writer);
}
writer.write("</docs>");
writer.flush();
String xml = writer.toString();
return (xml.length() > 0) ? xml : null;
}
示例2: adoc
import org.apache.solr.client.solrj.util.ClientUtils; //导入方法依赖的package包/类
/**
* Generates a simple <add><doc>... XML String with no options
*/
public static String adoc(SolrInputDocument sdoc) {
StringWriter out = new StringWriter(512);
try {
out.append("<add>");
ClientUtils.writeXML(sdoc, out);
out.append("</add>");
} catch (IOException e) {
throw new RuntimeException("Inexplicable IO error from StringWriter", e);
}
return out.toString();
}
示例3: writeXML
import org.apache.solr.client.solrj.util.ClientUtils; //导入方法依赖的package包/类
public void writeXML(Writer writer) throws IOException {
List<List<SolrDoc>> getDocLists = getDocLists(documents);
for (List<SolrDoc> docs : getDocLists) {
if ((docs != null && docs.size() > 0)) {
SolrDoc firstDoc = docs.get(0);
int commitWithin = firstDoc.commitWithin != -1 ? firstDoc.commitWithin : this.commitWithin;
boolean overwrite = firstDoc.overwrite;
if (commitWithin > -1 || overwrite != true) {
writer.write("<add commitWithin=\"" + commitWithin + "\" " + "overwrite=\"" + overwrite + "\">");
} else {
writer.write("<add>");
}
if (documents != null) {
for (SolrDoc doc : documents) {
if (doc != null) {
ClientUtils.writeXML(doc.document, writer);
}
}
}
writer.write("</add>");
}
}
// Add the delete commands
boolean deleteI = deleteById != null && deleteById.size() > 0;
boolean deleteQ = deleteQuery != null && deleteQuery.size() > 0;
if (deleteI || deleteQ) {
writer.append("<delete>");
if (deleteI) {
for (Map.Entry<String,Long> entry : deleteById.entrySet()) {
writer.append("<id");
Long version = entry.getValue();
if (version != null) {
writer.append(" version=\"" + version + "\"");
}
writer.append(">");
XML.escapeCharData(entry.getKey(), writer);
writer.append("</id>");
}
}
if (deleteQ) {
for (String q : deleteQuery) {
writer.append("<query>");
XML.escapeCharData(q, writer);
writer.append("</query>");
}
}
writer.append("</delete>");
}
}