我正在尝试将文档存储到 Google AppEngine 数据存储区。起初,我尝试使用 Text 对象,但存储的文本被某种我无法找到任何信息的索引截断。我现在收到错误:test.at.example.com: com.google.appengine.api.search.Document 不是受支持的属性类型。
如何存储 String
长度超过 500 个字符?
这是存储字符串的方法:
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();
}
最佳答案
您需要使用文本值类型。它没有被截断。无法对该值类型建立索引。
在此处查看属性支持的值类型列表:
如果您需要在文本字符串内搜索,则需要使用搜索 API。它有自己的插入和检索文档的方法 - 您不能将 Document 对象存储在数据存储实体的属性中。
关于java - 在 Google AppEngine 数据存储中使用 500 多个字符字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28507106/