【发布时间】:2015-02-13 19:19:42
【问题描述】:
我正在尝试将文档存储到 Google AppEngine 数据存储区。起初我尝试使用 Text 对象,但存储的文本被某种索引截断,我无法找到任何相关信息。我现在收到错误:test.at.example.com: com.google.appengine.api.search.Document is not a supported property type. 如何存储超过 500 个字符的String?
这是存储字符串的方法:
public String post(String user, String documentText) {
if (!documents.hasProperty(user)) {
String indexesstr = (String) documents.getProperty(INDEXLABEL);
documents.setProperty(INDEXLABEL, indexesstr + "\n" + user);
}
documentText = documentText.replace("<", "<");
documentText = documentText.replace("\n", "<br>");
documentText = documentText.replace("\r", "<br>");
Document doc = Document.newBuilder()
.addField(Field.newBuilder().setName("user").setText(user))
.addField(Field.newBuilder().setName("content").setText(documentText))
.build();
documents.setProperty(convertId(user), doc);
datastore.put(documents);
return makeIndex();
}
这是我检索数据的方法:
public String getDocument(String contextPath) {
int offsSlash = contextPath.lastIndexOf("/") + 1;
String ID = contextPath.substring(offsSlash,
contextPath.lastIndexOf("."));
StringBuilder sb = new StringBuilder();
sb.append(prependHTML);
Document document = (Document) documents.getProperty(convertId(ID));
if (document == null)
sb.append("Document not found.");
else {
sb.append(document.getOnlyField("document").getText());
sb.append("<br><div align=\"right\">");
sb.append(document.getOnlyField("user").getText());
sb.append("</div>");
}
sb.append(ammendHTML);
return sb.toString();
}
【问题讨论】:
标签: java google-app-engine google-cloud-datastore